# 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](https://www.php-fig.org/psr/psr-18/) HTTP client, you can provide a mock client [when you create the SDK](../api/core/croct/plug) and queue the responses your test expects.

This example uses [`php-http/mock-client`](https://github.com/php-http/mock-client):

```php
<?php
use 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`](../api/storage/cookie-storage), so tests never read or write cookies.

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

## Explore

- [Unit testing](unit-testing): Learn how to mock the SDK in your unit tests.
- [plug reference](../api/core/croct/plug): Explore the options you can override in your tests.
