Skip to content

Instantly share code, notes, and snippets.

@celosauro
Created September 21, 2022 20:14
Show Gist options
  • Save celosauro/503c7e4892e453542b71f26100629471 to your computer and use it in GitHub Desktop.
Save celosauro/503c7e4892e453542b71f26100629471 to your computer and use it in GitHub Desktop.
<?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