From bc091271826aa7be800d961c4739bc2482ff7a00 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Fri, 23 Feb 2024 17:06:27 +0100 Subject: [PATCH 01/16] use composer runtime api --- src/Core/Manifest/VersionProvider.php | 42 +++++++++++++++++---------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/Core/Manifest/VersionProvider.php b/src/Core/Manifest/VersionProvider.php index 75339b4ba56..d93a8899ab2 100644 --- a/src/Core/Manifest/VersionProvider.php +++ b/src/Core/Manifest/VersionProvider.php @@ -30,7 +30,7 @@ class VersionProvider use Injectable; /** - * @var array + * @var array */ private static $modules = [ 'silverstripe/framework' => 'Framework', @@ -50,10 +50,10 @@ public function getVersion() return $version; } $modules = $this->getModules(); - $lockModules = $this->getModuleVersionFromComposer(array_keys($modules ?? [])); + $lockModules = $this->getModuleVersionFromComposer(array_keys($modules)); $moduleVersions = []; foreach ($modules as $module => $title) { - if (!array_key_exists($module, $lockModules ?? [])) { + if (!array_key_exists($module, $lockModules)) { continue; } $version = $lockModules[$module]; @@ -145,14 +145,14 @@ private function setCacheValue(string $key, string $value): void * cwp/cwp-core => ['CWP', '4.4.4'] * ] * - * @param array $modules - * @return array + * @param array $modules + * @return array */ private function filterModules(array $modules) { $accountModule = []; foreach ($modules as $module => $value) { - if (!preg_match('#^([a-z0-9\-]+)/([a-z0-9\-]+)$#', $module ?? '', $m)) { + if (!preg_match('#^([a-z0-9\-]+)/([a-z0-9\-]+)$#', $module, $m)) { continue; } $account = $m[1]; @@ -169,7 +169,7 @@ private function filterModules(array $modules) /** * Gets the configured core modules to use for the SilverStripe application version * - * @return array + * @return array */ public function getModules() { @@ -180,16 +180,23 @@ public function getModules() /** * Tries to obtain version number from composer.lock if it exists * - * @param array $modules - * @return array + * @param array $modules + * @return array */ public function getModuleVersionFromComposer($modules = []) { + if (class_exists(\Composer\InstalledVersions::class)) { + $versions = []; + foreach ($modules as $module) { + $versions[$module] = \Composer\InstalledVersions::getPrettyVersion($module); + } + return $versions; + } $versions = []; $lockData = $this->getComposerLock(); if ($lockData && !empty($lockData['packages'])) { foreach ($lockData['packages'] as $package) { - if (in_array($package['name'], $modules ?? []) && isset($package['version'])) { + if (in_array($package['name'], $modules) && isset($package['version'])) { $versions[$package['name']] = $package['version']; } } @@ -201,34 +208,37 @@ public function getModuleVersionFromComposer($modules = []) * Load composer.lock's contents and return it * * @param bool $cache - * @return array + * @return array */ protected function getComposerLock($cache = true) { $composerLockPath = $this->getComposerLockPath(); - if (!file_exists($composerLockPath ?? '')) { + if (!file_exists($composerLockPath)) { return []; } $lockData = []; - $jsonData = file_get_contents($composerLockPath ?? ''); + $jsonData = file_get_contents($composerLockPath); + $jsonData = $jsonData ? $jsonData : ''; + $cacheKey = md5($jsonData); if ($cache) { $cache = Injector::inst()->get(CacheInterface::class . '.VersionProvider_composerlock'); - $cacheKey = md5($jsonData ?? ''); if ($versions = $cache->get($cacheKey)) { - $lockData = json_decode($versions ?? '', true); + $lockData = json_decode($versions, true); } } if (empty($lockData) && $jsonData) { - $lockData = json_decode($jsonData ?? '', true); + $lockData = json_decode($jsonData, true); if ($cache) { $cache->set($cacheKey, $jsonData); } } + $lockData = $lockData ? $lockData : []; + return $lockData; } From a196719502e96019c5a0cf00cad9c33ea0c0fed7 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 09:09:31 +0100 Subject: [PATCH 02/16] Update src/Core/Manifest/VersionProvider.php Co-authored-by: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> --- src/Core/Manifest/VersionProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Manifest/VersionProvider.php b/src/Core/Manifest/VersionProvider.php index d93a8899ab2..11e165642ce 100644 --- a/src/Core/Manifest/VersionProvider.php +++ b/src/Core/Manifest/VersionProvider.php @@ -181,7 +181,7 @@ public function getModules() * Tries to obtain version number from composer.lock if it exists * * @param array $modules - * @return array + * @return array */ public function getModuleVersionFromComposer($modules = []) { From a2486c085948c65545670fb903c99b92636eed7e Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 09:09:38 +0100 Subject: [PATCH 03/16] Update src/Core/Manifest/VersionProvider.php Co-authored-by: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> --- src/Core/Manifest/VersionProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Manifest/VersionProvider.php b/src/Core/Manifest/VersionProvider.php index 11e165642ce..17d5ae82ba0 100644 --- a/src/Core/Manifest/VersionProvider.php +++ b/src/Core/Manifest/VersionProvider.php @@ -208,7 +208,7 @@ public function getModuleVersionFromComposer($modules = []) * Load composer.lock's contents and return it * * @param bool $cache - * @return array + * @return array */ protected function getComposerLock($cache = true) { From e649310f7bb96f1970156d07a31d990dde317e0f Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 09:09:45 +0100 Subject: [PATCH 04/16] Update src/Core/Manifest/VersionProvider.php Co-authored-by: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> --- src/Core/Manifest/VersionProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Manifest/VersionProvider.php b/src/Core/Manifest/VersionProvider.php index 17d5ae82ba0..e5d8385aa64 100644 --- a/src/Core/Manifest/VersionProvider.php +++ b/src/Core/Manifest/VersionProvider.php @@ -180,7 +180,7 @@ public function getModules() /** * Tries to obtain version number from composer.lock if it exists * - * @param array $modules + * @param array $modules * @return array */ public function getModuleVersionFromComposer($modules = []) From 2600b266172a51215963ebbb0dc640d77f6ded95 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 09:20:22 +0100 Subject: [PATCH 05/16] add composer-runtime-api --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index a74b1fe35e5..fdf66f1a004 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ ], "require": { "php": "^8.1", + "composer-runtime-api": "^2.2", "composer/installers": "^2.2", "guzzlehttp/guzzle": "^7.5.0", "guzzlehttp/psr7": "^2.4.0", From b53148c034394a37b7c16ce34a340a83da3f4afe Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 09:23:35 +0100 Subject: [PATCH 06/16] add deprecation, remove class_exists --- src/Core/Manifest/VersionProvider.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Core/Manifest/VersionProvider.php b/src/Core/Manifest/VersionProvider.php index e5d8385aa64..137642316d8 100644 --- a/src/Core/Manifest/VersionProvider.php +++ b/src/Core/Manifest/VersionProvider.php @@ -8,6 +8,7 @@ use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injector; +use SilverStripe\Dev\Deprecation; /** * The version provider will look up configured modules and examine the composer.lock file @@ -185,21 +186,9 @@ public function getModules() */ public function getModuleVersionFromComposer($modules = []) { - if (class_exists(\Composer\InstalledVersions::class)) { - $versions = []; - foreach ($modules as $module) { - $versions[$module] = \Composer\InstalledVersions::getPrettyVersion($module); - } - return $versions; - } $versions = []; - $lockData = $this->getComposerLock(); - if ($lockData && !empty($lockData['packages'])) { - foreach ($lockData['packages'] as $package) { - if (in_array($package['name'], $modules) && isset($package['version'])) { - $versions[$package['name']] = $package['version']; - } - } + foreach ($modules as $module) { + $versions[$module] = \Composer\InstalledVersions::getPrettyVersion($module); } return $versions; } @@ -207,11 +196,13 @@ public function getModuleVersionFromComposer($modules = []) /** * Load composer.lock's contents and return it * + * @deprecated 5.1 Has been replaced by composer-runtime-api * @param bool $cache * @return array */ protected function getComposerLock($cache = true) { + Deprecation::notice("5.1", "Has been replaced by composer-runtime-api", Deprecation::SCOPE_METHOD); $composerLockPath = $this->getComposerLockPath(); if (!file_exists($composerLockPath)) { return []; From 2b64e98afc6e2368cce156e7c55dda7accfc8f00 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 09:48:15 +0100 Subject: [PATCH 07/16] Update VersionProviderTest.php --- .../php/Core/Manifest/VersionProviderTest.php | 142 ++---------------- 1 file changed, 13 insertions(+), 129 deletions(-) diff --git a/tests/php/Core/Manifest/VersionProviderTest.php b/tests/php/Core/Manifest/VersionProviderTest.php index 21f07b10f70..b3155424d5a 100644 --- a/tests/php/Core/Manifest/VersionProviderTest.php +++ b/tests/php/Core/Manifest/VersionProviderTest.php @@ -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 @@ protected function setup(): void $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 @@ public function testGetModules() '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 @@ public function testGetModulesEmpty() Config::modify()->set(VersionProvider::class, 'modules', []); $this->assertEquals( ['silverstripe/framework' => 'Framework'], - $this->getMockProvider()->getModules() + $this->getProvider()->getModules() ); } @@ -65,7 +58,7 @@ public function testGetModulesNone() Config::modify()->remove(VersionProvider::class, 'modules'); $this->assertEquals( ['silverstripe/framework' => 'Framework'], - $this->getMockProvider()->getModules() + $this->getProvider()->getModules() ); } @@ -76,7 +69,7 @@ public function testGetModuleVersionFromComposer() '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 @@ public function testGetVersion() '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() From 1cf3dde9f15623d61399814ee90360d225691b53 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 09:48:35 +0100 Subject: [PATCH 08/16] Update src/Core/Manifest/VersionProvider.php Co-authored-by: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> --- src/Core/Manifest/VersionProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Manifest/VersionProvider.php b/src/Core/Manifest/VersionProvider.php index 137642316d8..fe77955e6a3 100644 --- a/src/Core/Manifest/VersionProvider.php +++ b/src/Core/Manifest/VersionProvider.php @@ -188,7 +188,7 @@ public function getModuleVersionFromComposer($modules = []) { $versions = []; foreach ($modules as $module) { - $versions[$module] = \Composer\InstalledVersions::getPrettyVersion($module); + $versions[$module] = InstalledVersions::getPrettyVersion($module); } return $versions; } From 2696922023297943b1a5a9189490aa9a7f3a1243 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 09:52:48 +0100 Subject: [PATCH 09/16] update return type --- src/Core/Manifest/VersionProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/Manifest/VersionProvider.php b/src/Core/Manifest/VersionProvider.php index fe77955e6a3..9f6e59e4e36 100644 --- a/src/Core/Manifest/VersionProvider.php +++ b/src/Core/Manifest/VersionProvider.php @@ -146,8 +146,8 @@ private function setCacheValue(string $key, string $value): void * cwp/cwp-core => ['CWP', '4.4.4'] * ] * - * @param array $modules - * @return array + * @param array> $modules + * @return array> */ private function filterModules(array $modules) { From 68b79e11ee6cca43637f6746c2c3ea64ee3af0a2 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 09:54:18 +0100 Subject: [PATCH 10/16] missing import --- src/Core/Manifest/VersionProvider.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Core/Manifest/VersionProvider.php b/src/Core/Manifest/VersionProvider.php index 9f6e59e4e36..65cfc73768f 100644 --- a/src/Core/Manifest/VersionProvider.php +++ b/src/Core/Manifest/VersionProvider.php @@ -3,12 +3,13 @@ namespace SilverStripe\Core\Manifest; use InvalidArgumentException; -use SilverStripe\Core\Config\Config; +use Composer\InstalledVersions; +use SilverStripe\Dev\Deprecation; use Psr\SimpleCache\CacheInterface; +use SilverStripe\Core\Config\Config; +use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Injector\Injectable; -use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\Deprecation; /** * The version provider will look up configured modules and examine the composer.lock file From 071333f774419f8f4549e9a5a027ead0796646c9 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 10:10:20 +0100 Subject: [PATCH 11/16] add composer/semver --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index fdf66f1a004..e4453cedb11 100644 --- a/composer.json +++ b/composer.json @@ -60,6 +60,7 @@ "ext-xml": "*" }, "require-dev": { + "composer/semver": "^3.4", "phpunit/phpunit": "^9.6", "silverstripe/versioned": "^2", "squizlabs/php_codesniffer": "^3.7" From a1d1e977c5912bcc5ed4a9a46901c523da1e7bbe Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 10:13:34 +0100 Subject: [PATCH 12/16] use composer/semver --- tests/php/Core/Manifest/VersionProviderTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/php/Core/Manifest/VersionProviderTest.php b/tests/php/Core/Manifest/VersionProviderTest.php index b3155424d5a..f5a9ea34a35 100644 --- a/tests/php/Core/Manifest/VersionProviderTest.php +++ b/tests/php/Core/Manifest/VersionProviderTest.php @@ -3,15 +3,15 @@ namespace SilverStripe\Core\Tests\Manifest; use SebastianBergmann\Version; +use Composer\Semver\Comparator; use SilverStripe\Dev\SapphireTest; +use Psr\SimpleCache\CacheInterface; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Manifest\VersionProvider; 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 */ @@ -92,10 +92,9 @@ public function testGetModuleVersion() Config::modify()->set(VersionProvider::class, 'modules', [ 'silverstripe/framework' => 'Framework', ]); - $this->assertMatchesRegularExpression('/' . self::SEMVER_REGEX . '/', $provider->getModuleVersion('silverstripe/framework')); + $this->assertTrue(Comparator::greaterThan($provider->getModuleVersion('silverstripe/framework'), '5.0.0')); $result = $provider->getVersion(); $this->assertStringNotContainsString('Framework: 1.2.3', $result); - $this->assertMatchesRegularExpression('/Framework: ' . self::SEMVER_REGEX . '/', $result); } private function clearCache() From 80e197fe4ffffc12136bb1dad49944971bddfe76 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 10:21:23 +0100 Subject: [PATCH 13/16] make error message more readable --- tests/php/Core/Manifest/VersionProviderTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/php/Core/Manifest/VersionProviderTest.php b/tests/php/Core/Manifest/VersionProviderTest.php index f5a9ea34a35..54eace9883e 100644 --- a/tests/php/Core/Manifest/VersionProviderTest.php +++ b/tests/php/Core/Manifest/VersionProviderTest.php @@ -92,7 +92,8 @@ public function testGetModuleVersion() Config::modify()->set(VersionProvider::class, 'modules', [ 'silverstripe/framework' => 'Framework', ]); - $this->assertTrue(Comparator::greaterThan($provider->getModuleVersion('silverstripe/framework'), '5.0.0')); + $moduleVersion = $provider->getModuleVersion('silverstripe/framework'); + $this->assertTrue(Comparator::greaterThanOrEqualTo($moduleVersion, '5.0.0'), "Expected > 5.0.0 but got $moduleVersion"); $result = $provider->getVersion(); $this->assertStringNotContainsString('Framework: 1.2.3', $result); } From a06ce0493a5507bd78d35805f114b57927c14223 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 26 Feb 2024 11:44:11 +0100 Subject: [PATCH 14/16] use VersionParser instead of comparator --- tests/php/Core/Manifest/VersionProviderTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/php/Core/Manifest/VersionProviderTest.php b/tests/php/Core/Manifest/VersionProviderTest.php index 54eace9883e..96e62795afa 100644 --- a/tests/php/Core/Manifest/VersionProviderTest.php +++ b/tests/php/Core/Manifest/VersionProviderTest.php @@ -3,7 +3,7 @@ namespace SilverStripe\Core\Tests\Manifest; use SebastianBergmann\Version; -use Composer\Semver\Comparator; +use Composer\Semver\VersionParser; use SilverStripe\Dev\SapphireTest; use Psr\SimpleCache\CacheInterface; use SilverStripe\Core\Config\Config; @@ -93,7 +93,8 @@ public function testGetModuleVersion() 'silverstripe/framework' => 'Framework', ]); $moduleVersion = $provider->getModuleVersion('silverstripe/framework'); - $this->assertTrue(Comparator::greaterThanOrEqualTo($moduleVersion, '5.0.0'), "Expected > 5.0.0 but got $moduleVersion"); + $parser = new VersionParser(); + $this->assertIsString($parser->normalize($moduleVersion), "Expected a valid semver but got $moduleVersion"); $result = $provider->getVersion(); $this->assertStringNotContainsString('Framework: 1.2.3', $result); } From 2921d68a57ed718a5d0633b90c186d24b90c98dc Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Tue, 27 Feb 2024 10:40:28 +0100 Subject: [PATCH 15/16] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e4453cedb11..cce015b27ae 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ ], "require": { "php": "^8.1", - "composer-runtime-api": "^2.2", + "composer-runtime-api": "^2.0", "composer/installers": "^2.2", "guzzlehttp/guzzle": "^7.5.0", "guzzlehttp/psr7": "^2.4.0", From 59177dd3157f5b0894d5e7c07244a76a327c7c40 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Tue, 27 Feb 2024 10:42:25 +0100 Subject: [PATCH 16/16] Delete tests/php/Core/Manifest/fixtures/VersionProviderTest directory --- .../composer.no-recipe.testlock | 16 ----------- ...poser.recipe-cms-core-and-cwpcore.testlock | 28 ------------------- .../composer.recipe-core.testlock | 20 ------------- 3 files changed, 64 deletions(-) delete mode 100644 tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.no-recipe.testlock delete mode 100644 tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.recipe-cms-core-and-cwpcore.testlock delete mode 100644 tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.recipe-core.testlock diff --git a/tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.no-recipe.testlock b/tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.no-recipe.testlock deleted file mode 100644 index aad7303d9b0..00000000000 --- a/tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.no-recipe.testlock +++ /dev/null @@ -1,16 +0,0 @@ -{ - "_readme": [ - "This is a fixture file for unit tests" - ], - "content-hash": "abc123", - "packages": [ - { - "name": "silverstripe/framework", - "version": "1.2.3" - }, - { - "name": "silverstripe/cms", - "version": "4.5.6" - } - ] -} diff --git a/tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.recipe-cms-core-and-cwpcore.testlock b/tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.recipe-cms-core-and-cwpcore.testlock deleted file mode 100644 index a3beb11f0c6..00000000000 --- a/tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.recipe-cms-core-and-cwpcore.testlock +++ /dev/null @@ -1,28 +0,0 @@ -{ - "_readme": [ - "This is a fixture file for unit tests" - ], - "content-hash": "abc888", - "packages": [ - { - "name": "silverstripe/framework", - "version": "1.2.3" - }, - { - "name": "silverstripe/cms", - "version": "4.5.6" - }, - { - "name": "silverstripe/recipe-core", - "version": "7.7.7" - }, - { - "name": "silverstripe/recipe-cms", - "version": "8.8.8" - }, - { - "name": "cwp/cwp-core", - "version": "9.9.9" - } - ] -} diff --git a/tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.recipe-core.testlock b/tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.recipe-core.testlock deleted file mode 100644 index 4cf00ce0cf0..00000000000 --- a/tests/php/Core/Manifest/fixtures/VersionProviderTest/composer.recipe-core.testlock +++ /dev/null @@ -1,20 +0,0 @@ -{ - "_readme": [ - "This is a fixture file for unit tests" - ], - "content-hash": "abc777", - "packages": [ - { - "name": "silverstripe/framework", - "version": "1.2.3" - }, - { - "name": "silverstripe/cms", - "version": "4.5.6" - }, - { - "name": "silverstripe/recipe-core", - "version": "7.7.7" - } - ] -}