mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Update VersionProviderTest.php
This commit is contained in:
parent
b53148c034
commit
2b64e98afc
@ -2,14 +2,15 @@
|
||||
|
||||
namespace SilverStripe\Core\Tests\Manifest;
|
||||
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use SebastianBergmann\Version;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Core\Manifest\VersionProvider;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
class VersionProviderTest extends SapphireTest
|
||||
{
|
||||
const SEMVER_REGEX = '(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(0|[1-9A-Za-z-][0-9A-Za-z-]*)(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?';
|
||||
|
||||
/**
|
||||
* @var VersionProvider
|
||||
@ -22,17 +23,9 @@ class VersionProviderTest extends SapphireTest
|
||||
$this->clearCache();
|
||||
}
|
||||
|
||||
public function getMockProvider($composerLockPath = '')
|
||||
public function getProvider()
|
||||
{
|
||||
if ($composerLockPath == '') {
|
||||
// composer.lock file without silverstripe/recipe-core or silverstripe/recipe-cms
|
||||
$composerLockPath = __DIR__ . '/fixtures/VersionProviderTest/composer.no-recipe.testlock';
|
||||
}
|
||||
/** @var VersionProvider $provider */
|
||||
$provider = $this->getMockBuilder(VersionProvider::class)
|
||||
->setMethods(['getComposerLockPath'])
|
||||
->getMock();
|
||||
$provider->method('getComposerLockPath')->willReturn($composerLockPath);
|
||||
$provider = Injector::inst()->get(VersionProvider::class);
|
||||
return $provider;
|
||||
}
|
||||
|
||||
@ -44,7 +37,7 @@ class VersionProviderTest extends SapphireTest
|
||||
'silverstripe/another' => 'Another',
|
||||
'cwp/cwp-something' => 'CWP something',
|
||||
]);
|
||||
$result = $this->getMockProvider()->getModules();
|
||||
$result = $this->getProvider()->getModules();
|
||||
$this->assertArrayHasKey('silverstripe/mypackage', $result);
|
||||
$this->assertArrayHasKey('silverstripe/somepackage', $result);
|
||||
$this->assertArrayHasKey('silverstripe/another', $result);
|
||||
@ -56,7 +49,7 @@ class VersionProviderTest extends SapphireTest
|
||||
Config::modify()->set(VersionProvider::class, 'modules', []);
|
||||
$this->assertEquals(
|
||||
['silverstripe/framework' => 'Framework'],
|
||||
$this->getMockProvider()->getModules()
|
||||
$this->getProvider()->getModules()
|
||||
);
|
||||
}
|
||||
|
||||
@ -65,7 +58,7 @@ class VersionProviderTest extends SapphireTest
|
||||
Config::modify()->remove(VersionProvider::class, 'modules');
|
||||
$this->assertEquals(
|
||||
['silverstripe/framework' => 'Framework'],
|
||||
$this->getMockProvider()->getModules()
|
||||
$this->getProvider()->getModules()
|
||||
);
|
||||
}
|
||||
|
||||
@ -76,7 +69,7 @@ class VersionProviderTest extends SapphireTest
|
||||
'silverstripe/framework' => 'Framework',
|
||||
]);
|
||||
|
||||
$result = $this->getMockProvider()->getModules(['silverstripe/framework']);
|
||||
$result = $this->getProvider()->getModules(['silverstripe/framework']);
|
||||
$this->assertArrayHasKey('silverstripe/framework', $result);
|
||||
$this->assertNotEmpty($result['silverstripe/framework']);
|
||||
}
|
||||
@ -87,131 +80,22 @@ class VersionProviderTest extends SapphireTest
|
||||
'silverstripe/siteconfig' => 'SiteConfig',
|
||||
'silverstripe/framework' => 'Framework'
|
||||
]);
|
||||
$result = $this->getMockProvider()->getVersion();
|
||||
$result = $this->getProvider()->getVersion();
|
||||
$this->assertStringNotContainsString('SiteConfig: ', $result);
|
||||
$this->assertStringContainsString('Framework: ', $result);
|
||||
$this->assertStringNotContainsString(', ', $result);
|
||||
}
|
||||
|
||||
public function testGetVersionNoRecipe()
|
||||
{
|
||||
// composer.lock file without silverstripe/recipe-core or silverstripe/recipe-cms
|
||||
$provider = $this->getMockProvider(__DIR__ . '/fixtures/VersionProviderTest/composer.no-recipe.testlock');
|
||||
|
||||
Config::modify()->set(VersionProvider::class, 'modules', []);
|
||||
$result = $provider->getVersion();
|
||||
$this->assertStringContainsString('Framework: 1.2.3', $result);
|
||||
|
||||
$this->clearCache();
|
||||
|
||||
Config::modify()->set(VersionProvider::class, 'modules', [
|
||||
'silverstripe/framework' => 'Framework',
|
||||
'silverstripe/recipe-core' => 'Core Recipe',
|
||||
'silverstripe/cms' => 'CMS',
|
||||
'silverstripe/recipe-cms' => 'CMS Recipe',
|
||||
]);
|
||||
$result = $provider->getVersion();
|
||||
$this->assertStringNotContainsString('Framework: 1.2.3', $result);
|
||||
$this->assertStringContainsString('CMS: 4.5.6', $result);
|
||||
$this->assertStringNotContainsString('Core Recipe: 7.7.7', $result);
|
||||
$this->assertStringNotContainsString('CMS Recipe: 8.8.8', $result);
|
||||
}
|
||||
|
||||
public function testGetVersionRecipeCore()
|
||||
{
|
||||
// composer.lock file with silverstripe/recipe-core but not silverstripe/recipe-cms
|
||||
$provider = $this->getMockProvider(__DIR__ . '/fixtures/VersionProviderTest/composer.recipe-core.testlock');
|
||||
Config::modify()->set(VersionProvider::class, 'modules', [
|
||||
'silverstripe/framework' => 'Framework',
|
||||
'silverstripe/recipe-core' => 'Core Recipe',
|
||||
'silverstripe/cms' => 'CMS',
|
||||
'silverstripe/recipe-cms' => 'CMS Recipe',
|
||||
]);
|
||||
$result = $provider->getVersion();
|
||||
$this->assertStringNotContainsString('Framework: 1.2.3', $result);
|
||||
$this->assertStringNotContainsString('Core Recipe: 7.7.7', $result);
|
||||
$this->assertStringContainsString('CMS: 4.5.6', $result);
|
||||
$this->assertStringNotContainsString('CMS Recipe: 8.8.8', $result);
|
||||
}
|
||||
|
||||
public function testGetVersionRecipeCmsCore()
|
||||
{
|
||||
// composer.lock file with silverstripe/recipe-core and silverstripe/recipe-cms
|
||||
$path = __DIR__ . '/fixtures/VersionProviderTest/composer.recipe-cms-core-and-cwpcore.testlock';
|
||||
$provider = $this->getMockProvider($path);
|
||||
|
||||
Config::modify()->set(VersionProvider::class, 'modules', [
|
||||
'silverstripe/framework' => 'Framework',
|
||||
'silverstripe/recipe-core' => 'Core Recipe',
|
||||
'silverstripe/cms' => 'CMS',
|
||||
'silverstripe/recipe-cms' => 'CMS Recipe',
|
||||
]);
|
||||
$result = $provider->getVersion();
|
||||
|
||||
$this->assertStringNotContainsString('Framework: 1.2.3', $result);
|
||||
$this->assertStringNotContainsString('CMS: 4.5.6', $result);
|
||||
$this->assertStringNotContainsString('Core Recipe: 7.7.7', $result);
|
||||
$this->assertStringContainsString('CMS Recipe: 8.8.8', $result);
|
||||
$this->assertStringNotContainsString('CWP: 9.9.9', $result);
|
||||
|
||||
$this->clearCache();
|
||||
|
||||
Config::modify()->set(VersionProvider::class, 'modules', [
|
||||
'silverstripe/framework' => 'Framework',
|
||||
'silverstripe/recipe-core' => 'Core Recipe',
|
||||
'silverstripe/cms' => 'CMS',
|
||||
'silverstripe/recipe-cms' => 'CMS Recipe',
|
||||
'cwp/cwp-core' => 'CWP',
|
||||
]);
|
||||
$result = $provider->getVersion();
|
||||
$this->assertStringNotContainsString('Framework: 1.2.3', $result);
|
||||
$this->assertStringNotContainsString('CMS: 4.5.6', $result);
|
||||
$this->assertStringNotContainsString('Core Recipe: 7.7.7', $result);
|
||||
$this->assertStringContainsString('CMS Recipe:', $result);
|
||||
$this->assertStringContainsString('CWP: 9.9.9', $result);
|
||||
}
|
||||
|
||||
public function testGetModulesFromComposerLock()
|
||||
{
|
||||
$mock = $this->getMockBuilder(VersionProvider::class)
|
||||
->setMethods(['getComposerLock'])
|
||||
->getMock();
|
||||
|
||||
$mock->expects($this->exactly(1))
|
||||
->method('getComposerLock')
|
||||
->will($this->returnValue([
|
||||
'packages' => [
|
||||
[
|
||||
'name' => 'silverstripe/somepackage',
|
||||
'version' => '1.2.3'
|
||||
],
|
||||
[
|
||||
'name' => 'silverstripe/another',
|
||||
'version' => '2.3.4'
|
||||
]
|
||||
]
|
||||
]));
|
||||
|
||||
Config::modify()->set(VersionProvider::class, 'modules', [
|
||||
'silverstripe/somepackage' => 'Some Package'
|
||||
]);
|
||||
|
||||
$result = $mock->getVersion();
|
||||
$this->assertStringContainsString('Some Package: 1.2.3', $result);
|
||||
}
|
||||
|
||||
public function testGetModuleVersion()
|
||||
{
|
||||
$provider = $this->getMockProvider(__DIR__ . '/fixtures/VersionProviderTest/composer.recipe-core.testlock');
|
||||
$provider = $this->getProvider();
|
||||
Config::modify()->set(VersionProvider::class, 'modules', [
|
||||
'silverstripe/framework' => 'Framework',
|
||||
'silverstripe/recipe-core' => 'Core Recipe'
|
||||
]);
|
||||
$this->assertSame('1.2.3', $provider->getModuleVersion('silverstripe/framework'));
|
||||
// assert that the temporary config changes in getModuleVersion() had no side-effects
|
||||
$this->assertMatchesRegularExpression('/' . self::SEMVER_REGEX . '/', $provider->getModuleVersion('silverstripe/framework'));
|
||||
$result = $provider->getVersion();
|
||||
$this->assertStringNotContainsString('Framework: 1.2.3', $result);
|
||||
$this->assertStringContainsString('Core Recipe: 7.7.7', $result);
|
||||
$this->assertMatchesRegularExpression('/Framework: ' . self::SEMVER_REGEX . '/', $result);
|
||||
}
|
||||
|
||||
private function clearCache()
|
||||
|
Loading…
Reference in New Issue
Block a user