tests/Encoder/EncoderTest.php
/**
     * Test add meta to empty relationship.
     */
Test add meta to empty relationship.
Test add meta to empty relationship .
public function testAddMetaToEmptyRelationship(): void
    {
        $actual = Encoder::instance(
            [
                Author::class  => AuthorSchema::class,
                Comment::class => CommentSchema::class,
                Post::class    => function ($factory) {
                    $schema = new PostSchema($factory);
                    $schema->removeFromRelationship(Post::LINK_AUTHOR, PostSchema::RELATIONSHIP_DATA);
                    $schema->hideDefaultLinksInRelationship(Post::LINK_AUTHOR);
                    $schema->addToRelationship(Post::LINK_AUTHOR, PostSchema::RELATIONSHIP_META, ['author' => 'meta']);
                    $schema->removeFromRelationship(Post::LINK_COMMENTS, PostSchema::RELATIONSHIP_DATA);
                    $schema->hideDefaultLinksInRelationship(Post::LINK_COMMENTS);
                    $schema->addToRelationship(
                        Post::LINK_COMMENTS,
                        PostSchema::RELATIONSHIP_META,
                        function () {
                            return ['comments' => 'meta'];
                        }
                    );
                    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" : {
                       "meta": { "author": "meta" }
                    },
                    "comments" : {
                        "meta": { "comments": "meta" }
                    }
                },
                "links" : {
                    "self" : "http://example.com/posts/1"
                }
            }
        }
EOL;
        self::assertJsonStringEqualsJsonString($expected, $actual);
    }
public function testAddMetaToEmptyRelationship ( ) : void { $ actual = Encoder :: instance ( [ Author :: class => AuthorSchema :: class , Comment :: class => CommentSchema :: class , Post :: class => function ( $ factory ) { $ schema = new PostSchema ( $ factory ) ; $ schema -> removeFromRelationship ( Post :: LINK_AUTHOR , PostSchema :: RELATIONSHIP_DATA ) ; $ schema -> hideDefaultLinksInRelationship ( Post :: LINK_AUTHOR ) ; $ schema -> addToRelationship ( Post :: LINK_AUTHOR , PostSchema :: RELATIONSHIP_META , [ 'author' => 'meta' ] ) ; $ schema -> removeFromRelationship ( Post :: LINK_COMMENTS , PostSchema :: RELATIONSHIP_DATA ) ; $ schema -> hideDefaultLinksInRelationship ( Post :: LINK_COMMENTS ) ; $ schema -> addToRelationship ( Post :: LINK_COMMENTS , PostSchema :: RELATIONSHIP_META , function ( ) { return [ 'comments' => 'meta' ] ; } ) ; 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" : {                        "meta": { "author": "meta" }                     },                     "comments" : {                         "meta": { "comments": "meta" }                     }                 },                 "links" : {                     "self" : "http://example.com/posts/1"                 }             }         } 
EOL ; self :: assertJsonStringEqualsJsonString ( $ expected , $ actual ) ; }
Test add meta to empty relationship.
Test add meta to empty relationship .