tests/Extensions/Issue236/IssueTest.php
/**
     * Test having extra info (current path of the resource being parsed) in a schema.
     *
     * @see https://github.com/neomerx/json-api/issues/236
     */
Test having extra info (current path of the resource being parsed) in a schema.
Test having extra info ( current path of the resource being parsed ) in a schema .
public function testDataSerializationWithPartialWildcard(): void
    {
        $pathsToInclude  = [Comment::LINK_AUTHOR];
        $fieldSetFilters = [];
        $actual = CustomEncoder::instance($this->prepareSchemas($pathsToInclude, $fieldSetFilters))
            ->withUrlPrefix('http://example.com')
            ->withIncludedPaths($pathsToInclude)
            ->encodeData($this->prepareDataToEncode());
        $expected = <<<EOL
        {
            "data" : {
                "type" : "comments",
                "id"   : "5",
                "attributes" : {
                    "body" : "First!"
                },
                "relationships" : {
                    "author" : {
                        "links" : {
                            "self": "http://example.com/comments/5/relationships/author"
                        },
                        "data"  : { "type":"people", "id":"42" },
                        "meta" : {
                            "current_path"             : "",
                            "fields_filter"            : null,
                            "relationships_to_include" : [
                                "author"
                            ]
                        }
                    }
                },
                "links":{
                    "self" : "http://example.com/comments/5"
                }
            },
            "included" : [{
                "type" : "people",
                "id"   : "42",
                "attributes" : {
                    "first_name" : "Peter",
                    "last_name"  : "Weller"
                },
                "relationships":{
                    "comments" : {
                        "links": {
                            "self": "http://example.com/people/42/relationships/comments"
                        },
                        "meta": {
                            "current_path"             : "author",
                            "fields_filter"            : null,
                            "relationships_to_include" : []
                        }
                    }
                },
                "links": {
                    "self": "http://example.com/people/42"
                }
            }]
        }
EOL;
        self::assertJsonStringEqualsJsonString($expected, $actual);
    }
public function testDataSerializationWithPartialWildcard ( ) : void { $ pathsToInclude = [ Comment :: LINK_AUTHOR ] ; $ fieldSetFilters = [ ] ; $ actual = CustomEncoder :: instance ( $ this -> prepareSchemas ( $ pathsToInclude , $ fieldSetFilters ) ) -> withUrlPrefix ( 'http://example.com' ) -> withIncludedPaths ( $ pathsToInclude ) -> encodeData ( $ this -> prepareDataToEncode ( ) ) ; $ expected = <<< EOL         {             "data" : {                 "type" : "comments",                 "id"   : "5",                 "attributes" : {                     "body" : "First!"                 },                 "relationships" : {                     "author" : {                         "links" : {                             "self": "http://example.com/comments/5/relationships/author"                         },                         "data"  : { "type":"people", "id":"42" },                         "meta" : {                             "current_path"             : "",                             "fields_filter"            : null,                             "relationships_to_include" : [                                 "author"                             ]                         }                     }                 },                 "links":{                     "self" : "http://example.com/comments/5"                 }             },             "included" : [{                 "type" : "people",                 "id"   : "42",                 "attributes" : {                     "first_name" : "Peter",                     "last_name"  : "Weller"                 },                 "relationships":{                     "comments" : {                         "links": {                             "self": "http://example.com/people/42/relationships/comments"                         },                         "meta": {                             "current_path"             : "author",                             "fields_filter"            : null,                             "relationships_to_include" : []                         }                     }                 },                 "links": {                     "self": "http://example.com/people/42"                 }             }]         } 
EOL ; self :: assertJsonStringEqualsJsonString ( $ expected , $ actual ) ; }
Test having extra info (current path of the resource being parsed) in a schema.
Test having extra info ( current path of the resource being parsed ) in a schema .
// please note the whole point of encoding is to have `include paths` and `current path` in meta so // the schema to know which relationships should be included.