---
url: https://elasticbridge.dev/docs/v2/testing.md
---
# Testing

Use the provided fake connection to test without a live search cluster.

## Faking the Connection

Any bridge can call `::fake($response, $status = 200)` to bind a fake connection that returns your payload. In v2 the fake is driver-agnostic — the same call works whether the configured driver is Elasticsearch or OpenSearch.

```php
use App\Bridges\HotelRoom;

HotelRoom::fake([
    'hits' => [
        'total' => ['value' => 0, 'relation' => 'eq'],
        'hits' => [],
    ],
]);

$query = HotelRoom::asBoolean()->matchAll()->toQuery();
```

## Example PHPUnit Test

```php
public function test_builds_term_filter(): void
{
    HotelRoom::fake([
        'hits' => [
            'total' => ['value' => 0, 'relation' => 'eq'],
            'hits' => [],
        ],
    ]);

    $query = HotelRoom::asBoolean()
        ->filterByTerm('code', 'usd')
        ->toQuery();

    $this->assertSame([
        'query' => [
            'bool' => [
                'filter' => [
                    ['term' => ['code' => 'usd']],
                ],
            ],
        ],
    ], $query);
}
```
