Skip to content

Commit 00933af

Browse files
Merge pull request #115 from creative-commoners/pulls/1.17/doorman
ENH Fallback to reading PHP version from composer.json
2 parents 1908713 + 8754dbb commit 00933af

File tree

2 files changed

+101
-6
lines changed

2 files changed

+101
-6
lines changed

job_creator.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,26 @@ private function createPhpunitJobs(
368368
private function getListOfPhpVersionsByBranchName(): array
369369
{
370370
$branch = $this->getInstallerBranch();
371-
return MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$branch] ?? MetaData::PHP_VERSIONS_FOR_CMS_RELEASES['4'];
371+
if (isset(MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$branch])) {
372+
return MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$branch];
373+
}
374+
// Fallback to using a CMS major based on the version of PHP in composer.json
375+
$json = $this->getComposerJsonContent();
376+
if ($json) {
377+
$php = $json->require->php ?? null;
378+
$php = str_replace('^', '', $php);
379+
$cmsMajors = array_keys(MetaData::PHP_VERSIONS_FOR_CMS_RELEASES);
380+
$cmsMajors = array_filter($cmsMajors, fn($v) => !str_contains($v, '.'));
381+
$cmsMajors = array_reverse($cmsMajors);
382+
foreach ($cmsMajors as $cmsMajor) {
383+
$phpVersions = MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$cmsMajor];
384+
if (in_array($php, $phpVersions)) {
385+
return $phpVersions;
386+
}
387+
}
388+
}
389+
// Fallback to the PHP versions allowed for the lowest supported major release line
390+
return MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[MetaData::LOWEST_SUPPORTED_CMS_MAJOR];
372391
}
373392

374393
/**

tests/JobCreatorTest.php

+81-5
Original file line numberDiff line numberDiff line change
@@ -1988,16 +1988,16 @@ public function provideGetInstallerVersionFromComposer(): array
19881988
// the `6.0` branches are created - currently only `6` branches exist
19891989
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '6.x-dev'], 'silverstripe-module', '6.x-dev'],
19901990
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '6.0.x-dev'], 'silverstripe-vendormodule', '6.0.x-dev'],
1991-
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^6'], 'silverstripe-theme', '6.x-dev'],
1992-
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^6'], 'silverstripe-recipe', '6.x-dev'],
1993-
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^3'], 'silverstripe-vendormodule', '6.x-dev'],
1991+
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^6'], 'silverstripe-theme', '6.0.x-dev'],
1992+
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^6'], 'silverstripe-recipe', '6.0.x-dev'],
1993+
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^3'], 'silverstripe-vendormodule', '6.0.x-dev'],
19941994
['myaccount/silverstripe-somemodule', '4', ['silverstripe/framework' => '^6'], 'silverstripe-vendormodule', '6.x-dev'],
19951995
['myaccount/silverstripe-somemodule', '4', ['silverstripe/framework' => '^6'], 'package', ''],
19961996
['myaccount/silverstripe-somemodule', '4', ['silverstripe/framework' => '^6'], '', ''],
19971997
['myaccount/silverstripe-somemodule', '4', [], '', ''],
19981998
// // recipe-plugin and vendor-plugin do not override framework
1999-
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/recipe-plugin' => '^2', 'silverstripe/framework' => '^6'], 'silverstripe-vendormodule', '6.x-dev'],
2000-
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/vendor-plugin' => '^2', 'silverstripe/framework' => '^6'], 'silverstripe-vendormodule', '6.x-dev'],
1999+
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/recipe-plugin' => '^2', 'silverstripe/framework' => '^6'], 'silverstripe-vendormodule', '6.0.x-dev'],
2000+
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/vendor-plugin' => '^2', 'silverstripe/framework' => '^6'], 'silverstripe-vendormodule', '6.0.x-dev'],
20012001
];
20022002
}
20032003

@@ -2299,4 +2299,80 @@ public function testDuplicateJobsRemoved(): void
22992299
];
23002300
$this->assertSame($expected, $actual);
23012301
}
2302+
2303+
public function providePhpFallbackDoorman(): array
2304+
{
2305+
return [
2306+
'php81' => [
2307+
'php' => '^8.1',
2308+
'exception' => false,
2309+
'expected' => [
2310+
'8.1 prf-low mariadb phpunit all',
2311+
'8.2 mysql80 phpunit all',
2312+
'8.3 mysql84 phpunit all',
2313+
],
2314+
],
2315+
'php83' => [
2316+
'php' => '^8.3',
2317+
'exception' => false,
2318+
'expected' => [
2319+
'8.3 prf-low mariadb phpunit all',
2320+
'8.3 mysql80 phpunit all',
2321+
'8.4 mysql84 phpunit all',
2322+
],
2323+
],
2324+
'none' => [
2325+
'php' => 'none',
2326+
'exception' => true,
2327+
'expected' => null,
2328+
],
2329+
];
2330+
}
2331+
2332+
/**
2333+
* @dataProvider providePhpFallbackDoorman
2334+
*/
2335+
public function testPhpFallbackDoorman(string $php, bool $exception, ?array $expected): void
2336+
{
2337+
if (!function_exists('yaml_parse')) {
2338+
$this->markTestSkipped('yaml extension is not installed');
2339+
}
2340+
if ($exception) {
2341+
$this->expectException(Exception::class);
2342+
}
2343+
try {
2344+
$yml = implode("\n", [
2345+
<<<EOT
2346+
composer_install: false
2347+
endtoend: true
2348+
js: true
2349+
phpcoverage: false
2350+
phpcoverage_force_off: false
2351+
phplinting: true
2352+
phpunit: true
2353+
doclinting: true
2354+
phpunit_skip_suites: ''
2355+
dynamic_matrix: true
2356+
simple_matrix: false
2357+
github_repository: 'silverstripe/doorman'
2358+
github_my_ref: '5'
2359+
parent_branch: ''
2360+
EOT
2361+
]);
2362+
$creator = new JobCreator();
2363+
$creator->composerJsonPath = '__composer.json';
2364+
$this->writeComposerJson(['php' => $php]);
2365+
$creator->githubRepository = 'silverstripe/doorman';
2366+
$creator->repoName = 'doorman';
2367+
$creator->branch = '5';
2368+
$creator->parseRepositoryMetadata();
2369+
$json = json_decode($creator->createJson($yml));
2370+
$actual = array_map(fn($job) => $job->name, $json->include);
2371+
$this->assertSame($expected, $actual);
2372+
} finally {
2373+
if (file_exists('__composer.json')) {
2374+
unlink('__composer.json');
2375+
}
2376+
}
2377+
}
23022378
}

0 commit comments

Comments
 (0)