getJson('/api/v1/employees'); // THEN $response->assertStatus(200); $etag = $response->headers->get('ETag'); expect($etag)->toBeString()->and($etag)->not->toBeEmpty(); // WHEN: Sending conditional GET with matching ETag $conditionalResponse = $this->withHeaders([ 'If-None-Match' => (string) $etag, ])->getJson('/api/v1/employees'); // THEN: Returns 304 Not Modified $conditionalResponse->assertStatus(304); expect($conditionalResponse->getContent())->toBeEmpty(); }); it('returns 406 Not Acceptable when Accept header explicitly excludes JSON', function (): void { // GIVEN /** @var \Tests\TestCase $this */ $response = $this->withHeaders([ 'Accept' => 'text/html', ])->get('/api/v1/employees'); // THEN $response->assertStatus(406) ->assertHeader('Content-Type', 'application/problem+json'); /** @var array $data */ $data = json_decode((string) $response->getContent(), true); expect($data['status'])->toBe(406) ->and($data['title'])->toBe('Not Acceptable'); }); it('allows GET /api/v1/openapi route to return YAML spec without forcing JSON or returning 406', function (): void { // GIVEN /** @var \Tests\TestCase $this */ $response = $this->withHeaders([ 'Accept' => 'application/yaml', ])->get('/api/v1/openapi'); // THEN $response->assertStatus(200) ->assertHeader('Content-Type', 'application/yaml'); $etag = $response->headers->get('ETag'); expect($etag)->toBeString()->and($etag)->not->toBeEmpty(); }); });