10
10
11
11
use Art4 \JsonApiClient \Helper \Parser ;
12
12
use Art4 \JsonApiClient \Tests \Fixtures \HelperTrait ;
13
+ use Art4 \JsonApiClient \V1 \Document ;
14
+ use Art4 \JsonApiClient \V1 \Error ;
15
+ use Art4 \JsonApiClient \V1 \ErrorCollection ;
16
+ use Art4 \JsonApiClient \V1 \ErrorLink ;
17
+ use Art4 \JsonApiClient \V1 \ErrorSource ;
18
+ use Art4 \JsonApiClient \V1 \Link ;
19
+ use Art4 \JsonApiClient \V1 \Meta ;
13
20
use PHPUnit \Framework \TestCase ;
14
21
15
22
class ErrorParsingTest extends TestCase
@@ -21,7 +28,7 @@ public function testParseErrors(): void
21
28
$ string = $ this ->getJsonString ('09_errors.json ' );
22
29
$ document = Parser::parseResponseString ($ string );
23
30
24
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ Document' , $ document );
31
+ $ this ->assertInstanceOf (Document::class , $ document );
25
32
$ this ->assertTrue ($ document ->has ('errors ' ));
26
33
$ this ->assertFalse ($ document ->has ('meta ' ));
27
34
$ this ->assertTrue ($ document ->has ('jsonapi ' ));
@@ -30,37 +37,37 @@ public function testParseErrors(): void
30
37
$ this ->assertFalse ($ document ->has ('data ' ));
31
38
32
39
$ errors = $ document ->get ('errors ' );
33
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ ErrorCollection' , $ errors );
40
+ $ this ->assertInstanceOf (ErrorCollection::class , $ errors );
34
41
$ this ->assertCount (3 , $ errors ->getKeys ());
35
42
36
43
$ this ->assertTrue ($ errors ->has ('0 ' ));
37
44
$ error0 = $ errors ->get ('0 ' );
38
45
39
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ Error' , $ error0 );
46
+ $ this ->assertInstanceOf (Error::class , $ error0 );
40
47
$ this ->assertCount (5 , $ error0 ->getKeys ());
41
48
$ this ->assertTrue ($ error0 ->has ('code ' ));
42
49
$ this ->assertSame ('123 ' , $ error0 ->get ('code ' ));
43
50
$ this ->assertTrue ($ error0 ->has ('source ' ));
44
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ ErrorSource' , $ error0 ->get ('source ' ));
51
+ $ this ->assertInstanceOf (ErrorSource::class , $ error0 ->get ('source ' ));
45
52
$ this ->assertTrue ($ error0 ->has ('source.pointer ' ));
46
53
$ this ->assertSame ('/data/attributes/first-name ' , $ error0 ->get ('source.pointer ' ));
47
54
$ this ->assertTrue ($ error0 ->has ('title ' ));
48
55
$ this ->assertSame ('Value is too short ' , $ error0 ->get ('title ' ));
49
56
$ this ->assertTrue ($ error0 ->has ('detail ' ));
50
57
$ this ->assertSame ('First name must contain at least three characters. ' , $ error0 ->get ('detail ' ));
51
58
$ this ->assertTrue ($ error0 ->has ('meta ' ));
52
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ Meta' , $ error0 ->get ('meta ' ));
59
+ $ this ->assertInstanceOf (Meta::class , $ error0 ->get ('meta ' ));
53
60
$ this ->assertSame ('bar ' , $ error0 ->get ('meta.foo ' ));
54
61
55
62
$ this ->assertTrue ($ errors ->has ('1 ' ));
56
63
$ error1 = $ errors ->get ('1 ' );
57
64
58
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ Error' , $ error1 );
65
+ $ this ->assertInstanceOf (Error::class , $ error1 );
59
66
$ this ->assertCount (4 , $ error1 ->getKeys ());
60
67
$ this ->assertTrue ($ error1 ->has ('code ' ));
61
68
$ this ->assertSame ('225 ' , $ error1 ->get ('code ' ));
62
69
$ this ->assertTrue ($ error1 ->has ('source ' ));
63
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ ErrorSource' , $ error1 ->get ('source ' ));
70
+ $ this ->assertInstanceOf (ErrorSource::class , $ error1 ->get ('source ' ));
64
71
$ this ->assertTrue ($ error1 ->has ('source.pointer ' ));
65
72
$ this ->assertSame ('/data/attributes/password ' , $ error1 ->get ('source.pointer ' ));
66
73
$ this ->assertTrue ($ error1 ->has ('title ' ));
@@ -71,12 +78,12 @@ public function testParseErrors(): void
71
78
$ this ->assertTrue ($ errors ->has ('2 ' ));
72
79
$ error2 = $ errors ->get ('2 ' );
73
80
74
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ Error' , $ error2 );
81
+ $ this ->assertInstanceOf (Error::class , $ error2 );
75
82
$ this ->assertCount (3 , $ error2 ->getKeys ());
76
83
$ this ->assertTrue ($ error2 ->has ('code ' ));
77
84
$ this ->assertSame ('226 ' , $ error2 ->get ('code ' ));
78
85
$ this ->assertTrue ($ error2 ->has ('source ' ));
79
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ ErrorSource' , $ error2 ->get ('source ' ));
86
+ $ this ->assertInstanceOf (ErrorSource::class , $ error2 ->get ('source ' ));
80
87
$ this ->assertTrue ($ error2 ->has ('source.pointer ' ));
81
88
$ this ->assertSame ('/data/attributes/password ' , $ error2 ->get ('source.pointer ' ));
82
89
$ this ->assertTrue ($ error2 ->has ('title ' ));
@@ -91,7 +98,7 @@ public function testParseErrorWithLinks(): void
91
98
$ string = $ this ->getJsonString ('10_error_with_links.json ' );
92
99
$ document = Parser::parseResponseString ($ string );
93
100
94
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ Document' , $ document );
101
+ $ this ->assertInstanceOf (Document::class , $ document );
95
102
$ this ->assertTrue ($ document ->has ('errors ' ));
96
103
$ this ->assertFalse ($ document ->has ('meta ' ));
97
104
$ this ->assertTrue ($ document ->has ('jsonapi ' ));
@@ -100,42 +107,42 @@ public function testParseErrorWithLinks(): void
100
107
$ this ->assertFalse ($ document ->has ('data ' ));
101
108
102
109
$ errors = $ document ->get ('errors ' );
103
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ ErrorCollection' , $ errors );
110
+ $ this ->assertInstanceOf (ErrorCollection::class , $ errors );
104
111
$ this ->assertCount (2 , $ errors ->getKeys ());
105
112
106
113
$ this ->assertTrue ($ errors ->has ('0 ' ));
107
114
$ error0 = $ errors ->get ('0 ' );
108
115
109
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ Error' , $ error0 );
116
+ $ this ->assertInstanceOf (Error::class , $ error0 );
110
117
$ this ->assertCount (4 , $ error0 ->getKeys ());
111
118
$ this ->assertTrue ($ error0 ->has ('code ' ));
112
119
$ this ->assertSame ('123 ' , $ error0 ->get ('code ' ));
113
120
$ this ->assertTrue ($ error0 ->has ('source ' ));
114
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ ErrorSource' , $ error0 ->get ('source ' ));
121
+ $ this ->assertInstanceOf (ErrorSource::class , $ error0 ->get ('source ' ));
115
122
$ this ->assertTrue ($ error0 ->has ('source.pointer ' ));
116
123
$ this ->assertSame ('/data/attributes/first-name ' , $ error0 ->get ('source.pointer ' ));
117
124
$ this ->assertTrue ($ error0 ->has ('title ' ));
118
125
$ this ->assertSame ('Value is too short ' , $ error0 ->get ('title ' ));
119
126
$ this ->assertTrue ($ error0 ->has ('links ' ));
120
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ ErrorLink' , $ error0 ->get ('links ' ));
127
+ $ this ->assertInstanceOf (ErrorLink::class , $ error0 ->get ('links ' ));
121
128
$ this ->assertTrue ($ error0 ->has ('links.about ' ));
122
129
$ this ->assertSame ('http://example.org/errors/123 ' , $ error0 ->get ('links.about ' ));
123
130
124
131
$ this ->assertTrue ($ errors ->has ('1 ' ));
125
132
$ error1 = $ errors ->get ('1 ' );
126
133
127
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ Error' , $ error1 );
134
+ $ this ->assertInstanceOf (Error::class , $ error1 );
128
135
$ this ->assertCount (2 , $ error1 ->getKeys ());
129
136
$ this ->assertTrue ($ error1 ->has ('code ' ));
130
137
$ this ->assertSame ('124 ' , $ error1 ->get ('code ' ));
131
138
$ this ->assertTrue ($ error1 ->has ('links ' ));
132
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ ErrorLink' , $ error1 ->get ('links ' ));
139
+ $ this ->assertInstanceOf (ErrorLink::class , $ error1 ->get ('links ' ));
133
140
$ this ->assertTrue ($ error1 ->has ('links.about ' ));
134
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ Link' , $ error1 ->get ('links.about ' ));
141
+ $ this ->assertInstanceOf (Link::class , $ error1 ->get ('links.about ' ));
135
142
$ this ->assertTrue ($ error1 ->has ('links.about.href ' ));
136
143
$ this ->assertSame ('http://example.org/errors/124 ' , $ error1 ->get ('links.about.href ' ));
137
144
$ this ->assertTrue ($ error1 ->has ('links.meta ' ));
138
- $ this ->assertInstanceOf (' Art4\JsonApiClient\V1\ Link' , $ error1 ->get ('links.meta ' ));
145
+ $ this ->assertInstanceOf (Link::class , $ error1 ->get ('links.meta ' ));
139
146
$ this ->assertTrue ($ error1 ->has ('links.meta.href ' ));
140
147
$ this ->assertSame ('http://example.org/meta ' , $ error1 ->get ('links.meta.href ' ));
141
148
0 commit comments