# Unit testing

Learn how to unit test code that uses the SDK.

When unit testing code that uses the SDK, you do not want to make real API calls. Because [`Plug`](../api/core/croct/plug) is an interface, you can replace it with a test double that returns the values your test expects.

## Mocking the SDK

Inject the [`Plug`](../api/core/croct/plug) interface into your code instead of the concrete `Croct` class, then provide a mock in your tests.

This example mocks a content fetch with PHPUnit:

```php
<?php
use Croct\Plug\Plug;
use Croct\Plug\FetchResponse;
use PHPUnit\Framework\TestCase;

final class HomeControllerTest extends TestCase
{
    public function testRendersHeadline(): void
    {
        $croct = $this->createMock(Plug::class);
        $croct->method('fetchContent')
            ->willReturn(new FetchResponse(['title' => 'Welcome']));

        $controller = new HomeController($croct);

        $this->assertStringContainsString('Welcome', $controller->render());
    }
}
```

Mocking the interface keeps your unit tests fast and deterministic, with no network access.

## Explore

- [Integration testing](integration-testing): Learn how to test the SDK end-to-end against a mock server.
- [Plug reference](../api/core/croct/plug): Explore the methods you can mock in your tests.
