tests/Encoder/EncodeSimpleObjectsTest.php
/**
     * Test encode polymorphic array (resources of different types).
     */
Test encode polymorphic array (resources of different types).
Test encode polymorphic array ( resources of different types ) .
public function testEncodePolymorphicArray(): void
    {
        $author  = Author::instance(7, 'First', 'Last', []);
        $site    = Site::instance(9, 'Main Site', []);
        $encoder = Encoder::instance(
            [
                Author::class => AuthorSchema::class,
                Site::class   => SiteSchema::class,
            ]
        )->withUrlPrefix('http://example.com');
        $actual = $encoder->encodeData([$author, $site]);
        $expected = <<<EOL
        {
            "data" : [
                {
                    "type" : "people",
                    "id"   : "7",
                    "attributes" : {
                        "first_name" : "First",
                        "last_name"  : "Last"
                    },
                    "relationships" : {
                        "comments" : {
                            "links": {
                                "self"    : "http://example.com/people/7/relationships/comments",
                                "related" : "http://example.com/people/7/comments"
                            },
                            "data" : []
                        }
                    },
                    "links" : {
                        "self":"http://example.com/people/7"
                    }
                }, {
                    "type" : "sites",
                    "id"   : "9",
                    "attributes" : {
                        "name" : "Main Site"
                    },
                    "relationships" : {
                        "posts" : {
                            "links": {
                                "self"    : "http://example.com/sites/9/relationships/posts",
                                "related" : "http://example.com/sites/9/posts"
                            },
                            "data" : []
                        }
                    },
                    "links" : {
                        "self":"http://example.com/sites/9"
                    }
                }
            ]
        }
EOL;
        self::assertJsonStringEqualsJsonString($expected, $actual);
    }
public function testEncodePolymorphicArray ( ) : void { $ author = Author :: instance ( 7 , 'First' , 'Last' , [ ] ) ; $ site = Site :: instance ( 9 , 'Main Site' , [ ] ) ; $ encoder = Encoder :: instance ( [ Author :: class => AuthorSchema :: class , Site :: class => SiteSchema :: class , ] ) -> withUrlPrefix ( 'http://example.com' ) ; $ actual = $ encoder -> encodeData ( [ $ author , $ site ] ) ; $ expected = <<< EOL         {             "data" : [                 {                     "type" : "people",                     "id"   : "7",                     "attributes" : {                         "first_name" : "First",                         "last_name"  : "Last"                     },                     "relationships" : {                         "comments" : {                             "links": {                                 "self"    : "http://example.com/people/7/relationships/comments",                                 "related" : "http://example.com/people/7/comments"                             },                             "data" : []                         }                     },                     "links" : {                         "self":"http://example.com/people/7"                     }                 }, {                     "type" : "sites",                     "id"   : "9",                     "attributes" : {                         "name" : "Main Site"                     },                     "relationships" : {                         "posts" : {                             "links": {                                 "self"    : "http://example.com/sites/9/relationships/posts",                                 "related" : "http://example.com/sites/9/posts"                             },                             "data" : []                         }                     },                     "links" : {                         "self":"http://example.com/sites/9"                     }                 }             ]         } 
EOL ; self :: assertJsonStringEqualsJsonString ( $ expected , $ actual ) ; }
Test encode polymorphic array (resources of different types).
Test encode polymorphic array ( resources of different types ) .