Add assertError method to ApiResponse and enhance CI test failure handling

This commit is contained in:
Jeppe Bundgaard
2026-07-08 13:03:33 +02:00
parent 940a3e5e9b
commit 870b88e707
8 changed files with 52 additions and 7 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -330,7 +330,7 @@ class productsRoute
}
);
}
if ($restrictCustomerBookingProducts) {
if ($restrictCustomerBookingProducts && !$productId) {
$products = $this->filterProductsVisibleOnBookingForm($products);
}
// Return all products, with the department pricing and customer discounts applied
@@ -39,9 +39,7 @@ function order_booking_create_department(string $name): array
function order_booking_create_department_price(int $departmentId, int $productId, int $price): void
{
global $db;
$statement = $db->prepare(
$statement = api_test_runtime()->db()->prepare(
'INSERT INTO `product_department_prices` (`department_id`, `product_id`, `price`)
VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE `price` = VALUES(`price`)'
@@ -425,10 +425,12 @@ it('edits and deletes only matching customer vehicles through the user-scoped su
], $session['headers']);
$deleted = api_client()->delete(
'/superuser/users/' . $targetUser['id'] . '/vehicles?id=' . $deletableVehicle['id'],
null,
$session['headers']
);
$foreignDelete = api_client()->delete(
'/superuser/users/' . $targetUser['id'] . '/vehicles?id=' . $otherVehicle['id'],
null,
$session['headers']
);
@@ -48,6 +48,11 @@ final class ApiResponse
return $this;
}
public function assertError(): self
{
return $this->assertSuccess(false);
}
public function assertMessage(string $expectedMessage): self
{
$this->assertEnvelope();
@@ -14,6 +14,10 @@ class ApiTestCase extends TestCase
$skipReason = \api_test_runtime()->skipReason();
if ($skipReason !== null) {
if (getenv('API_TEST_FAIL_ON_SKIP') === '1') {
throw new \RuntimeException($skipReason);
}
$this->markTestSkipped($skipReason);
}
@@ -47,13 +47,31 @@ $commands = [
'RUN_INTEGRATION_TESTS=1 vendor/bin/pest --testsuite=Integration --colors=always',
],
'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' => [
'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
{
$database = getenv('CONFIG_DB_DATABASE') ?: 'nnks_db_debug';
@@ -91,6 +109,10 @@ function reset_ci_state(): void
if ($suite === 'all') {
foreach (['unit', 'integration', 'api', 'legacy'] as $selectedSuite) {
if (in_array($selectedSuite, ['api', 'legacy'], true)) {
assert_required_php_extensions(['mysqli']);
}
reset_ci_state();
foreach ($commands[$selectedSuite] as $command) {
passthru($command, $exitCode);
@@ -107,6 +129,10 @@ if ($suite === 'all') {
exit(2);
}
if (in_array($suite, ['api', 'legacy'], true)) {
assert_required_php_extensions(['mysqli']);
}
foreach ($selectedCommands as $command) {
passthru($command, $exitCode);
if ($exitCode !== 0) {
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
it('fails CI API runs instead of allowing runtime bootstrap skips to pass', function (): void {
$runner = (string)file_get_contents(__DIR__ . '/../../Support/run_ci_suite.php');
expect($runner)->toContain('API_TEST_FAIL_ON_SKIP=1')
->and($runner)->toContain("assert_required_php_extensions(['mysqli'])");
});