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

MNT Mock version of framework #236

Merged
Merged
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
21 changes: 16 additions & 5 deletions tests/Tasks/UpdatePackageInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(<<<LOCK
Expand All @@ -57,7 +67,7 @@ public function testPackagesAreAddedCorrectly()
{
"name": "silverstripe/framework",
"description": "A faux package from a mocked composer.lock for testing purposes",
"version": "$frameworkVersion"
"version": "6.0.0"
},
{
"name": "fake/unsupported-package",
Expand All @@ -69,8 +79,9 @@ public function testPackagesAreAddedCorrectly()
}
LOCK
)));
$task->setComposerLoader($composerLoader);

$task = UpdatePackageInfoTask::create();
$task->setComposerLoader($composerLoader);
$task->run(null);

$packages = Package::get();
Expand Down
Loading