tests/Encoder/EncodeSimpleObjectsTest.php
/**
     * Test encode meta and top-level links for simple object.
     */
Test encode meta and top-level links for simple object.
Test encode meta and top - level links for simple object .
public function testEncodeMetaAndtopLinksForSimpleObject(): void
    {
        $author  = Author::instance(9, 'Dan', 'Gebhardt');
        $links   = [Link::SELF => new Link(true, '/people/9', false)];
        $profile = [
            new LinkWithAliases(false, 'http://example.com/profiles/flexible-pagination', [], false),
            new LinkWithAliases(false, 'http://example.com/profiles/resource-versioning', ['version' => 'v'], false),
        ];
        $meta    = [
            "copyright" => "Copyright 2015 Example Corp.",
            "authors"   => [
                "Yehuda Katz",
                "Steve Klabnik",
                "Dan Gebhardt",
            ],
        ];
        $actual = Encoder::instance(
            [
                Author::class => function ($factory) {
                    $schema = new AuthorSchema($factory);
                    $schema->removeRelationship(Author::LINK_COMMENTS);
                    return $schema;
                },
            ]
        )
            ->withUrlPrefix('http://example.com')
            ->withLinks([])
            ->withLinks($links)
            ->withProfile($profile)
            ->withMeta($meta)
            ->encodeData($author);
        $expected = <<<EOL
        {
            "meta" : {
                "copyright" : "Copyright 2015 Example Corp.",
                "authors" : [
                    "Yehuda Katz",
                    "Steve Klabnik",
                    "Dan Gebhardt"
                ]
            },
            "links" : {
                "self" : "http://example.com/people/9",
                "profile": [
                    "http://example.com/profiles/flexible-pagination",
                    {
                        "href"    : "http://example.com/profiles/resource-versioning",
                        "aliases" : {
                            "version": "v"
                        }
                    }
                ]
            },
            "data" : {
                "type"       : "people",
                "id"         : "9",
                "attributes" : {
                    "first_name" : "Dan",
                    "last_name"  : "Gebhardt"
                },
                "links" : {
                    "self" : "http://example.com/people/9"
                }
            }
        }
EOL;
        self::assertJsonStringEqualsJsonString($expected, $actual);
    }
public function testEncodeMetaAndtopLinksForSimpleObject ( ) : void { $ author = Author :: instance ( 9 , 'Dan' , 'Gebhardt' ) ; $ links = [ Link :: SELF => new Link ( true , '/people/9' , false ) ] ; $ profile = [ new LinkWithAliases ( false , 'http://example.com/profiles/flexible-pagination' , [ ] , false ) , new LinkWithAliases ( false , 'http://example.com/profiles/resource-versioning' , [ 'version' => 'v' ] , false ) , ] ; $ meta = [ " copyright " => " Copyright 2015 Example Corp. " , " authors " => [ " Yehuda Katz " , " Steve Klabnik " , " Dan Gebhardt " , ] , ] ; $ actual = Encoder :: instance ( [ Author :: class => function ( $ factory ) { $ schema = new AuthorSchema ( $ factory ) ; $ schema -> removeRelationship ( Author :: LINK_COMMENTS ) ; return $ schema ; } , ] ) -> withUrlPrefix ( 'http://example.com' ) -> withLinks ( [ ] ) -> withLinks ( $ links ) -> withProfile ( $ profile ) -> withMeta ( $ meta ) -> encodeData ( $ author ) ; $ expected = <<< EOL         {             "meta" : {                 "copyright" : "Copyright 2015 Example Corp.",                 "authors" : [                     "Yehuda Katz",                     "Steve Klabnik",                     "Dan Gebhardt"                 ]             },             "links" : {                 "self" : "http://example.com/people/9",                 "profile": [                     "http://example.com/profiles/flexible-pagination",                     {                         "href"    : "http://example.com/profiles/resource-versioning",                         "aliases" : {                             "version": "v"                         }                     }                 ]             },             "data" : {                 "type"       : "people",                 "id"         : "9",                 "attributes" : {                     "first_name" : "Dan",                     "last_name"  : "Gebhardt"                 },                 "links" : {                     "self" : "http://example.com/people/9"                 }             }         } 
EOL ; self :: assertJsonStringEqualsJsonString ( $ expected , $ actual ) ; }
Test encode meta and top-level links for simple object.
Test encode meta and top - level links for simple object .