Skip to content

Commit

Permalink
ENH Fallback to reading PHP version from composer.json
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 9, 2024
1 parent e35094d commit ee86c41
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
16 changes: 15 additions & 1 deletion job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,21 @@ private function createPhpunitJobs(
private function getListOfPhpVersionsByBranchName(): array
{
$branch = $this->getInstallerBranch();
return MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$branch] ?? MetaData::PHP_VERSIONS_FOR_CMS_RELEASES['4'];
if (isset(MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$branch])) {
return MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$branch];
}
// Fallback to using a CMS major based on the version of PHP in composer.json
$json = $this->getComposerJsonContent();
$cmsMajor = '4';
if ($json) {
$php = $json->require->php ?? null;
$cmsMajor = match($php) {
'^8.1' => '5',
'^8.3' => '6',
default => '4',
};
}
return MetaData::PHP_VERSIONS_FOR_CMS_RELEASES[$cmsMajor];
}

/**
Expand Down
76 changes: 76 additions & 0 deletions tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2299,4 +2299,80 @@ public function testDuplicateJobsRemoved(): void
];
$this->assertSame($expected, $actual);
}

public function providePhpFallbackDoorman(): array
{
return [
'php81' => [
'php' => '^8.1',
'exception' => false,
'expected' => [
'8.1 prf-low mariadb phpunit all',
'8.2 mysql80 phpunit all',
'8.3 mysql84 phpunit all',
],
],
'php83' => [
'php' => '^8.3',
'exception' => false,
'expected' => [
'8.3 prf-low mariadb phpunit all',
'8.3 mysql80 phpunit all',
'8.4 mysql84 phpunit all',
],
],
'none' => [
'php' => 'none',
'exception' => true,
'expected' => null,
],
];
}

/**
* @dataProvider providePhpFallbackDoorman
*/
public function testPhpFallbackDoorman(string $php, bool $exception, ?array $expected): void
{
if (!function_exists('yaml_parse')) {
$this->markTestSkipped('yaml extension is not installed');
}
if ($exception) {
$this->expectException(Exception::class);
}
try {
$yml = implode("\n", [
<<<EOT
composer_install: false
endtoend: true
js: true
phpcoverage: false
phpcoverage_force_off: false
phplinting: true
phpunit: true
doclinting: true
phpunit_skip_suites: ''
dynamic_matrix: true
simple_matrix: false
github_repository: 'silverstripe/doorman'
github_my_ref: '5'
parent_branch: ''
EOT
]);
$creator = new JobCreator();
$creator->composerJsonPath = '__composer.json';
$this->writeComposerJson(['php' => $php]);
$creator->githubRepository = 'silverstripe/doorman';
$creator->repoName = 'doorman';
$creator->branch = '5';
$creator->parseRepositoryMetadata();
$json = json_decode($creator->createJson($yml));
$actual = array_map(fn($job) => $job->name, $json->include);
$this->assertSame($expected, $actual);
} finally {
if (file_exists('__composer.json')) {
unlink('__composer.json');
}
}
}
}

0 comments on commit ee86c41

Please sign in to comment.