2019-08-07 05:48:00 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Repositories\KvpRepository;
|
|
|
|
use App\Services\VersionService;
|
|
|
|
|
|
|
|
class VersionTest extends TestCase
|
|
|
|
{
|
|
|
|
private $kvpRepo;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->kvpRepo = app(KvpRepository::class);
|
|
|
|
}
|
|
|
|
|
2019-08-09 00:50:43 +08:00
|
|
|
/**
|
|
|
|
* Test that the new versions (keys) are properly regarded as new versions
|
|
|
|
*/
|
|
|
|
public function testGreaterThanVersionStrings(): void
|
|
|
|
{
|
|
|
|
$test = [
|
2020-02-09 02:29:34 +08:00
|
|
|
['7.0.0' => '6.0.0'],
|
|
|
|
['7.0.0+1231s' => '6.0.0'],
|
|
|
|
// ['7.0.0-beta' => '7.0.0-dev'],
|
|
|
|
['7.0.0-beta' => '7.0.0-alpha'],
|
|
|
|
['7.0.0-beta.1' => '7.0.0-beta'],
|
|
|
|
['7.0.0-beta.2' => '7.0.0-beta.1'],
|
|
|
|
['7.0.0-beta.2+a34sdf' => '7.0.0-beta.1'],
|
2019-08-09 00:50:43 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
$versionSvc = app(VersionService::class);
|
2020-02-09 02:29:34 +08:00
|
|
|
foreach ($test as $set) {
|
|
|
|
$newVersion = array_key_first($set);
|
|
|
|
$currentVersion = $set[$newVersion];
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
$versionSvc->isGreaterThan($newVersion, $currentVersion),
|
|
|
|
"{$newVersion} not greater than ${currentVersion}"
|
|
|
|
);
|
2019-08-09 00:50:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLatestVersion(): void
|
2019-08-07 05:48:00 +08:00
|
|
|
{
|
|
|
|
setting('general.check_prerelease_version', false);
|
|
|
|
|
|
|
|
$this->mockGuzzleClient('releases.json');
|
|
|
|
$versionSvc = app(VersionService::class);
|
|
|
|
|
|
|
|
$str = $versionSvc->getLatestVersion();
|
|
|
|
|
|
|
|
$this->assertEquals('7.0.0-alpha2', $str);
|
|
|
|
$this->assertEquals('7.0.0-alpha2', $this->kvpRepo->get('latest_version_tag'));
|
|
|
|
}
|
|
|
|
|
2019-08-09 00:50:43 +08:00
|
|
|
public function testGetLatestPrereleaseVersion(): void
|
2019-08-07 05:48:00 +08:00
|
|
|
{
|
|
|
|
$this->updateSetting('general.check_prerelease_version', true);
|
|
|
|
|
|
|
|
$this->mockGuzzleClient('releases.json');
|
|
|
|
$versionSvc = app(VersionService::class);
|
|
|
|
|
|
|
|
$str = $versionSvc->getLatestVersion();
|
|
|
|
|
|
|
|
$this->assertEquals('7.0.0-beta', $str);
|
|
|
|
$this->assertEquals('7.0.0-beta', $this->kvpRepo->get('latest_version_tag'));
|
|
|
|
}
|
|
|
|
|
2019-08-09 00:50:43 +08:00
|
|
|
public function testNewVersionNotAvailable(): void
|
2019-08-07 05:48:00 +08:00
|
|
|
{
|
|
|
|
$this->updateSetting('general.check_prerelease_version', false);
|
|
|
|
|
|
|
|
$versions = [
|
|
|
|
'v7.0.0',
|
|
|
|
'7.0.0',
|
|
|
|
'8.0.0',
|
|
|
|
'7.0.0-beta',
|
|
|
|
'7.0.0+buildid',
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($versions as $v) {
|
|
|
|
$this->mockGuzzleClient('releases.json');
|
|
|
|
$versionSvc = app(VersionService::class);
|
|
|
|
$this->assertFalse($versionSvc->isNewVersionAvailable($v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 00:50:43 +08:00
|
|
|
/**
|
|
|
|
* Version in the prerelease releases.json is v7.0.0-beta
|
|
|
|
*/
|
|
|
|
public function testNewVersionIsAvailable(): void
|
2019-08-07 05:48:00 +08:00
|
|
|
{
|
|
|
|
$this->updateSetting('general.check_prerelease_version', true);
|
|
|
|
|
|
|
|
$versions = [
|
|
|
|
'v6.0.1',
|
|
|
|
'6.0.0',
|
|
|
|
'7.0.0-alpha',
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($versions as $v) {
|
|
|
|
$this->mockGuzzleClient('releases.json');
|
|
|
|
$versionSvc = app(VersionService::class);
|
|
|
|
$this->assertTrue($versionSvc->isNewVersionAvailable($v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|