File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ and this project adheres to
37
37
- Add ` Resource::links() ` method for defining custom resource-level links
38
38
(including ` describedby ` )
39
39
- Add ` Schema\Link ` class for defining rich link objects with metadata
40
+ - Add ` JsonApiError::id(string $id) ` method for setting error IDs
40
41
- Add full support for JSON: API profiles:
41
42
- Parse profile URIs from ` Accept ` header
42
43
- ` Context::profileRequested(string $uri): bool ` - check if a profile was
Original file line number Diff line number Diff line change @@ -48,6 +48,13 @@ public function links(array $links): static
48
48
return $ this ;
49
49
}
50
50
51
+ public function id (string $ id ): static
52
+ {
53
+ $ this ->error ['id ' ] = $ id ;
54
+
55
+ return $ this ;
56
+ }
57
+
51
58
public function getJsonApiError (): array
52
59
{
53
60
$ class = (new ReflectionClass ($ this ))->getShortName ();
Original file line number Diff line number Diff line change @@ -154,4 +154,44 @@ public function test_multiple_errors_most_applicable_status()
154
154
155
155
$ this ->assertEquals (500 , $ response ->getStatusCode ());
156
156
}
157
+
158
+ public function test_error_id_can_be_set_via_fluent_method ()
159
+ {
160
+ $ response = $ this ->api ->error ((new MockErrorException ())->id ('error-12345 ' ));
161
+
162
+ $ this ->assertJsonApiDocumentSubset (
163
+ [
164
+ 'errors ' => [
165
+ [
166
+ 'id ' => 'error-12345 ' ,
167
+ 'status ' => '400 ' ,
168
+ ],
169
+ ],
170
+ ],
171
+ $ response ->getBody (),
172
+ );
173
+ }
174
+
175
+ public function test_error_id_can_be_set_via_customization ()
176
+ {
177
+ $ this ->api ->errors ([
178
+ MockErrorException::class => [
179
+ 'id ' => 'custom-error-id ' ,
180
+ ],
181
+ ]);
182
+
183
+ $ response = $ this ->api ->error (new MockErrorException ());
184
+
185
+ $ this ->assertJsonApiDocumentSubset (
186
+ [
187
+ 'errors ' => [
188
+ [
189
+ 'id ' => 'custom-error-id ' ,
190
+ 'status ' => '400 ' ,
191
+ ],
192
+ ],
193
+ ],
194
+ $ response ->getBody (),
195
+ );
196
+ }
157
197
}
You can’t perform that action at this time.
0 commit comments