1111
1212namespace Tobyz \Tests \JsonApiServer \specification ;
1313
14+ use Tobyz \JsonApiServer \Context ;
15+ use Tobyz \JsonApiServer \Exception \ResourceNotFoundException ;
1416use Tobyz \JsonApiServer \JsonApi ;
17+ use Tobyz \JsonApiServer \Schema \Type ;
1518use Tobyz \Tests \JsonApiServer \AbstractTestCase ;
1619use Tobyz \Tests \JsonApiServer \MockAdapter ;
1720
1821/**
19- * @see https://jsonapi.org/format/1.0 /#crud-deleting
22+ * @see https://jsonapi.org/format/1.1 /#crud-deleting
2023 */
2124class DeletingResourcesTest extends AbstractTestCase
2225{
@@ -25,25 +28,48 @@ class DeletingResourcesTest extends AbstractTestCase
2528 */
2629 private $ api ;
2730
28- /**
29- * @var MockAdapter
30- */
31- private $ adapter ;
32-
3331 public function setUp (): void
3432 {
3533 $ this ->api = new JsonApi ('http://example.com ' );
3634
37- $ this ->adapter = new MockAdapter ();
35+ $ this ->api ->resourceType ('users ' , new MockAdapter (), function (Type $ type ) {
36+ $ type ->deletable ();
37+ });
3838 }
3939
4040 public function test_no_content_response_if_resource_successfully_deleted ()
4141 {
42- $ this ->markTestIncomplete ();
42+ $ response = $ this ->api ->handle (
43+ $ this ->buildRequest ('DELETE ' , '/users/1 ' )
44+ );
45+
46+ $ this ->assertEquals (204 , $ response ->getStatusCode ());
47+ $ this ->assertEmpty ($ response ->getBody ()->getContents ());
48+ }
49+
50+ public function test_ok_response_if_meta ()
51+ {
52+ $ this ->api ->resourceType ('users ' , new MockAdapter (), function (Type $ type ) {
53+ $ type ->deletable ();
54+ $ type ->deleting (function ($ model , Context $ context ) {
55+ $ context ->meta ('foo ' , 'bar ' );
56+ });
57+ });
58+
59+ $ response = $ this ->api ->handle (
60+ $ this ->buildRequest ('DELETE ' , '/users/1 ' )
61+ );
62+
63+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
64+ $ this ->assertJsonApiDocumentSubset (['meta ' => ['foo ' => 'bar ' ]], $ response ->getBody ());
4365 }
4466
4567 public function test_not_found_error_if_resource_does_not_exist ()
4668 {
47- $ this ->markTestIncomplete ();
69+ $ this ->expectException (ResourceNotFoundException::class);
70+
71+ $ this ->api ->handle (
72+ $ this ->buildRequest ('DELETE ' , '/users/404 ' )
73+ );
4874 }
4975}
0 commit comments