# Testing

Learn how to test your integration.

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

## Unit testing \[#unit-testing]

Inject the [`Plug`](/reference/sdk/php/api/core/plug) interface into your controllers and services, 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->index()->getContent());
    }
}
```

## Integration testing \[#integration-testing]

To test a request end-to-end, replace the [`Plug`](/reference/sdk/php/api/core/plug) service in the test container with a mock so you control the responses.

In a [`WebTestCase`](https://symfony.com/doc/current/testing.html#application-tests), swap the service before issuing the request:

```php
<?php

use Croct\Plug\Plug;
use Croct\Plug\FetchResponse;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

final class HomeControllerTest extends WebTestCase
{
    public function testRendersHero(): void
    {
        $client = static::createClient();

        $croct = $this->createMock(Plug::class);
        $croct->method('fetchContent')
            ->willReturn(new FetchResponse(['title' => 'Welcome']));

        static::getContainer()->set(Plug::class, $croct);

        $client->request('GET', '/');

        self::assertSelectorTextContains('h1', 'Welcome');
    }
}
```

To exercise the real SDK against a mock server instead, point the [`base_endpoint_url`](/reference/sdk/symfony/api/configuration#base_endpoint_url-prop) at it in the test environment:

**config/packages/test/croct.yaml**

```yaml
croct:
    base_endpoint_url: 'http://localhost:8080'
```

Both approaches keep your tests deterministic and isolated from the network.

## Explore

- [Plug reference](/reference/sdk/php/api/core/plug): Explore the methods you can mock in your tests.
- [Configuration](/reference/sdk/symfony/api/configuration): Explore the options you can override in your tests.
