Expand description
Test helpers, as the PHP package’s InteractsWithApi, ApiTestResponse and
TransformsVersionChanges: request headers for versions, keys and idempotency, assertions
for JSON:API documents, errors, replays, deprecation and shapes, and helpers that run one
version change on its own.
use fusion_stack::testing::{ApiRequest, ApiResponse};
use laravel::testing::prelude::*;
#[laravel::test(app = create)]
async fn old_clients_see_the_old_name(app: Application) {
app.get("/v1/customers/1")
.api_version("2026-06-01")
.await
.assert_json_api_resource(Some("customers"), Some("1"))
.assert_deprecated(Some("2027-06-01"))
.assert_shape(json!({ "data": { "type": "string", "id": "string",
"attributes": { "name": "string" } } }));
}Traits§
- ApiRequest
- Fusion Stack’s request headers on a test request.
- ApiResponse
- Fusion Stack’s assertions on a test response. Each returns the response, so they chain.
- Expected
Error - The error an
ApiResponse::assert_api_errorexpects: a code such as"not_found", which checks no status, or anErrorCode, which also checks the code’s own status.
Functions§
- assert_
round_ trip - Downgrading
documentand upgrading the result givesdocumentback, so old clients can send what they receive. Not for changes that drop data, such as a removed attribute. Returns the downgraded document, for further assertions. - downgrade_
response - A latest-shape response document, migrated back to the shape before the change.
- shape
- A value’s shape: its keys, with each value replaced by its JSON type (
string,integer,number,booleanornull) and each list by the shape of its first item. - upgrade_
request - An older client’s request body, migrated to the shape after the change.