Skip to content

Commit

Permalink
MNT Mock version of framework
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Aug 22, 2024
1 parent 09adf38 commit 0dc1798
Showing 1 changed file with 16 additions and 5 deletions.
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

0 comments on commit 0dc1798

Please sign in to comment.