tests/Encoder/EncoderTest.php
/**
     * Test encode resource object links as references.
     */
Test encode resource object links as references.
Test encode resource object links as references .
public function testEncodeEmptyLinks(): void
    {
        $actual = Encoder::instance(
            [
                Author::class  => AuthorSchema::class,
                Comment::class => CommentSchema::class,
                Post::class    => function ($factory) {
                    $schema = new PostSchema($factory);
                    $schema->addToRelationship(Post::LINK_AUTHOR, PostSchema::RELATIONSHIP_DATA, null);
                    $schema->addToRelationship(Post::LINK_COMMENTS, PostSchema::RELATIONSHIP_DATA, []);
                    $schema->hideDefaultLinksInRelationship(Post::LINK_AUTHOR);
                    $schema->hideDefaultLinksInRelationship(Post::LINK_COMMENTS);
                    return $schema;
                },
            ]
        )->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"   : {"data" : null},
                    "comments" : {"data" : []}
                },
                "links" : {
                    "self"     : "http://example.com/posts/1"
                }
            }
        }
EOL;
        self::assertJsonStringEqualsJsonString($expected, $actual);
    }
public function testEncodeEmptyLinks ( ) : void { $ actual = Encoder :: instance ( [ Author :: class => AuthorSchema :: class , Comment :: class => CommentSchema :: class , Post :: class => function ( $ factory ) { $ schema = new PostSchema ( $ factory ) ; $ schema -> addToRelationship ( Post :: LINK_AUTHOR , PostSchema :: RELATIONSHIP_DATA , null ) ; $ schema -> addToRelationship ( Post :: LINK_COMMENTS , PostSchema :: RELATIONSHIP_DATA , [ ] ) ; $ schema -> hideDefaultLinksInRelationship ( Post :: LINK_AUTHOR ) ; $ schema -> hideDefaultLinksInRelationship ( Post :: LINK_COMMENTS ) ; return $ schema ; } , ] ) -> 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"   : {"data" : null},                     "comments" : {"data" : []}                 },                 "links" : {                     "self"     : "http://example.com/posts/1"                 }             }         } 
EOL ; self :: assertJsonStringEqualsJsonString ( $ expected , $ actual ) ; }
Test encode resource object links as references.
Test encode resource object links as references .
// hide links