File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed
tests/Unit/Http/Service/EventSubscriber Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 11
11
12
12
final class ResourceResponse
13
13
{
14
- /** @var ResourceInterface */
14
+ /** @var null| ResourceInterface */
15
15
private $ primaryResource ;
16
16
17
17
/** @var null|ResourceCollectionInterface */
@@ -24,7 +24,7 @@ final class ResourceResponse
24
24
private $ links ;
25
25
26
26
public function __construct (
27
- ResourceInterface $ primaryResource ,
27
+ ? ResourceInterface $ primaryResource ,
28
28
?ResourceCollectionInterface $ includedResources = null ,
29
29
?MetaInterface $ meta = null ,
30
30
?LinkCollectionInterface $ links = null
@@ -35,7 +35,7 @@ public function __construct(
35
35
$ this ->links = $ links ;
36
36
}
37
37
38
- public function getPrimaryResource (): ResourceInterface
38
+ public function getPrimaryResource (): ? ResourceInterface
39
39
{
40
40
return $ this ->primaryResource ;
41
41
}
Original file line number Diff line number Diff line change @@ -101,7 +101,12 @@ public function resource(
101
101
array $ meta = null ,
102
102
array $ links = null
103
103
): ResourceResponse {
104
- $ resource = $ this ->encodeData ($ primaryData );
104
+ /**
105
+ * resource response can be single resource or null.
106
+ *
107
+ * @see https://jsonapi.org/format/#fetching-resources-responses-200
108
+ */
109
+ $ resource = null === $ primaryData ? null : $ this ->encodeData ($ primaryData );
105
110
106
111
return new ResourceResponse (
107
112
$ resource ,
Original file line number Diff line number Diff line change @@ -86,6 +86,11 @@ public function controllerResultProvider(): \Generator
86
86
true ,
87
87
];
88
88
89
+ yield 'Null ResourceResponse returned by controller ' => [
90
+ new ResourceResponse (null ),
91
+ true ,
92
+ ];
93
+
89
94
yield 'ResourceValidationErrorsResponse returned by controller ' => [
90
95
new ResourceValidationErrorsResponse (new ErrorCollection ([])),
91
96
true ,
You can’t perform that action at this time.
0 commit comments