Skip to content

Commit

Permalink
Merge branch '3' into 4
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 21, 2024
2 parents 5690e89 + 2659275 commit 3165283
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 47 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.3",
"silverstripe/framework": "^6",
"silverstripe/reports": "^6",
"silverstripe/supported-modules": "dev-main",
"silverstripe/supported-modules": "^1.1",
"symbiote/silverstripe-queuedjobs": "^6",
"guzzlehttp/guzzle": "^7.5"
},
Expand Down
97 changes: 51 additions & 46 deletions tests/Tasks/UpdatePackageInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
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;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\PolyExecution\PolyOutput;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
Expand Down Expand Up @@ -50,56 +50,61 @@ public function testGetPackageInfo()

public function testPackagesAreAddedCorrectly()
{
// 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
$oldVersionProvider = Injector::inst()->get(VersionProvider::class);
try {
// 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)
->onlyMethods(['getLock'])->getMock();
$composerLoader->expects($this->any())->method('getLock')->willReturn(json_decode(<<<LOCK
{
"packages": [
{
return '6.0.0';
"name": "silverstripe/framework",
"description": "A faux package from a mocked composer.lock for testing purposes",
"version": "6.0.0"
},
{
"name": "fake/unsupported-package",
"description": "A faux package from a mocked composer.lock for testing purposes",
"version": "1.0.0"
}
};
Injector::inst()->registerService(new $mockVersionProvider(), VersionProvider::class);
$composerLoader = $this->getMockBuilder(ComposerLoader::class)
->onlyMethods(['getLock'])->getMock();
$composerLoader->expects($this->any())->method('getLock')->willReturn(json_decode(<<<LOCK
{
"packages": [
{
"name": "silverstripe/framework",
"description": "A faux package from a mocked composer.lock for testing purposes",
"version": "6.0.0"
},
{
"name": "fake/unsupported-package",
"description": "A faux package from a mocked composer.lock for testing purposes",
"version": "1.0.0"
}
],
"packages-dev": null
}
LOCK
));
],
"packages-dev": null
}
LOCK
));

$task = UpdatePackageInfoTask::create();
$task->setComposerLoader($composerLoader);
$output = PolyOutput::create(PolyOutput::FORMAT_ANSI);
$output->setWrappedOutput(new BufferedOutput());
$input = new ArrayInput([]);
$input->setInteractive(false);
$task->run($input, $output);
$task = UpdatePackageInfoTask::create();
$task->setComposerLoader($composerLoader);
$output = PolyOutput::create(PolyOutput::FORMAT_ANSI);
$output->setWrappedOutput(new BufferedOutput());
$input = new ArrayInput([]);
$input->setInteractive(false);
$task->run($input, $output);

$packages = Package::get();
$this->assertCount(2, $packages);
$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', '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);
$package = $packages->find('Name', 'fake/unsupported-package');
$this->assertInstanceOf(Package::class, $package);
$this->assertEquals(0, $package->Supported);
} finally {
Injector::inst()->registerService($oldVersionProvider, VersionProvider::class);
}
}
}

0 comments on commit 3165283

Please sign in to comment.