Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,29 @@ Add the coverage extension to your `phpunit.xml`:

#### With Laravel (recommended)

Publish the config file:

```bash
php artisan vendor:publish --tag=openapi-contract-testing
```

This creates `config/openapi-contract-testing.php`:

```php
return [
'default_spec' => '', // e.g., 'front'
];
```

Set `default_spec` to your spec name, then use the trait — no per-class override needed:

```php
use Studio\OpenApiContractTesting\Laravel\ValidatesOpenApiSchema;

class GetPetsTest extends TestCase
{
use ValidatesOpenApiSchema;

protected function openApiSpec(): string
{
return 'front';
}

public function test_list_pets(): void
{
$response = $this->get('/api/v1/pets');
Expand All @@ -89,6 +100,22 @@ class GetPetsTest extends TestCase
}
```

To use a different spec for a specific test class, override `openApiSpec()`:

```php
class AdminGetUsersTest extends TestCase
{
use ValidatesOpenApiSchema;

protected function openApiSpec(): string
{
return 'admin';
}

// ...
}
```

#### Framework-agnostic

```php
Expand Down