Skip to content

Commit

Permalink
Merge pull request #11199 from kinglozzer/11197-oob-exception
Browse files Browse the repository at this point in the history
FIX: OutOfBoundsException when recipe-core isn't installed (fixes #11197)
  • Loading branch information
GuySartorelli committed Apr 16, 2024
2 parents 6743de4 + a53301f commit 908bdcf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Core/Manifest/VersionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ public function getModuleVersionFromComposer($modules = [])
{
$versions = [];
foreach ($modules as $module) {
if (!InstalledVersions::isInstalled($module)) {
continue;
}
$versions[$module] = InstalledVersions::getPrettyVersion($module);
}
return $versions;
Expand Down
21 changes: 21 additions & 0 deletions tests/php/Core/Manifest/VersionProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ public function testGetModuleVersion()
$this->assertStringNotContainsString('Framework: 1.2.3', $result);
}

public function testGetModuleVersionWhenPackageMayNotBeInstalled()
{
if (!class_exists(VersionParser::class)) {
$this->markTestSkipped('This test requires composer/semver to be installed');
}
$provider = $this->getProvider();
// VersionProvider::getModuleVersion() will loop over the modules defined in the "modules" config value, which
// may sometimes include packages that are optional (e.g. recipe-core). This tests that the version can still
// be found even if non-existent modules are encountered
Config::modify()->set(VersionProvider::class, 'modules', [
'this/module/cannot/possibly/exist' => 'Oopsies',
'silverstripe/framework' => 'Framework',
'silverstripe/another-module-that-does-not-exist' => 'Sapphire',
]);
$moduleVersion = $provider->getModuleVersion('silverstripe/framework');
$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);
}

private function clearCache()
{
$cache = Injector::inst()->get(CacheInterface::class . '.VersionProvider');
Expand Down

0 comments on commit 908bdcf

Please sign in to comment.