Skip to content

Commit ab6e176

Browse files
Merge pull request #74 from creative-commoners/pulls/1/support-php-83
MNT New PHP 8.3 support
2 parents 313a706 + 628434f commit ab6e176

File tree

3 files changed

+268
-27
lines changed

3 files changed

+268
-27
lines changed

consts.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@
3131
'8.1',
3232
'8.2',
3333
],
34+
'5.2' => [
35+
'8.1',
36+
'8.2',
37+
'8.3',
38+
],
3439
'5' => [
3540
'8.1',
3641
'8.2',
42+
'8.3',
3743
],
3844
];
3945

job_creator.php

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,23 +197,33 @@ private function isAllowedPhpVersion(string $phpVersion)
197197
return false;
198198
}
199199

200-
private function getPhpVersion(int $phpIndex): string
200+
/**
201+
* Get the branch name from the installer version and left only the minor version
202+
* e.g. 4.10.x-dev -> 4.10
203+
*/
204+
private function getBranchName(): string
201205
{
202-
if ($this->phpVersionOverride) {
203-
return $this->phpVersionOverride;
204-
}
205-
$key = str_replace('.x-dev', '', $this->installerVersion);
206+
$version = str_replace('.x-dev', '', $this->installerVersion);
206207
$repo = explode('/', $this->githubRepository)[1];
207208
if (in_array($repo, NO_INSTALLER_LOCKSTEPPED_REPOS)) {
208209
$cmsMajor = $this->getCmsMajor();
209210
$branch = $this->getCleanedBranch();
210211
if (preg_match('#^[1-9]$#', $branch)) {
211-
$key = $cmsMajor;
212+
$version = $cmsMajor;
212213
} elseif (preg_match('#^[1-9]\.([0-9]+)$#', $branch, $matches)) {
213-
$key = sprintf('%d.%d', $cmsMajor, $matches[1]);
214+
$version = sprintf('%d.%d', $cmsMajor, $matches[1]);
214215
}
215216
}
216-
$phpVersions = INSTALLER_TO_PHP_VERSIONS[$key] ?? INSTALLER_TO_PHP_VERSIONS['4'];
217+
218+
return $version;
219+
}
220+
221+
private function getPhpVersion(int $phpIndex): string
222+
{
223+
if ($this->phpVersionOverride) {
224+
return $this->phpVersionOverride;
225+
}
226+
$phpVersions = $this->getListOfPhpVersionsByBranchName();
217227
// Use the max allowed php version
218228
if (!array_key_exists($phpIndex, $phpVersions)) {
219229
for ($i = count($phpVersions) - 1; $i >= 0; $i--) {
@@ -235,6 +245,7 @@ private function getPhpVersion(int $phpIndex): string
235245
return $phpVersion;
236246
}
237247
}
248+
238249
throw new Exception("No valid PHP version allowed");
239250
}
240251

@@ -369,21 +380,57 @@ private function createPhpunitJobs(
369380
'phpunit_suite' => $suite,
370381
]);
371382
} elseif ($this->getCmsMajor() === '5') {
372-
$matrix['include'][] = $this->createJob(0, [
373-
'db' => DB_MARIADB,
374-
'phpunit' => true,
375-
'phpunit_suite' => $suite,
376-
]);
377-
$matrix['include'][] = $this->createJob(1, [
378-
'db' => DB_MYSQL_80,
379-
'phpunit' => true,
380-
'phpunit_suite' => $suite,
381-
]);
383+
// phpunit tests for cms 5 are run on php 8.1, 8.2 or 8.3 and mysql 8.0 or mariadb
384+
$phpToDB = $this->generatePhpToDBMap();
385+
foreach ($phpToDB as $php => $db) {
386+
$matrix['include'][] = $this->createJob($this->getIndexByPHPVersion($php), [
387+
'db' => $db,
388+
'phpunit' => true,
389+
'phpunit_suite' => $suite,
390+
]);
391+
}
382392
}
383393
}
384394
return $matrix;
385395
}
386396

