11
11
12
12
namespace Tobyz \Tests \JsonApiServer \specification ;
13
13
14
+ use Tobyz \JsonApiServer \Context ;
15
+ use Tobyz \JsonApiServer \Exception \ResourceNotFoundException ;
14
16
use Tobyz \JsonApiServer \JsonApi ;
17
+ use Tobyz \JsonApiServer \Schema \Type ;
15
18
use Tobyz \Tests \JsonApiServer \AbstractTestCase ;
16
19
use Tobyz \Tests \JsonApiServer \MockAdapter ;
17
20
18
21
/**
19
- * @see https://jsonapi.org/format/1.0 /#crud-deleting
22
+ * @see https://jsonapi.org/format/1.1 /#crud-deleting
20
23
*/
21
24
class DeletingResourcesTest extends AbstractTestCase
22
25
{
@@ -25,25 +28,48 @@ class DeletingResourcesTest extends AbstractTestCase
25
28
*/
26
29
private $ api ;
27
30
28
- /**
29
- * @var MockAdapter
30
- */
31
- private $ adapter ;
32
-
33
31
public function setUp (): void
34
32
{
35
33
$ this ->api = new JsonApi ('http://example.com ' );
36
34
37
- $ this ->adapter = new MockAdapter ();
35
+ $ this ->api ->resourceType ('users ' , new MockAdapter (), function (Type $ type ) {
36
+ $ type ->deletable ();
37
+ });
38
38
}
39
39
40
40
public function test_no_content_response_if_resource_successfully_deleted ()
41
41
{
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 ());
43
65
}
44
66
45
67
public function test_not_found_error_if_resource_does_not_exist ()
46
68
{
47
- $ this ->markTestIncomplete ();
69
+ $ this ->expectException (ResourceNotFoundException::class);
70
+
71
+ $ this ->api ->handle (
72
+ $ this ->buildRequest ('DELETE ' , '/users/404 ' )
73
+ );
48
74
}
49
75
}
0 commit comments