File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,22 +106,51 @@ class GetPetsTest extends TestCase
106106}
107107```
108108
109- To use a different spec for a specific test class, override ` openApiSpec() ` :
109+ To use a different spec for a specific test class, add the ` #[OpenApiSpec] ` attribute :
110110
111111``` php
112+ use Studio\OpenApiContractTesting\Laravel\OpenApiSpec;
113+ use Studio\OpenApiContractTesting\Laravel\ValidatesOpenApiSchema;
114+
115+ #[OpenApiSpec('admin')]
112116class AdminGetUsersTest extends TestCase
113117{
114118 use ValidatesOpenApiSchema;
115119
116- protected function openApiSpec(): string
120+ // All tests in this class use the 'admin' spec
121+ }
122+ ```
123+
124+ You can also specify the spec per test method. Method-level attributes take priority over class-level:
125+
126+ ``` php
127+ #[OpenApiSpec('front')]
128+ class MixedApiTest extends TestCase
129+ {
130+ use ValidatesOpenApiSchema;
131+
132+ public function test_front_endpoint(): void
117133 {
118- return 'admin';
134+ // Uses 'front' from class-level attribute
119135 }
120136
121- // ...
137+ #[OpenApiSpec('admin')]
138+ public function test_admin_endpoint(): void
139+ {
140+ // Uses 'admin' from method-level attribute (overrides class)
141+ }
122142}
123143```
124144
145+ Resolution priority (highest to lowest):
146+
147+ 1 . Method-level ` #[OpenApiSpec] ` attribute
148+ 2 . Class-level ` #[OpenApiSpec] ` attribute
149+ 3 . ` openApiSpec() ` method override
150+ 4 . ` config('openapi-contract-testing.default_spec') `
151+
152+ > ** Note:** You can still override ` openApiSpec() ` as before — it remains fully backward-compatible.
153+
125154#### Framework-agnostic
126155
127156``` php
You can’t perform that action at this time.
0 commit comments