Created
September 21, 2022 20:14
-
-
Save celosauro/503c7e4892e453542b71f26100629471 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests\Unit; | |
use TestCase; | |
class AppVersionTest extends TestCase | |
{ | |
/** | |
* @dataProvider elegibleVersionDataprovider | |
*/ | |
public function testShouldCheckVersionTrue(string $appVersion): void | |
{ | |
$splitedVersion = $this->splitVersion($appVersion); | |
$check = $this->checkVersion($splitedVersion); | |
$this->assertTrue($check); | |
} | |
/** | |
* @dataProvider notElegibleVersionDataprovider | |
*/ | |
public function testShouldCheckVersionFalse(string $appVersion): void | |
{ | |
$splitedVersion = $this->splitVersion($appVersion); | |
$check = $this->checkVersion($splitedVersion); | |
$this->assertFalse($check); | |
} | |
private function splitVersion(string $appVersion): array | |
{ | |
$splited = explode('.', $appVersion); | |
return [ | |
'major' => $splited[0], | |
'minor' => $splited[1], | |
'patch' => $splited[2], | |
]; | |
} | |
private function checkVersion(array $appVersion): bool | |
{ | |
if ($appVersion['major'] > 11) { | |
return true; | |
} elseif ($appVersion['major'] == 11 and $appVersion['minor'] > 0) { | |
return true; | |
} elseif ($appVersion['major'] == 11 and $appVersion['minor'] == 0 and $appVersion['patch'] > 45) { | |
return true; | |
} elseif ($appVersion['major'] == 11 and $appVersion['minor'] == 0 and $appVersion['patch'] == 45) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
public function elegibleVersionDataprovider() | |
{ | |
yield '11.0.45' => [ | |
'app_version' => '11.0.45' | |
]; | |
yield '12.0.45' => [ | |
'app_version' => '12.0.45' | |
]; | |
yield '11.1.45' => [ | |
'app_version' => '11.1.45' | |
]; | |
yield '11.0.46' => [ | |
'app_version' => '11.0.46' | |
]; | |
} | |
public function notElegibleVersionDataprovider() | |
{ | |
yield '11.0.44' => [ | |
'app_version' => '11.0.44' | |
]; | |
yield '10.0.45' => [ | |
'app_version' => '10.0.45' | |
]; | |
yield '10.0.46' => [ | |
'app_version' => '10.0.46' | |
]; | |
yield '10.1.45' => [ | |
'app_version' => '10.1.45' | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment