tests/Encoder/EncodeSimpleObjectsTest.php
/**
     * Test encode array of simple objects with attributes only.
     */
Test encode array of simple objects with attributes only.
Test encode array of simple objects with attributes only .
public function testEncodeArrayOfObjectsWithAttributesOnly(): void
    {
        $author1 = Author::instance(7, 'First', 'Last');
        $author2 = Author::instance(9, 'Dan', 'Gebhardt');
        $encoder = Encoder::instance(
            [
                Author::class => function ($factory) {
                    $schema = new AuthorSchema($factory);
                    $schema->removeRelationship(Author::LINK_COMMENTS);
                    return $schema;
                },
            ]
        )->withUrlPrefix('http://example.com');
        $actual = $encoder->encodeData([$author1, $author2]);
        $expected = <<<EOL
        {
            "data" : [
                {
                    "type"       : "people",
                    "id"         : "7",
                    "attributes" : {
                        "first_name" : "First",
                        "last_name"  : "Last"
                    },
                    "links" : {
                        "self" : "http://example.com/people/7"
                    }
                },
                {
                    "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 testEncodeArrayOfObjectsWithAttributesOnly ( ) : void { $ author1 = Author :: instance ( 7 , 'First' , 'Last' ) ; $ author2 = Author :: instance ( 9 , 'Dan' , 'Gebhardt' ) ; $ encoder = Encoder :: instance ( [ Author :: class => function ( $ factory ) { $ schema = new AuthorSchema ( $ factory ) ; $ schema -> removeRelationship ( Author :: LINK_COMMENTS ) ; return $ schema ; } , ] ) -> withUrlPrefix ( 'http://example.com' ) ; $ actual = $ encoder -> encodeData ( [ $ author1 , $ author2 ] ) ; $ expected = <<< EOL         {             "data" : [                 {                     "type"       : "people",                     "id"         : "7",                     "attributes" : {                         "first_name" : "First",                         "last_name"  : "Last"                     },                     "links" : {                         "self" : "http://example.com/people/7"                     }                 },                 {                     "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 array of simple objects with attributes only.
Test encode array of simple objects with attributes only .