File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ class JsonApiParser extends JsonParser
3434 public function parse ($ rawBody , $ contentType )
3535 {
3636 $ array = parent ::parse ($ rawBody , $ contentType );
37- if (!ArrayHelper::keyExists ('data ' , $ array )) {
37+ if (!empty ( $ array ) && ! ArrayHelper::keyExists ('data ' , $ array )) {
3838 if ($ this ->throwException ) {
3939 throw new BadRequestHttpException ('The request MUST include a single resource object as primary data. ' );
4040 }
Original file line number Diff line number Diff line change 88
99use tuyakhov \jsonapi \JsonApiParser ;
1010use yii \helpers \Json ;
11+ use yii \web \BadRequestHttpException ;
1112
1213class JsonApiParserTest extends TestCase
1314{
15+ public function testEmptyBody ()
16+ {
17+ $ parser = new JsonApiParser ();
18+ $ body = '' ;
19+ $ this ->assertEquals ([], $ parser ->parse ($ body , '' ));
20+ }
21+
22+ public function testMissingData ()
23+ {
24+ $ parser = new JsonApiParser ();
25+ $ this ->expectException (BadRequestHttpException::class);
26+ $ body = Json::encode (['incorrect-member ' ]);
27+ $ parser ->parse ($ body , '' );
28+ }
29+
1430 public function testSingleResource ()
1531 {
1632 $ parser = new JsonApiParser ();
You can’t perform that action at this time.
0 commit comments