Testing
Add InteractsWithRevisions to your base test case:
use Ark4ne\ApiRevisions\Testing\InteractsWithRevisions;
abstract class TestCase extends BaseTestCase
{
use InteractsWithRevisions;
}
The schema assertions need opis/json-schema:
composer require --dev opis/json-schema
Send a request in a revision
withRevision() makes the next requests carry the revision, the way the first built-in resolver of your chain reads
it: the header, the path parameter (through URL::defaults(), for route()), or the query parameter.
$this->withRevision(ApiRevision::Winter25)
->getJson('/orders/1')
->assertOk()
->assertJsonPath('data.state', 'paid');
Custom resolvers are skipped; a chain with no built-in resolver throws a LogicException.
Validate a response against its revision
assertMatchesRevisionSchema() validates the body against the schema of the revision named by the Api-Revision
response header (or the revision given as second argument). Objects are closed: an undeclared field fails. The data
of a wrapped body is validated, and a list item by item.
$this->withRevision(ApiRevision::Winter25)
->getJson('/orders/1')
->assertOk()
->assertMatchesRevisionSchema(OrderResource::class);
Render a fixture at every revision
assertRendersAtEveryRevision() renders a head subject at every revision (or the ones given) and validates each
rendering against the schema of that revision: a contract test for one resource.
$this->assertRendersAtEveryRevision(
OrderResource::class,
Order::factory()->make(),
);
Run it with each meaningful variant of the subject, for instance with and without an optional relation loaded.
Run the check
public function test_the_revisions_are_consistent(): void
{
$this->assertRevisionsAreConsistent();
}
It fails with every error revision:check would report.