397+
/**
398+
* Return the list of php versions for the branch
399+
*/
400+
private function getListOfPhpVersionsByBranchName(): array
401+
{
402+
return INSTALLER_TO_PHP_VERSIONS[$this->getBranchName()] ?? INSTALLER_TO_PHP_VERSIONS['4'];
403+
}
404+
405+
/**
406+
* Return the index of the php version in the list of php versions for the branch
407+
*/
408+
private function getIndexByPHPVersion(string $version): int
409+
{
410+
return array_search($version, $this->getListOfPhpVersionsByBranchName()) ?? 0;
411+
}
412+
413+
/**
414+
* Generate a map of php versions to db versions
415+
* e.g. [ '8.1' => 'mariadb', '8.2' => 'mysql80' ]
416+
*/
417+
private function generatePhpToDBMap(): array
418+
{
419+
$map = [];
420+
$phpVersions = $this->getListOfPhpVersionsByBranchName();
421+
$dbs = [DB_MARIADB, DB_MYSQL_80];
422+
foreach ($phpVersions as $key => $phpVersion) {
423+
if (count($phpVersions) < 3) {
424+
$map[$phpVersion] = $dbs[$key];
425+
} else {
426+
if ($key === 0) continue;
427+
$map[$phpVersion] = array_key_exists($key, $dbs) ? $dbs[$key - 1] : DB_MYSQL_80;
428+
}
429+
}
430+
431+
return $map;
432+
}
433+
387434
private function doRunPhpCoverage(array $run): bool
388435
{
389436
// (currently disabled) always run on silverstripe account, unless phpcoverage_force_off is set to true

tests/JobCreatorTest.php

Lines changed: 197 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,70 @@ public function provideCreateJson(): array
263263
],
264264
[
265265
'installer_version' => '5.x-dev',
266+
'php' => '8.2',
267+
'db' => DB_MARIADB,
268+
'composer_require_extra' => '',
269+
'composer_args' => '',
270+
'name_suffix' => '',
271+
'phpunit' => 'true',
272+
'phpunit_suite' => 'all',
273+
'phplinting' => 'false',
274+
'phpcoverage' => 'false',
275+
'endtoend' => 'false',
276+
'endtoend_suite' => 'root',
277+
'endtoend_config' => '',
278+
'js' => 'false',
279+
'name' => '8.2 mariadb phpunit all',
280+
],
281+
[
282+
'installer_version' => '5.x-dev',
283+
'php' => '8.3',
284+
'db' => DB_MYSQL_80,
285+
'composer_require_extra' => '',
286+
'composer_args' => '',
287+
'name_suffix' => '',
288+
'phpunit' => 'true',
289+
'phpunit_suite' => 'all',
290+
'phplinting' => 'false',
291+
'phpcoverage' => 'false',
292+
'endtoend' => 'false',
293+
'endtoend_suite' => 'root',
294+
'endtoend_config' => '',
295+
'js' => 'false',
296+
'name' => '8.3 mysql80 phpunit all',
297+
],
298+
]
299+
],
300+
// general test for v5.1
301+
[
302+
implode("\n", [
303+
$this->getGenericYml(),
304+
<<<EOT
305+
github_repository: 'myaccount/silverstripe-framework'
306+
github_my_ref: '5.1'
307+
parent_branch: ''
308+
EOT
309+
]),
310+
[
311+
[
312+
'installer_version' => '5.1.x-dev',
313+
'php' => '8.1',
314+
'db' => DB_MYSQL_57,
315+
'composer_require_extra' => '',
316+
'composer_args' => '--prefer-lowest',
317+
'name_suffix' => '',
318+
'phpunit' => 'true',
319+
'phpunit_suite' => 'all',
320+
'phplinting' => 'false',
321+
'phpcoverage' => 'false',
322+
'endtoend' => 'false',
323+
'endtoend_suite' => 'root',
324+
'endtoend_config' => '',
325+
'js' => 'false',
326+
'name' => '8.1 prf-low mysql57 phpunit all',
327+
],
328+
[
329+
'installer_version' => '5.1.x-dev',
266330
'php' => '8.1',
267331
'db' => DB_MARIADB,
268332
'composer_require_extra' => '',
@@ -279,7 +343,7 @@ public function provideCreateJson(): array
279343
'name' => '8.1 mariadb phpunit all',
280344
],
281345
[
282-
'installer_version' => '5.x-dev',
346+
'installer_version' => '5.1.x-dev',
283347
'php' => '8.2',
284348
'db' => DB_MYSQL_80,
285349
'composer_require_extra' => '',
@@ -297,6 +361,70 @@ public function provideCreateJson(): array
297361
],
298362
]
299363
],
364+
// general test for v5.2
365+
[
366+
implode("\n", [
367+
$this->getGenericYml(),
368+
<<<EOT
369+
github_repository: 'myaccount/silverstripe-framework'
370+
github_my_ref: '5.2'
371+
parent_branch: ''
372+
EOT
373+
]),
374+
[
375+
[
376+
'installer_version' => '5.2.x-dev',
377+
'php' => '8.1',
378+
'db' => DB_MYSQL_57,
379+
'composer_require_extra' => '',
380+
'composer_args' => '--prefer-lowest',
381+
'name_suffix' => '',
382+
'phpunit' => 'true',
383+
'phpunit_suite' => 'all',
384+
'phplinting' => 'false',
385+
'phpcoverage' => 'false',
386+
'endtoend' => 'false',
387+
'endtoend_suite' => 'root',
388+
'endtoend_config' => '',
389+
'js' => 'false',
390+
'name' => '8.1 prf-low mysql57 phpunit all',
391+
],
392+
[
393+
'installer_version' => '5.2.x-dev',
394+
'php' => '8.2',
395+
'db' => DB_MARIADB,
396+
'composer_require_extra' => '',
397+
'composer_args' => '',
398+
'name_suffix' => '',
399+
'phpunit' => 'true',
400+
'phpunit_suite' => 'all',
401+
'phplinting' => 'false',
402+
'phpcoverage' => 'false',
403+
'endtoend' => 'false',
404+
'endtoend_suite' => 'root',
405+
'endtoend_config' => '',
406+
'js' => 'false',
407+
'name' => '8.2 mariadb phpunit all',
408+
],
409+
[
410+
'installer_version' => '5.2.x-dev',
411+
'php' => '8.3',
412+
'db' => DB_MYSQL_80,
413+
'composer_require_extra' => '',
414+
'composer_args' => '',
415+
'name_suffix' => '',
416+
'phpunit' => 'true',
417+
'phpunit_suite' => 'all',
418+
'phplinting' => 'false',
419+
'phpcoverage' => 'false',
420+
'endtoend' => 'false',
421+
'endtoend_suite' => 'root',
422+
'endtoend_config' => '',
423+
'js' => 'false',
424+
'name' => '8.3 mysql80 phpunit all',
425+
],
426+
]
427+
],
300428
];
301429
}
302430

