@@ -33,6 +33,13 @@ class ApiTestCaseTest extends ApiTestCase
3333{
3434 use ExpectDeprecationTrait;
3535
36+ public static function providerFormats (): iterable
37+ {
38+ // yield 'jsonapi' => ['jsonapi', 'application/vnd.api+json'];
39+ yield 'jsonhal ' => ['jsonhal ' , 'application/hal+json ' ];
40+ yield 'jsonld ' => ['jsonld ' , 'application/ld+json ' ];
41+ }
42+
3643 public function testAssertJsonContains (): void
3744 {
3845 self ::createClient ()->request ('GET ' , '/ ' );
@@ -122,13 +129,19 @@ public function testAssertMatchesJsonSchema(): void
122129 $ this ->assertMatchesJsonSchema (json_decode ($ jsonSchema , true ));
123130 }
124131
125- public function testAssertMatchesResourceCollectionJsonSchema (): void
132+ /**
133+ * @dataProvider providerFormats
134+ */
135+ public function testAssertMatchesResourceCollectionJsonSchema (string $ format , string $ mimeType ): void
126136 {
127- self ::createClient ()->request ('GET ' , '/resource_interfaces ' );
128- $ this ->assertMatchesResourceCollectionJsonSchema (ResourceInterface::class);
137+ self ::createClient ()->request ('GET ' , '/resource_interfaces ' , [ ' headers ' => [ ' Accept ' => $ mimeType ]] );
138+ $ this ->assertMatchesResourceCollectionJsonSchema (ResourceInterface::class, format: $ format );
129139 }
130140
131- public function testAssertMatchesResourceCollectionJsonSchemaKeepSerializationContext (): void
141+ /**
142+ * @dataProvider providerFormats
143+ */
144+ public function testAssertMatchesResourceCollectionJsonSchemaKeepSerializationContext (string $ format , string $ mimeType ): void
132145 {
133146 $ this ->recreateSchema ();
134147
@@ -146,20 +159,26 @@ public function testAssertMatchesResourceCollectionJsonSchemaKeepSerializationCo
146159 $ manager ->persist ($ child );
147160 $ manager ->flush ();
148161
149- self ::createClient ()->request ('GET ' , "issue-6146-parents/ {$ parent ->getId ()}" );
150- $ this ->assertMatchesResourceItemJsonSchema (Issue6146Parent::class);
162+ self ::createClient ()->request ('GET ' , "issue-6146-parents/ {$ parent ->getId ()}" , [ ' headers ' => [ ' Accept ' => $ mimeType ]] );
163+ $ this ->assertMatchesResourceItemJsonSchema (Issue6146Parent::class, format: $ format );
151164
152- self ::createClient ()->request ('GET ' , '/issue-6146-parents ' );
153- $ this ->assertMatchesResourceCollectionJsonSchema (Issue6146Parent::class);
165+ self ::createClient ()->request ('GET ' , '/issue-6146-parents ' , [ ' headers ' => [ ' Accept ' => $ mimeType ]] );
166+ $ this ->assertMatchesResourceCollectionJsonSchema (Issue6146Parent::class, format: $ format );
154167 }
155168
156- public function testAssertMatchesResourceItemJsonSchema (): void
169+ /**
170+ * @dataProvider providerFormats
171+ */
172+ public function testAssertMatchesResourceItemJsonSchema (string $ format , string $ mimeType ): void
157173 {
158- self ::createClient ()->request ('GET ' , '/resource_interfaces/some-id ' );
159- $ this ->assertMatchesResourceItemJsonSchema (ResourceInterface::class);
174+ self ::createClient ()->request ('GET ' , '/resource_interfaces/some-id ' , [ ' headers ' => [ ' Accept ' => $ mimeType ]] );
175+ $ this ->assertMatchesResourceItemJsonSchema (ResourceInterface::class, format: $ format );
160176 }
161177
162- public function testAssertMatchesResourceItemJsonSchemaWithCustomJson (): void
178+ /**
179+ * @dataProvider providerFormats
180+ */
181+ public function testAssertMatchesResourceItemJsonSchemaWithCustomJson (string $ format , string $ mimeType ): void
163182 {
164183 $ this ->recreateSchema ();
165184
@@ -169,11 +188,14 @@ public function testAssertMatchesResourceItemJsonSchemaWithCustomJson(): void
169188 $ manager ->persist ($ jsonSchemaContextDummy );
170189 $ manager ->flush ();
171190
172- self ::createClient ()->request ('GET ' , '/json_schema_context_dummies/1 ' );
173- $ this ->assertMatchesResourceItemJsonSchema (JsonSchemaContextDummy::class);
191+ self ::createClient ()->request ('GET ' , '/json_schema_context_dummies/1 ' , [ ' headers ' => [ ' Accept ' => $ mimeType ]] );
192+ $ this ->assertMatchesResourceItemJsonSchema (JsonSchemaContextDummy::class, format: $ format );
174193 }
175194
176- public function testAssertMatchesResourceItemJsonSchemaOutput (): void
195+ /**
196+ * @dataProvider providerFormats
197+ */
198+ public function testAssertMatchesResourceItemJsonSchemaOutput (string $ format , string $ mimeType ): void
177199 {
178200 $ this ->recreateSchema ();
179201
@@ -184,11 +206,14 @@ public function testAssertMatchesResourceItemJsonSchemaOutput(): void
184206 $ dummyDtoInputOutput ->num = 54 ;
185207 $ manager ->persist ($ dummyDtoInputOutput );
186208 $ manager ->flush ();
187- self ::createClient ()->request ('GET ' , '/dummy_dto_input_outputs/1 ' );
188- $ this ->assertMatchesResourceItemJsonSchema (DummyDtoInputOutput::class);
209+ self ::createClient ()->request ('GET ' , '/dummy_dto_input_outputs/1 ' , [ ' headers ' => [ ' Accept ' => $ mimeType ]] );
210+ $ this ->assertMatchesResourceItemJsonSchema (DummyDtoInputOutput::class, format: $ format );
189211 }
190212
191- public function testAssertMatchesResourceItemAndCollectionJsonSchemaOutputWithContext (): void
213+ /**
214+ * @dataProvider providerFormats
215+ */
216+ public function testAssertMatchesResourceItemAndCollectionJsonSchemaOutputWithContext (string $ format , string $ mimeType ): void
192217 {
193218 $ this ->recreateSchema ();
194219
@@ -201,11 +226,11 @@ public function testAssertMatchesResourceItemAndCollectionJsonSchemaOutputWithCo
201226 $ manager ->persist ($ user );
202227 $ manager ->flush ();
203228
204- self ::createClient ()->request ('GET ' , "/users-with-groups/ {$ user ->getId ()}" );
205- $ this ->assertMatchesResourceItemJsonSchema (User::class, null , ' jsonld ' , ['groups ' => ['api-test-case-group ' ]]);
229+ self ::createClient ()->request ('GET ' , "/users-with-groups/ {$ user ->getId ()}" , [ ' headers ' => [ ' Accept ' => $ mimeType ]] );
230+ $ this ->assertMatchesResourceItemJsonSchema (User::class, null , $ format , ['groups ' => ['api-test-case-group ' ]]);
206231
207- self ::createClient ()->request ('GET ' , '/users-with-groups ' );
208- $ this ->assertMatchesResourceCollectionJsonSchema (User::class, null , ' jsonld ' , ['groups ' => ['api-test-case-group ' ]]);
232+ self ::createClient ()->request ('GET ' , '/users-with-groups ' , [ ' headers ' => [ ' Accept ' => $ mimeType ]] );
233+ $ this ->assertMatchesResourceCollectionJsonSchema (User::class, null , $ format , ['groups ' => ['api-test-case-group ' ]]);
209234 }
210235
211236 public function testAssertMatchesResourceItemAndCollectionJsonSchemaOutputWithRangeAssertions (): void
0 commit comments