@@ -33,6 +33,13 @@ class ApiTestCaseTest extends ApiTestCase
33
33
{
34
34
use ExpectDeprecationTrait;
35
35
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
+
36
43
public function testAssertJsonContains (): void
37
44
{
38
45
self ::createClient ()->request ('GET ' , '/ ' );
@@ -122,13 +129,19 @@ public function testAssertMatchesJsonSchema(): void
122
129
$ this ->assertMatchesJsonSchema (json_decode ($ jsonSchema , true ));
123
130
}
124
131
125
- public function testAssertMatchesResourceCollectionJsonSchema (): void
132
+ /**
133
+ * @dataProvider providerFormats
134
+ */
135
+ public function testAssertMatchesResourceCollectionJsonSchema (string $ format , string $ mimeType ): void
126
136
{
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 );
129
139
}
130
140
131
- public function testAssertMatchesResourceCollectionJsonSchemaKeepSerializationContext (): void
141
+ /**
142
+ * @dataProvider providerFormats
143
+ */
144
+ public function testAssertMatchesResourceCollectionJsonSchemaKeepSerializationContext (string $ format , string $ mimeType ): void
132
145
{
133
146
$ this ->recreateSchema ();
134
147
@@ -146,20 +159,26 @@ public function testAssertMatchesResourceCollectionJsonSchemaKeepSerializationCo
146
159
$ manager ->persist ($ child );
147
160
$ manager ->flush ();
148
161
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 );
151
164
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 );
154
167
}
155
168
156
- public function testAssertMatchesResourceItemJsonSchema (): void
169
+ /**
170
+ * @dataProvider providerFormats
171
+ */
172
+ public function testAssertMatchesResourceItemJsonSchema (string $ format , string $ mimeType ): void
157
173
{
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 );
160
176
}
161
177
162
- public function testAssertMatchesResourceItemJsonSchemaWithCustomJson (): void
178
+ /**
179
+ * @dataProvider providerFormats
180
+ */
181
+ public function testAssertMatchesResourceItemJsonSchemaWithCustomJson (string $ format , string $ mimeType ): void
163
182
{
164
183
$ this ->recreateSchema ();
165
184
@@ -169,11 +188,14 @@ public function testAssertMatchesResourceItemJsonSchemaWithCustomJson(): void
169
188
$ manager ->persist ($ jsonSchemaContextDummy );
170
189
$ manager ->flush ();
171
190
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 );
174
193
}
175
194
176
- public function testAssertMatchesResourceItemJsonSchemaOutput (): void
195
+ /**
196
+ * @dataProvider providerFormats
197
+ */
198
+ public function testAssertMatchesResourceItemJsonSchemaOutput (string $ format , string $ mimeType ): void
177
199
{
178
200
$ this ->recreateSchema ();
179
201
@@ -184,11 +206,14 @@ public function testAssertMatchesResourceItemJsonSchemaOutput(): void
184
206
$ dummyDtoInputOutput ->num = 54 ;
185
207
$ manager ->persist ($ dummyDtoInputOutput );
186
208
$ 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 );
189
211
}
190
212
191
- public function testAssertMatchesResourceItemAndCollectionJsonSchemaOutputWithContext (): void
213
+ /**
214
+ * @dataProvider providerFormats
215
+ */
216
+ public function testAssertMatchesResourceItemAndCollectionJsonSchemaOutputWithContext (string $ format , string $ mimeType ): void
192
217
{
193
218
$ this ->recreateSchema ();
194
219
@@ -201,11 +226,11 @@ public function testAssertMatchesResourceItemAndCollectionJsonSchemaOutputWithCo
201
226
$ manager ->persist ($ user );
202
227
$ manager ->flush ();
203
228
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 ' ]]);
206
231
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 ' ]]);
209
234
}
210
235
211
236
public function testAssertMatchesResourceItemAndCollectionJsonSchemaOutputWithRangeAssertions (): void
0 commit comments