tests/Encoder/EncoderTest.php
/**
     * Test encode with 'self' and 'related' URLs in main document and relationships.
     */
Test encode with 'self' and 'related' URLs in main document and relationships.
Test encode with ' self ' and ' related ' URLs in main document and relationships .
public function testEncodeLinksInDocumentAndRelationships(): void
    {
        $actual = Encoder::instance(
            [
                Author::class  => AuthorSchema::class,
                Comment::class => CommentSchema::class,
                Post::class    => PostSchema::class,
            ]
        )->withUrlPrefix('http://example.com')->encodeData($this->getStandardPost());
        $expected = <<<EOL
        {
            "data" : {
                "type" : "posts",
                "id"   : "1",
                "attributes" : {
                    "title" : "JSON API paints my bikeshed!",
                    "body"  : "Outside every fat man there was an even fatter man trying to close in"
                },
                "relationships" : {
                    "author" : {
                        "links" : {
                            "self"    : "http://example.com/posts/1/relationships/author",
                            "related" : "http://example.com/posts/1/author"
                        },
                        "data" : { "type" : "people", "id" : "9" }
                    },
                    "comments" : {
                        "links" : {
                            "self"    : "http://example.com/posts/1/relationships/comments",
                            "related" : "http://example.com/posts/1/comments"
                        },
                        "data":[
                            { "type" : "comments", "id" : "5" },
                            { "type" : "comments", "id" : "12" }
                        ]
                    }
                },
                "links" : {
                    "self" : "http://example.com/posts/1"
                }
            }
        }
EOL;
        self::assertJsonStringEqualsJsonString($expected, $actual);
    }
public function testEncodeLinksInDocumentAndRelationships ( ) : void { $ actual = Encoder :: instance ( [ Author :: class => AuthorSchema :: class , Comment :: class => CommentSchema :: class , Post :: class => PostSchema :: class , ] ) -> withUrlPrefix ( 'http://example.com' ) -> encodeData ( $ this -> getStandardPost ( ) ) ; $ expected = <<< EOL         {             "data" : {                 "type" : "posts",                 "id"   : "1",                 "attributes" : {                     "title" : "JSON API paints my bikeshed!",                     "body"  : "Outside every fat man there was an even fatter man trying to close in"                 },                 "relationships" : {                     "author" : {                         "links" : {                             "self"    : "http://example.com/posts/1/relationships/author",                             "related" : "http://example.com/posts/1/author"                         },                         "data" : { "type" : "people", "id" : "9" }                     },                     "comments" : {                         "links" : {                             "self"    : "http://example.com/posts/1/relationships/comments",                             "related" : "http://example.com/posts/1/comments"                         },                         "data":[                             { "type" : "comments", "id" : "5" },                             { "type" : "comments", "id" : "12" }                         ]                     }                 },                 "links" : {                     "self" : "http://example.com/posts/1"                 }             }         } 
EOL ; self :: assertJsonStringEqualsJsonString ( $ expected , $ actual ) ; }
Test encode with 'self' and 'related' URLs in main document and relationships.
Test encode with ' self ' and ' related ' URLs in main document and relationships .