Skip to content

Commit

Permalink
DEP Use stable version of silverstripe/supported-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 20, 2024
1 parent 40dd03d commit 9c828fc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 36 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
84 changes: 49 additions & 35 deletions tests/Tasks/UpdatePackageInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(<<<LOCK
{
"packages": [
{
"name": "silverstripe/framework",
"description": "A faux package from a mocked composer.lock for testing purposes",
"version": "$frameworkVersion"
},
{
"name": "fake/unsupported-package",
"description": "A faux package from a mocked composer.lock for testing purposes",
"version": "1.0.0"
/** @var VersionProvider $versionProvider */
$versionProvider = $this->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(<<<LOCK
{
"packages": [
{
"name": "silverstripe/framework",
"description": "A faux package from a mocked composer.lock for testing purposes",
"version": "$frameworkVersion"
},
{
"name": "fake/unsupported-package",
"description": "A faux package from a mocked composer.lock for testing purposes",
"version": "1.0.0"
}
],
"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);
} 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);
}
}

0 comments on commit 9c828fc

Please sign in to comment.