@@ -39,6 +39,7 @@ protected function defineEnvironment($app): void
3939 tap ($ app ['config ' ], function (Repository $ config ): void {
4040 $ config ->set ('api-platform.formats ' , ['jsonapi ' => ['application/vnd.api+json ' ]]);
4141 $ config ->set ('api-platform.docs_formats ' , ['jsonapi ' => ['application/vnd.api+json ' ]]);
42+ $ config ->set ('api-platform.resources ' , [app_path ('Models ' ), app_path ('ApiResource ' )]);
4243 $ config ->set ('app.debug ' , true );
4344 });
4445 }
@@ -48,13 +49,15 @@ public function testGetEntrypoint(): void
4849 $ response = $ this ->get ('/api/ ' , ['accept ' => ['application/vnd.api+json ' ]]);
4950 $ response ->assertStatus (200 );
5051 $ response ->assertHeader ('content-type ' , 'application/vnd.api+json; charset=utf-8 ' );
51- $ this ->assertJsonContains ([
52- 'links ' => [
53- 'self ' => 'http://localhost/api ' ,
54- 'book ' => 'http://localhost/api/books ' ,
52+ $ this ->assertJsonContains (
53+ [
54+ 'links ' => [
55+ 'self ' => 'http://localhost/api ' ,
56+ 'book ' => 'http://localhost/api/books ' ,
57+ ],
5558 ],
56- ],
57- $ response -> json () );
59+ $ response -> json ()
60+ );
5861 }
5962
6063 public function testGetCollection (): void
@@ -209,4 +212,56 @@ public function testRelationWithGroups(): void
209212 $ this ->assertArrayHasKey ('relation ' , $ content ['data ' ]['relationships ' ]);
210213 $ this ->assertArrayHasKey ('data ' , $ content ['data ' ]['relationships ' ]['relation ' ]);
211214 }
215+
216+ public function testValidateJsonApi (): void
217+ {
218+ $ response = $ this ->postJson (
219+ '/api/issue6745/rule_validations ' ,
220+ [
221+ 'data ' => [
222+ 'type ' => 'string ' ,
223+ 'attributes ' => [
224+ 'prop ' => 1 ,
225+ ],
226+ ],
227+ ],
228+ [
229+ 'accept ' => 'application/vnd.api+json ' ,
230+ 'content_type ' => 'application/vnd.api+json ' ,
231+ ]
232+ );
233+
234+ $ response ->assertStatus (422 );
235+ $ response ->assertHeader ('content-type ' , 'application/vnd.api+json; charset=utf-8 ' );
236+ $ json = $ response ->json ();
237+ $ this ->assertJsonContains ([
238+ 'errors ' => [
239+ [
240+ 'description ' => 'The prop field is required. ' ,
241+ 'title ' => 'Validation Error ' ,
242+ 'detail ' => 'The prop field is required. ' ,
243+ 'status ' => 422 ,
244+ 'code ' => 'ac88443768512709 ' ,
245+ ],
246+ ],
247+ ], $ json );
248+
249+ $ this ->assertArrayHasKey ('id ' , $ json ['errors ' ][0 ]);
250+ $ this ->assertArrayHasKey ('links ' , $ json ['errors ' ][0 ]);
251+ $ this ->assertArrayHasKey ('type ' , $ json ['errors ' ][0 ]['links ' ]);
252+ }
253+
254+ public function testNotFound (): void
255+ {
256+ $ response = $ this ->get ('/api/books/notfound ' , headers: ['accept ' => 'application/vnd.api+json ' ]);
257+ $ response ->assertStatus (404 );
258+ $ response ->assertHeader ('content-type ' , 'application/vnd.api+json; charset=utf-8 ' );
259+
260+ $ this ->assertJsonContains ([
261+ 'links ' => ['type ' => '/errors/404 ' ],
262+ 'title ' => 'An error occurred ' ,
263+ 'status ' => 404 ,
264+ 'detail ' => 'Not Found ' ,
265+ ], $ response ->json ()['errors ' ][0 ]);
266+ }
212267}
0 commit comments