tests/Encoder/EncodeSimpleObjectsTest.php
/**
     * Test encode simple object with attributes only in array.
     */
Test encode simple object with attributes only in array.
Test encode simple object with attributes only in array .
public function testEncodeObjectWithAttributesOnlyInArray(): void
    {
        $author  = 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([$author]);
        $expected = <<<EOL
        {
            "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 testEncodeObjectWithAttributesOnlyInArray ( ) : void { $ author = 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 ( [ $ author ] ) ; $ expected = <<< EOL         {             "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 simple object with attributes only in array.
Test encode simple object with attributes only in array .