From 64502bc354732d79ffee72ac606b4ccb8b543f6c Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 14 Aug 2024 12:24:08 +1200 Subject: [PATCH] MNT Mock version of framework --- tests/Tasks/UpdatePackageInfoTest.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/Tasks/UpdatePackageInfoTest.php b/tests/Tasks/UpdatePackageInfoTest.php index 2319784..cdb11a1 100644 --- a/tests/Tasks/UpdatePackageInfoTest.php +++ b/tests/Tasks/UpdatePackageInfoTest.php @@ -10,6 +10,7 @@ use SilverStripe\Core\Manifest\VersionProvider; use SilverStripe\Dev\SapphireTest; use SilverStripe\SupportedModules\MetaData; +use SilverStripe\Core\Injector\Injector; /** * @mixin PHPUnit_Framework_TestCase @@ -46,9 +47,18 @@ public function testGetPackageInfo() public function testPackagesAreAddedCorrectly() { - $task = UpdatePackageInfoTask::create(); - - $frameworkVersion = VersionProvider::singleton()->getModuleVersion('silverstripe/framework'); + // Mock the version provider to return a known version because VersionProvider + // will normally read the projects composer.lock file to get the version of framework + // which is often a forked version of silverstripe/framework + // This does need to match a supported major version in silverstripe/supported-modules + // repositories.json + $mockVersionProvider = new class extends VersionProvider { + public function getModuleVersion(string $module): string + { + return '6.0.0'; + } + }; + Injector::inst()->registerService(new $mockVersionProvider(), VersionProvider::class); $composerLoader = $this->getMockBuilder(ComposerLoader::class) ->setMethods(['getLock'])->getMock(); $composerLoader->expects($this->any())->method('getLock')->will($this->returnValue(json_decode(<<setComposerLoader($composerLoader); + $task = UpdatePackageInfoTask::create(); + $task->setComposerLoader($composerLoader); $task->run(null); $packages = Package::get();