tests/Encoder/EncodeSimpleObjectsTest.php
/**
     * Test encode resource with an array of identifiers in a relationship.
     *
     * @see https://github.com/neomerx/json-api/pull/235
     */
Test encode resource with an array of identifiers in a relationship.
Test encode resource with an array of identifiers in a relationship .
public function testEncodingIdentifierArrays(): void
    {
        $commentId1 = new CommentIdentity('1');
        $commentId2 = new CommentIdentity('2');
        $author     = Author::instance(9, 'Dan', 'Gebhardt', [$commentId1, $commentId2]);
        $actual = Encoder::instance(
            [
                Author::class  => AuthorSchema::class,
                Comment::class => CommentSchema::class,
            ]
        )->withUrlPrefix('http://example.com')->withIncludedPaths([Author::LINK_COMMENTS])->encodeData($author);
        $expected = <<<EOL
        {
            "data": {
                "type" : "people",
                "id"   : "9",
                "attributes" : {
                    "first_name" : "Dan",
                    "last_name"  : "Gebhardt"
                },
                "relationships" : {
                    "comments" : {
                        "data": [
                            { "type" : "comments", "id" : "1" },
                            { "type" : "comments", "id" : "2" }
                        ],
                        "links" : {
                            "self"    : "http://example.com/people/9/relationships/comments",
                            "related" : "http://example.com/people/9/comments"
                        }
                    }
                },
                "links" : {
                    "self" : "http://example.com/people/9"
                }
            }
        }
EOL;
        self::assertJsonStringEqualsJsonString($expected, $actual);
    }
public function testEncodingIdentifierArrays ( ) : void { $ commentId1 = new CommentIdentity ( '1' ) ; $ commentId2 = new CommentIdentity ( '2' ) ; $ author = Author :: instance ( 9 , 'Dan' , 'Gebhardt' , [ $ commentId1 , $ commentId2 ] ) ; $ actual = Encoder :: instance ( [ Author :: class => AuthorSchema :: class , Comment :: class => CommentSchema :: class , ] ) -> withUrlPrefix ( 'http://example.com' ) -> withIncludedPaths ( [ Author :: LINK_COMMENTS ] ) -> encodeData ( $ author ) ; $ expected = <<< EOL         {             "data": {                 "type" : "people",                 "id"   : "9",                 "attributes" : {                     "first_name" : "Dan",                     "last_name"  : "Gebhardt"                 },                 "relationships" : {                     "comments" : {                         "data": [                             { "type" : "comments", "id" : "1" },                             { "type" : "comments", "id" : "2" }                         ],                         "links" : {                             "self"    : "http://example.com/people/9/relationships/comments",                             "related" : "http://example.com/people/9/comments"                         }                     }                 },                 "links" : {                     "self" : "http://example.com/people/9"                 }             }         } 
EOL ; self :: assertJsonStringEqualsJsonString ( $ expected , $ actual ) ; }
Test encode resource with an array of identifiers in a relationship.
Test encode resource with an array of identifiers in a relationship .
// The issue was that comment with id 1 was also added in `included` section