woohoolabs / yang

The efficient and elegant, PSR-7 compliant JSON:API 1.1 client library for PHP
MIT License
168 stars 13 forks source link

Fix For Unexpected Behaviour When To-One Relationship Data Is NULL - Closes #7 #8

Closed ginnj-gilmore closed 6 years ago

ginnj-gilmore commented 6 years ago

Please see issue #7 for full information.

JSONAPI spec states to-one relationships with no associated resource should return {"data": null} but Yang does not properly account for this when converting Relationship to an array. This pull request fixes Yang returning an empty to-many relationship (['data' => []]) instead of an empty to-one relationship (['data' => null]).

ginnj-gilmore commented 6 years ago

@kocsismate That's strange... Travis says a specific test fails relating to the changes I made, but PHPUnit on my local doesn't through any errors. Do you want me to update the WoohooLabs\Yang\Tests\JsonApi\Schema\ResourceObjectTest::toArray() and WoohooLabs\Yang\Tests\JsonApi\Schema\RelationshipTest::toArray() tests?

kocsismate commented 6 years ago

I'll take care of the tests, thank you :) And I'll get back to you when I release the new versions with your fix.

kocsismate commented 6 years ago

I managed to fix the problem, but it was a bit more tricky than I thought. :) Furthermore, I have just cherry-picked our commits to the 1.2 branch. So I'd like to ask you to test it. If all is good, then I'll release 1.2.1 and 1.3.1.