Preflight required extensions for API CI

This commit is contained in:
Jeppe B
2026-07-08 12:32:19 +02:00
parent 3817a37021
commit eac83b18a0
@@ -47,13 +47,31 @@ $commands = [
'RUN_INTEGRATION_TESTS=1 vendor/bin/pest --testsuite=Integration --colors=always', 'RUN_INTEGRATION_TESTS=1 vendor/bin/pest --testsuite=Integration --colors=always',
], ],
'api' => [ 'api' => [
'RUN_API_TESTS=1 API_TEST_BOOTSTRAP_SCHEMA=1 API_TEST_ALLOW_LIVE_DB=1 API_TEST_REQUEST_TIMEOUT=180 vendor/bin/pest --testsuite=Api --colors=always', 'RUN_API_TESTS=1 API_TEST_FAIL_ON_SKIP=1 API_TEST_BOOTSTRAP_SCHEMA=1 API_TEST_ALLOW_LIVE_DB=1 API_TEST_REQUEST_TIMEOUT=180 vendor/bin/pest --testsuite=Api --colors=always',
], ],
'legacy' => [ 'legacy' => [
'RUN_LEGACY_TESTS=1 RUN_INTEGRATION_TESTS=1 RUN_API_TESTS=1 API_TEST_BOOTSTRAP_SCHEMA=1 API_TEST_ALLOW_LIVE_DB=1 API_TEST_REQUEST_TIMEOUT=180 vendor/bin/pest --testsuite=Legacy --colors=always', 'RUN_LEGACY_TESTS=1 RUN_INTEGRATION_TESTS=1 RUN_API_TESTS=1 API_TEST_FAIL_ON_SKIP=1 API_TEST_BOOTSTRAP_SCHEMA=1 API_TEST_ALLOW_LIVE_DB=1 API_TEST_REQUEST_TIMEOUT=180 vendor/bin/pest --testsuite=Legacy --colors=always',
], ],
]; ];
/**
* @param array<int, string> $extensions
*/
function assert_required_php_extensions(array $extensions): void
{
$missing = array_values(array_filter(
$extensions,
static fn (string $extension): bool => !extension_loaded($extension)
));
if ($missing === []) {
return;
}
fwrite(STDERR, 'Missing required PHP extension(s): ' . implode(', ', $missing) . PHP_EOL);
exit(1);
}
function reset_ci_state(): void function reset_ci_state(): void
{ {
$database = getenv('CONFIG_DB_DATABASE') ?: 'nnks_db_debug'; $database = getenv('CONFIG_DB_DATABASE') ?: 'nnks_db_debug';
@@ -91,6 +109,10 @@ function reset_ci_state(): void
if ($suite === 'all') { if ($suite === 'all') {
foreach (['unit', 'integration', 'api', 'legacy'] as $selectedSuite) { foreach (['unit', 'integration', 'api', 'legacy'] as $selectedSuite) {
if (in_array($selectedSuite, ['api', 'legacy'], true)) {
assert_required_php_extensions(['mysqli']);
}
reset_ci_state(); reset_ci_state();
foreach ($commands[$selectedSuite] as $command) { foreach ($commands[$selectedSuite] as $command) {
passthru($command, $exitCode); passthru($command, $exitCode);
@@ -107,6 +129,10 @@ if ($suite === 'all') {
exit(2); exit(2);
} }
if (in_array($suite, ['api', 'legacy'], true)) {
assert_required_php_extensions(['mysqli']);
}
foreach ($selectedCommands as $command) { foreach ($selectedCommands as $command) {
passthru($command, $exitCode); passthru($command, $exitCode);
if ($exitCode !== 0) { if ($exitCode !== 0) {