From 9c828fcf723e6f07a1e690e449feddeddc0a939a Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 21 Oct 2024 11:39:44 +1300 Subject: [PATCH] DEP Use stable version of silverstripe/supported-modules --- composer.json | 2 +- tests/Tasks/UpdatePackageInfoTest.php | 84 ++++++++++++++++----------- 2 files changed, 50 insertions(+), 36 deletions(-) diff --git a/composer.json b/composer.json index ee8316e..c478f28 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "php": "^8.1", "silverstripe/framework": "^5.4", "silverstripe/reports": "^5", - "silverstripe/supported-modules": "dev-main", + "silverstripe/supported-modules": "^1", "symbiote/silverstripe-queuedjobs": "^5", "guzzlehttp/guzzle": "^7.5" }, diff --git a/tests/Tasks/UpdatePackageInfoTest.php b/tests/Tasks/UpdatePackageInfoTest.php index 2319784..9d30682 100644 --- a/tests/Tasks/UpdatePackageInfoTest.php +++ b/tests/Tasks/UpdatePackageInfoTest.php @@ -7,6 +7,7 @@ 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; @@ -46,42 +47,55 @@ public function testGetPackageInfo() public function testPackagesAreAddedCorrectly() { - $task = UpdatePackageInfoTask::create(); + $oldVersionProvider = Injector::inst()->get(VersionProvider::class); + try { + $task = UpdatePackageInfoTask::create(); - $frameworkVersion = VersionProvider::singleton()->getModuleVersion('silverstripe/framework'); - $composerLoader = $this->getMockBuilder(ComposerLoader::class) - ->setMethods(['getLock'])->getMock(); - $composerLoader->expects($this->any())->method('getLock')->will($this->returnValue(json_decode(<<getMockBuilder(VersionProvider::class) + ->setMethods(['getModuleVersion']) + ->getMock(); + $versionProvider->expects($this->any())->method('getModuleVersion')->will($this->returnValue('5.9.9')); + Injector::inst()->registerService($versionProvider, VersionProvider::class); + + $frameworkVersion = $versionProvider->getModuleVersion('silverstripe/framework'); + + $composerLoader = $this->getMockBuilder(ComposerLoader::class) + ->setMethods(['getLock'])->getMock(); + $composerLoader->expects($this->any())->method('getLock')->will($this->returnValue(json_decode(<<setComposerLoader($composerLoader); + + $task->run(null); + + $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', 'fake/unsupported-package'); + $this->assertInstanceOf(Package::class, $package); + $this->assertEquals(0, $package->Supported); + } finally { + Injector::inst()->registerService($oldVersionProvider, VersionProvider::class); } - ], - "packages-dev": null -} -LOCK - ))); - $task->setComposerLoader($composerLoader); - - $task->run(null); - - $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', 'fake/unsupported-package'); - $this->assertInstanceOf(Package::class, $package); - $this->assertEquals(0, $package->Supported); } }