2ad6e9cf02
API CI/CD / Validate (composer + pint) (push) Successful in 2m51s
API CI/CD / Test (PHPUnit) (push) Failing after 3m6s
API CI/CD / Build frontend assets (push) Failing after 5m23s
API CI/CD / Security audit (push) Failing after 34s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
70 lines
2.6 KiB
PHP
70 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Api\V1\FullSurface;
|
|
|
|
use Tests\Feature\Api\V1\FullSurface\Support\FullSurfaceE2EContractCase;
|
|
|
|
class ApiDataShapeBackwardCompatibilityContractTest extends FullSurfaceE2EContractCase
|
|
{
|
|
public function test_collection_endpoints_keep_backward_compatible_envelope_keys(): void
|
|
{
|
|
$routes = array_slice(array_filter($this->apiRoutes(), fn ($route) => $this->primaryMethod($route) === 'GET' && ! str_contains($route->uri(), '{')), 0, 120);
|
|
|
|
foreach ($routes as $route) {
|
|
$uri = $route->uri();
|
|
if ($this->isOpenApiDocumentRoute($uri)) {
|
|
continue;
|
|
}
|
|
|
|
$response = $this->actingAs($this->actorFor($uri), 'api')->getJson($this->materializePath($uri));
|
|
|
|
$this->assertControlled($response, 'GET', $uri);
|
|
$this->assertNoServerError($response, 'collection envelope '.$uri);
|
|
|
|
if ($response->getStatusCode() !== 200 || ! $this->isJsonString($response->getContent())) {
|
|
continue;
|
|
}
|
|
|
|
$payload = $response->json();
|
|
$this->assertTrue(
|
|
is_array($payload) && (array_is_list($payload) || $payload !== []),
|
|
$uri.' should keep a predictable collection/read envelope.'
|
|
);
|
|
}
|
|
}
|
|
|
|
public function test_successful_detail_endpoints_keep_identifier_or_data_keys(): void
|
|
{
|
|
$routes = array_slice(array_filter($this->apiRoutes(), fn ($route) => $this->primaryMethod($route) === 'GET' && str_contains($route->uri(), '{')), 0, 100);
|
|
|
|
foreach ($routes as $route) {
|
|
$uri = $route->uri();
|
|
if ($this->isOpenApiDocumentRoute($uri)) {
|
|
continue;
|
|
}
|
|
|
|
$response = $this->actingAs($this->actorFor($uri), 'api')->getJson($this->materializePath($uri));
|
|
|
|
$this->assertControlled($response, 'GET', $uri);
|
|
$this->assertNoServerError($response, 'detail envelope '.$uri);
|
|
|
|
if ($response->getStatusCode() !== 200 || ! $this->isJsonString($response->getContent())) {
|
|
continue;
|
|
}
|
|
|
|
$payload = $response->json();
|
|
$this->assertTrue(
|
|
is_array($payload) && (array_is_list($payload) || $payload !== []),
|
|
$uri.' should keep an identifier, data wrapper, or explicit status/message contract.'
|
|
);
|
|
}
|
|
}
|
|
|
|
private function isOpenApiDocumentRoute(string $uri): bool
|
|
{
|
|
return str_contains($uri, 'swagger.json')
|
|
|| str_contains($uri, 'openapi')
|
|
|| str_starts_with($uri, 'api/docs');
|
|
}
|
|
}
|