Skip to main content

Module testing

Module testing 

Source
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.
ExpectedError
The error an ApiResponse::assert_api_error expects: a code such as "not_found", which checks no status, or an ErrorCode, which also checks the code’s own status.

Functions§

assert_round_trip
Downgrading document and upgrading the result gives document back, 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, boolean or null) 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.