tests/Extensions/Issue81/IssueTest.php
/**
     * Test encoder will encode identities.
     *
     * @see https://github.com/neomerx/json-api/issues/81
     */
Test encoder will encode identities.
Test encoder will encode identities .
public function testEnheritedEncoder(): void
    {
        $author                          = Author::instance(321, 'John', 'Dow')->setIdentifierMeta('id meta');
        $comment                         = Comment::instance(123, 'Comment body', $author);
        $author->{Author::LINK_COMMENTS} = [$comment];
        $actual = Encoder::instance(
            [
                Comment::class => CommentSchema::class,
            ]
        )->encodeData($comment);
        $expected = <<<EOL
        {
            "data" : {
                "type"       : "comments",
                "id"         : "123",
                "attributes" : {
                    "body" : "Comment body"
                },
                "relationships" : {
                    "author" : {
                        "links": {
                            "self"    : "/comments/123/relationships/author",
                            "related" : "/comments/123/author"
                        },
                        "data" : { "type" : "people", "id" : "321", "meta": "id meta" }
                    }
                },
                "links" : {
                    "self" : "/comments/123"
                }
            }
        }
EOL;
        self::assertJsonStringEqualsJsonString($expected, $actual);
    }
public function testEnheritedEncoder ( ) : void { $ author = Author :: instance ( 321 , 'John' , 'Dow' ) -> setIdentifierMeta ( 'id meta' ) ; $ comment = Comment :: instance ( 123 , 'Comment body' , $ author ) ; $ author -> { Author :: LINK_COMMENTS } = [ $ comment ] ; $ actual = Encoder :: instance ( [ Comment :: class => CommentSchema :: class , ] ) -> encodeData ( $ comment ) ; $ expected = <<< EOL         {             "data" : {                 "type"       : "comments",                 "id"         : "123",                 "attributes" : {                     "body" : "Comment body"                 },                 "relationships" : {                     "author" : {                         "links": {                             "self"    : "/comments/123/relationships/author",                             "related" : "/comments/123/author"                         },                         "data" : { "type" : "people", "id" : "321", "meta": "id meta" }                     }                 },                 "links" : {                     "self" : "/comments/123"                 }             }         } 
EOL ; self :: assertJsonStringEqualsJsonString ( $ expected , $ actual ) ; }
Test encoder will encode identities.
Test encoder will encode identities .