Merge pull request #7175 from robbieaverill/pulls/4.0/version-provider

FIX Version provider uses non LSB config getters, move LeftAndMain config to admin module
This commit is contained in:
Daniel Hensby 2017-07-17 14:01:22 +01:00 committed by GitHub
commit 4f095ea61d
3 changed files with 26 additions and 31 deletions

View File

@ -12,9 +12,6 @@ SilverStripe\Control\HTTP:
must-revalidate: "true" must-revalidate: "true"
no-transform: "true" no-transform: "true"
vary: "Cookie, X-Forwarded-Protocol, User-Agent, Accept" vary: "Cookie, X-Forwarded-Protocol, User-Agent, Accept"
LeftAndMain:
dependencies:
versionProvider: %$VersionProvider
SilverStripe\Core\Manifest\VersionProvider: SilverStripe\Core\Manifest\VersionProvider:
modules: modules:
silverstripe/framework: Framework silverstripe/framework: Framework

View File

@ -33,11 +33,11 @@ class VersionProvider
{ {
$modules = $this->getModules(); $modules = $this->getModules();
$lockModules = $this->getModuleVersionFromComposer(array_keys($modules)); $lockModules = $this->getModuleVersionFromComposer(array_keys($modules));
$output = array(); $output = [];
foreach ($modules as $module => $title) { foreach ($modules as $module => $title) {
$version = isset($lockModules[$module]) $version = isset($lockModules[$module])
? $lockModules[$module] ? $lockModules[$module]
: _t('SilverStripe\Core\Manifest\VersionProvider.VERSIONUNKNOWN', 'Unknown'); : _t(__CLASS__.'.VERSIONUNKNOWN', 'Unknown');
$output[] = $title . ': ' . $version; $output[] = $title . ': ' . $version;
} }
return implode(', ', $output); return implode(', ', $output);
@ -51,8 +51,8 @@ class VersionProvider
*/ */
public function getModules() public function getModules()
{ {
$modules = Config::inst()->get(static::class, 'modules'); $modules = Config::inst()->get(self::class, 'modules');
return $modules ? array_filter($modules) : array(); return $modules ? array_filter($modules) : [];
} }
/** /**
@ -61,9 +61,9 @@ class VersionProvider
* @param array $modules * @param array $modules
* @return array * @return array
*/ */
public function getModuleVersionFromComposer($modules = array()) public function getModuleVersionFromComposer($modules = [])
{ {
$versions = array(); $versions = [];
$lockData = $this->getComposerLock(); $lockData = $this->getComposerLock();
if ($lockData && !empty($lockData['packages'])) { if ($lockData && !empty($lockData['packages'])) {
foreach ($lockData['packages'] as $package) { foreach ($lockData['packages'] as $package) {
@ -85,10 +85,10 @@ class VersionProvider
{ {
$composerLockPath = BASE_PATH . '/composer.lock'; $composerLockPath = BASE_PATH . '/composer.lock';
if (!file_exists($composerLockPath)) { if (!file_exists($composerLockPath)) {
return array(); return [];
} }
$lockData = array(); $lockData = [];
$jsonData = file_get_contents($composerLockPath); $jsonData = file_get_contents($composerLockPath);
if ($cache) { if ($cache) {

View File

@ -21,11 +21,11 @@ class VersionProviderTest extends SapphireTest
public function testGetModules() public function testGetModules()
{ {
Config::modify()->set(VersionProvider::class, 'modules', array( Config::modify()->set(VersionProvider::class, 'modules', [
'silverstripe/somepackage' => 'Some Package', 'silverstripe/somepackage' => 'Some Package',
'silverstripe/hidden' => '', 'silverstripe/hidden' => '',
'silverstripe/another' => 'Another' 'silverstripe/another' => 'Another'
)); ]);
$result = $this->provider->getModules(); $result = $this->provider->getModules();
$this->assertArrayHasKey('silverstripe/somepackage', $result); $this->assertArrayHasKey('silverstripe/somepackage', $result);
@ -36,22 +36,22 @@ class VersionProviderTest extends SapphireTest
public function testGetModuleVersionFromComposer() public function testGetModuleVersionFromComposer()
{ {
Config::modify()->set(VersionProvider::class, 'modules', array( Config::modify()->set(VersionProvider::class, 'modules', [
'silverstripe/framework' => 'Framework', 'silverstripe/framework' => 'Framework',
'silverstripe/siteconfig' => 'SiteConfig' 'silverstripe/siteconfig' => 'SiteConfig'
)); ]);
$result = $this->provider->getModules(array('silverstripe/framework')); $result = $this->provider->getModules(['silverstripe/framework']);
$this->assertArrayHasKey('silverstripe/framework', $result); $this->assertArrayHasKey('silverstripe/framework', $result);
$this->assertNotEmpty($result['silverstripe/framework']); $this->assertNotEmpty($result['silverstripe/framework']);
} }
public function testGetVersion() public function testGetVersion()
{ {
Config::modify()->set(VersionProvider::class, 'modules', array( Config::modify()->set(VersionProvider::class, 'modules', [
'silverstripe/framework' => 'Framework', 'silverstripe/framework' => 'Framework',
'silverstripe/siteconfig' => 'SiteConfig' 'silverstripe/siteconfig' => 'SiteConfig'
)); ]);
$result = $this->provider->getVersion(); $result = $this->provider->getVersion();
$this->assertContains('SiteConfig: ', $result); $this->assertContains('SiteConfig: ', $result);
@ -61,30 +61,28 @@ class VersionProviderTest extends SapphireTest
public function testGetModulesFromComposerLock() public function testGetModulesFromComposerLock()
{ {
$this->markTestSkipped('Unable to get this passing');
$mock = $this->getMockBuilder(VersionProvider::class) $mock = $this->getMockBuilder(VersionProvider::class)
->setMethods(array('getComposerLock')) ->setMethods(['getComposerLock'])
->getMock(); ->getMock();
$mock->expects($this->once()) $mock->expects($this->once())
->method('getComposerLock') ->method('getComposerLock')
->will($this->returnValue(array( ->will($this->returnValue([
'packages' => array( 'packages' => [
array( [
'name' => 'silverstripe/somepackage', 'name' => 'silverstripe/somepackage',
'version' => '1.2.3' 'version' => '1.2.3'
), ],
array( [
'name' => 'silverstripe/another', 'name' => 'silverstripe/another',
'version' => '2.3.4' 'version' => '2.3.4'
) ]
) ]
))); ]));
Config::modify()->set(VersionProvider::class, 'modules', array( Config::modify()->set(VersionProvider::class, 'modules', [
'silverstripe/somepackage' => 'Some Package' 'silverstripe/somepackage' => 'Some Package'
)); ]);
$result = $mock->getVersion(); $result = $mock->getVersion();
$this->assertContains('Some Package: 1.2.3', $result); $this->assertContains('Some Package: 1.2.3', $result);