diff --git a/composer.json b/composer.json index f461963..e2dcdf0 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "php": "^8.3", "silverstripe/framework": "^6", "silverstripe/reports": "^6", - "silverstripe/supported-modules": "dev-main", + "silverstripe/supported-modules": "^1.1", "symbiote/silverstripe-queuedjobs": "^6", "guzzlehttp/guzzle": "^7.5" }, diff --git a/tests/Tasks/UpdatePackageInfoTest.php b/tests/Tasks/UpdatePackageInfoTest.php index e034aca..7cb4d33 100644 --- a/tests/Tasks/UpdatePackageInfoTest.php +++ b/tests/Tasks/UpdatePackageInfoTest.php @@ -7,10 +7,10 @@ use RuntimeException; use BringYourOwnIdeas\Maintenance\Tasks\UpdatePackageInfoTask; use BringYourOwnIdeas\Maintenance\Model\Package; +use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Manifest\VersionProvider; use SilverStripe\Dev\SapphireTest; use SilverStripe\SupportedModules\MetaData; -use SilverStripe\Core\Injector\Injector; use SilverStripe\PolyExecution\PolyOutput; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; @@ -50,56 +50,61 @@ public function testGetPackageInfo() public function testPackagesAreAddedCorrectly() { - // 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 + $oldVersionProvider = Injector::inst()->get(VersionProvider::class); + try { + // 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) + ->onlyMethods(['getLock'])->getMock(); + $composerLoader->expects($this->any())->method('getLock')->willReturn(json_decode(<<registerService(new $mockVersionProvider(), VersionProvider::class); - $composerLoader = $this->getMockBuilder(ComposerLoader::class) - ->onlyMethods(['getLock'])->getMock(); - $composerLoader->expects($this->any())->method('getLock')->willReturn(json_decode(<<setComposerLoader($composerLoader); - $output = PolyOutput::create(PolyOutput::FORMAT_ANSI); - $output->setWrappedOutput(new BufferedOutput()); - $input = new ArrayInput([]); - $input->setInteractive(false); - $task->run($input, $output); + $task = UpdatePackageInfoTask::create(); + $task->setComposerLoader($composerLoader); + $output = PolyOutput::create(PolyOutput::FORMAT_ANSI); + $output->setWrappedOutput(new BufferedOutput()); + $input = new ArrayInput([]); + $input->setInteractive(false); + $task->run($input, $output); - $packages = Package::get(); - $this->assertCount(2, $packages); + $packages = Package::get(); + $this->assertCount(2, $packages); - $package = $packages->find('Name', 'silverstripe/framework'); - $this->assertInstanceOf(Package::class, $package); - $this->assertEquals(1, $package->Supported); + $package = $packages->find('Name', 'silverstripe/framework'); + $this->assertInstanceOf(Package::class, $package); + $this->assertEquals(1, $package->Supported); - $package = $packages->find('Name', 'fake/unsupported-package'); - $this->assertInstanceOf(Package::class, $package); - $this->assertEquals(0, $package->Supported); + $package = $packages->find('Name', 'fake/unsupported-package'); + $this->assertInstanceOf(Package::class, $package); + $this->assertEquals(0, $package->Supported); + } finally { + Injector::inst()->registerService($oldVersionProvider, VersionProvider::class); + } } }