tests/Encoder/EncodeSimpleObjectsTest.php
/**
     * Test encode with Schema instance.
     *
     * @link https://github.com/neomerx/json-api/issues/168
     */
Test encode with Schema instance.
Test encode with Schema instance .
public function testEncodeWithSchmaInstance(): void
    {
        $authorSchema = new AuthorSchema(new Factory());
        $authorSchema->removeRelationship(Author::LINK_COMMENTS);
        $author  = Author::instance(9, 'Dan', 'Gebhardt');
        $encoder = Encoder::instance(
            [
                Author::class => $authorSchema,
            ]
        )->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 testEncodeWithSchmaInstance ( ) : void { $ authorSchema = new AuthorSchema ( new Factory ( ) ) ; $ authorSchema -> removeRelationship ( Author :: LINK_COMMENTS ) ; $ author = Author :: instance ( 9 , 'Dan' , 'Gebhardt' ) ; $ encoder = Encoder :: instance ( [ Author :: class => $ authorSchema , ] ) -> 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 with Schema instance.
Test encode with Schema instance .