Integration testing

Learn how to test the SDK end-to-end.

To test the SDK end-to-end without hitting the real API, swap the HTTP client for a mock so you control the responses.

Mocking the HTTP client

Because the SDK works with any PSR-18 HTTP client, you can pass a mock client through the httpClient argument of plug and queue the responses your test expects.

This example uses php-http/mock-client:

12345678910111213141516171819202122
<?phpuse Croct\Plug\Croct;use Croct\Plug\InMemoryIdentityStore;use Http\Mock\Client;use Nyholm\Psr7\Response;
$httpClient = new Client();$httpClient->addResponse(    new Response(        200,        ['Content-Type' => 'application/json'],        '{"content": {"title": "Welcome"}}',    ),);
$croct = Croct::plug(    appId: 'APPLICATION_ID',    apiKey: 'API_KEY',    storage: new InMemoryIdentityStore(),    httpClient: $httpClient,);$content = $croct->fetchContent('home-hero')->getContent();

The example keeps the session in memory with InMemoryIdentityStore instead of the cookie-backed CookieStorage, so tests never read or write cookies.

This keeps your integration tests deterministic and isolated from the network.