tests/Encoder/EncoderTest.php
/**
     * Test encode 2 main resource duplicates and try to apply field set filter on relations.
     */
Test encode 2 main resource duplicates and try to apply field set filter on relations.
Test encode 2 main resource duplicates and try to apply field set filter on relations .
public function testEncodeDuplicatesWithRelationFieldSetFilter(): void
    {
        $author   = Author::instance(9, 'Dan', 'Gebhardt');
        $comments = [
            Comment::instance(5, 'First!', $author),
            Comment::instance(12, 'I like XML better', $author),
        ];
        $encoder  = Encoder::instance(
            [
                Author::class  => AuthorSchema::class,
                Comment::class => CommentSchema::class,
            ]
        )->withUrlPrefix('http://example.com')->withFieldSets(
            ['people' => [Author::ATTRIBUTE_LAST_NAME, Author::ATTRIBUTE_FIRST_NAME]]
        );
        $author->{Author::LINK_COMMENTS} = $comments;
        $actual = $encoder->encodeData([$author, $author]);
        $expected = <<<EOL
        {
            "data" : [
                {
                    "type"       : "people",
                    "id"         : "9",
                    "attributes" : {
                        "first_name" : "Dan",
                        "last_name"  : "Gebhardt"
                    },
                    "links" : {
                        "self" : "http://example.com/people/9"
                    }
                },
                {
                    "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 testEncodeDuplicatesWithRelationFieldSetFilter ( ) : void { $ author = Author :: instance ( 9 , 'Dan' , 'Gebhardt' ) ; $ comments = [ Comment :: instance ( 5 , 'First!' , $ author ) , Comment :: instance ( 12 , 'I like XML better' , $ author ) , ] ; $ encoder = Encoder :: instance ( [ Author :: class => AuthorSchema :: class , Comment :: class => CommentSchema :: class , ] ) -> withUrlPrefix ( 'http://example.com' ) -> withFieldSets ( [ 'people' => [ Author :: ATTRIBUTE_LAST_NAME , Author :: ATTRIBUTE_FIRST_NAME ] ] ) ; $ author -> { Author :: LINK_COMMENTS } = $ comments ; $ actual = $ encoder -> encodeData ( [ $ author , $ author ] ) ; $ expected = <<< EOL         {             "data" : [                 {                     "type"       : "people",                     "id"         : "9",                     "attributes" : {                         "first_name" : "Dan",                         "last_name"  : "Gebhardt"                     },                     "links" : {                         "self" : "http://example.com/people/9"                     }                 },                 {                     "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 2 main resource duplicates and try to apply field set filter on relations.
Test encode 2 main resource duplicates and try to apply field set filter on relations .
// filter attributes