@@ -675,9 +803,9 @@ public function provideGetInstallerVersionCMS5FromComposer(): array
675803
// fallback to looking at deps in composer.json, use current minor of installer .x-dev
676804
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '5.x-dev'], '5.x-dev'],
677805
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '5.0.x-dev'], '5.0.x-dev'],
678-
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^5'], '5.1.x-dev'],
679-
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^5'], '5.1.x-dev'],
680-
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^2'], '5.1.x-dev'],
806+
['myaccount/silverstripe-admin', 'mybranch', ['silverstripe/framework' => '^5'], '5.2.x-dev'],
807+
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/cms' => '^5'], '5.2.x-dev'],
808+
['myaccount/silverstripe-somemodule', 'mybranch', ['silverstripe/admin' => '^2'], '5.2.x-dev'],
681809
['myaccount/silverstripe-somemodule', '3', ['silverstripe/framework' => '^5'], '5.x-dev'],
682810
];
683811
}
@@ -771,8 +899,8 @@ public function provideComposerInstall(): array
771899
'5.x-dev',
772900
[
773901
'8.1 prf-low mysql57 phpunit all',
774-
'8.1 mariadb phpunit all',
775-
'8.2 mysql80 phpunit all'
902+
'8.2 mariadb phpunit all',
903+
'8.3 mysql80 phpunit all',
776904
]
777905
],
778906
'composerupgrade_definedphpversion_framework5' => [
@@ -781,18 +909,78 @@ public function provideComposerInstall(): array
781909
'5.x-dev',
782910
[
783911
'8.1 prf-low mysql57 phpunit all',
784-
'8.1 mariadb phpunit all',
785-
'8.2 mysql80 phpunit all'
912+
'8.2 mariadb phpunit all',
913+
'8.3 mysql80 phpunit all',
786914
]
787915
],
788916
'composerupgrade_invalidphpversion_framework5' => [
789917
'false',
790918
'fish',
791919
'5.x-dev',
920+
[
921+
'8.1 prf-low mysql57 phpunit all',
922+
'8.2 mariadb phpunit all',
923+
'8.3 mysql80 phpunit all',
924+
]
925+
],
926+
'composerupgrade_nophpversion_framework51' => [
927+
'false',
928+
'',
929+
'5.1.x-dev',
930+
[
931+
'8.1 prf-low mysql57 phpunit all',
932+
'8.1 mariadb phpunit all',
933+
'8.2 mysql80 phpunit all',
934+
]
935+
],
936+
'composerupgrade_definedphpversion_framework51' => [
937+
'false',
938+
'21.99',
939+
'5.1.x-dev',
940+
[
941+
'8.1 prf-low mysql57 phpunit all',
942+
'8.1 mariadb phpunit all',
943+
'8.2 mysql80 phpunit all',
944+
]
945+
],
946+
'composerupgrade_invalidphpversion_framework51' => [
947+
'false',
948+
'fish',
949+
'5.1.x-dev',
792950
[
793951
'8.1 prf-low mysql57 phpunit all',
794952
'8.1 mariadb phpunit all',
795-
'8.2 mysql80 phpunit all'
953+
'8.2 mysql80 phpunit all',
954+
]
955+
],
956+
'composerupgrade_nophpversion_framework52' => [
957+
'false',
958+
'',
959+
'5.2.x-dev',
960+
[
961+
'8.1 prf-low mysql57 phpunit all',
962+
'8.2 mariadb phpunit all',
963+
'8.3 mysql80 phpunit all',
964+
]
965+
],
966+
'composerupgrade_definedphpversion_framework52' => [
967+
'false',
968+
'21.99',
969+
'5.2.x-dev',
970+
[
971+
'8.1 prf-low mysql57 phpunit all',
972+
'8.2 mariadb phpunit all',
973+
'8.3 mysql80 phpunit all',
974+
]
975+
],
976+
'composerupgrade_invalidphpversion_framework52' => [
977+
'false',
978+
'fish',
979+
'5.2.x-dev',
980+
[
981+
'8.1 prf-low mysql57 phpunit all',
982+
'8.2 mariadb phpunit all',
983+
'8.3 mysql80 phpunit all',
796984
]
797985
],
798986
];

0 commit comments

Comments
 (0)