From 0dc17981b1aa44b8aa63965582f8bbc16587fae6 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 22 Aug 2024 12:56:33 +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();