Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP Use stable version of silverstripe/supported-modules #246

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to fix a long standing broken unit test when running sink with a forked framework version

The new try/finally block is to reset Injector::inst()->registerService($versionProvider, VersionProvider::class); back from the mock VersionProvider, to the original VersionProvder. Looking through the sapphire teststate code it's not immediately clear to me whether this is required or not (quite possibly it's not and it resets itself between tests), however I don't want to risk causing a regression later on in a subsequent unit test

Looking through the teststate stuff, it's not immediately clear to me whether or not resetting the


$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);
}
}