tests/Extensions/Issue231/IssueTest.php
/**
     * Test support of wildcards in include paths.
     *
     * @see https://github.com/neomerx/json-api/issues/231
     */
Test support of wildcards in include paths.
Test support of wildcards in include paths .
public function testDataSerializationWithFullWildcard(): void
    {
        $actual = CustomEncoder::instance($this->prepareSchemas())
            ->withUrlPrefix('http://example.com')
            ->withIncludedPaths([CustomEncoder::PATH_WILDCARD_ALL])
            ->encodeData($this->prepareDataToEncode());
        $expected = <<<EOL
        {
            "data" : {
                "type"  : "sites",
                "id"    : "2",
                "attributes" : {
                    "name"  : "site name"
                },
                "relationships" : {
                    "posts" : {
                        "data" : [{
                            "type" : "posts",
                            "id" : "1"
                        }]
                    }
                },
                "links" : {
                    "self" : "http://example.com/sites/2"
                }
            },
            "included" : [{
                "type"  : "posts",
                "id"    : "1",
                "attributes" : {
                    "title" : "JSON API paints my bikeshed!",
                    "body"  : "Outside every fat man there was an even fatter man trying to close in"
                },
                "relationships" : {
                    "author"   : { "data" : { "type" : "people", "id" : "9" } },
                    "comments" : { "data" : [
                        { "type" : "comments", "id" : "5" },
                        { "type" : "comments", "id" : "12" }
                    ]}
                }
            }, {
                "type" : "people",
                "id"   : "9",
                "attributes" : {
                    "first_name" : "Dan",
                    "last_name"  : "Gebhardt"
                },
                "relationships":{
                    "comments" : {
                        "links": {
                            "self": "http://example.com/people/9/relationships/comments"
                        }
                    }
                }
            }, {
                "type" : "comments",
                "id"   : "5",
                "attributes" : {
                    "body" : "First!"
                },
                "relationships" : {
                    "author" : {
                        "data" : { "type":"people", "id":"42" }
                    }
                },
                "links":{
                    "self" : "http://example.com/comments/5"
                }
            }, {
                "type" : "people",
                "id"   : "42",
                "attributes" : {
                    "first_name" : "Peter",
                    "last_name"  : "Weller"
                },
                "relationships":{
                    "comments" : {
                        "links": {
                            "self": "http://example.com/people/42/relationships/comments"
                        }
                    }
                }
            }, {
                "type" : "comments",
                "id"   : "12",
                "attributes" : {
                    "body" : "I like XML better"
                },
                "relationships":{
                    "author" : {
                        "data" : { "type":"people", "id":"42" }
                    }
                },
                "links":{
                    "self" : "http://example.com/comments/12"
                }
            }]
        }
EOL;
        self::assertJsonStringEqualsJsonString($expected, $actual);
    }
public function testDataSerializationWithFullWildcard ( ) : void { $ actual = CustomEncoder :: instance ( $ this -> prepareSchemas ( ) ) -> withUrlPrefix ( 'http://example.com' ) -> withIncludedPaths ( [ CustomEncoder :: PATH_WILDCARD_ALL ] ) -> encodeData ( $ this -> prepareDataToEncode ( ) ) ; $ expected = <<< EOL         {             "data" : {                 "type"  : "sites",                 "id"    : "2",                 "attributes" : {                     "name"  : "site name"                 },                 "relationships" : {                     "posts" : {                         "data" : [{                             "type" : "posts",                             "id" : "1"                         }]                     }                 },                 "links" : {                     "self" : "http://example.com/sites/2"                 }             },             "included" : [{                 "type"  : "posts",                 "id"    : "1",                 "attributes" : {                     "title" : "JSON API paints my bikeshed!",                     "body"  : "Outside every fat man there was an even fatter man trying to close in"                 },                 "relationships" : {                     "author"   : { "data" : { "type" : "people", "id" : "9" } },                     "comments" : { "data" : [                         { "type" : "comments", "id" : "5" },                         { "type" : "comments", "id" : "12" }                     ]}                 }             }, {                 "type" : "people",                 "id"   : "9",                 "attributes" : {                     "first_name" : "Dan",                     "last_name"  : "Gebhardt"                 },                 "relationships":{                     "comments" : {                         "links": {                             "self": "http://example.com/people/9/relationships/comments"                         }                     }                 }             }, {                 "type" : "comments",                 "id"   : "5",                 "attributes" : {                     "body" : "First!"                 },                 "relationships" : {                     "author" : {                         "data" : { "type":"people", "id":"42" }                     }                 },                 "links":{                     "self" : "http://example.com/comments/5"                 }             }, {                 "type" : "people",                 "id"   : "42",                 "attributes" : {                     "first_name" : "Peter",                     "last_name"  : "Weller"                 },                 "relationships":{                     "comments" : {                         "links": {                             "self": "http://example.com/people/42/relationships/comments"                         }                     }                 }             }, {                 "type" : "comments",                 "id"   : "12",                 "attributes" : {                     "body" : "I like XML better"                 },                 "relationships":{                     "author" : {                         "data" : { "type":"people", "id":"42" }                     }                 },                 "links":{                     "self" : "http://example.com/comments/12"                 }             }]         } 
EOL ; self :: assertJsonStringEqualsJsonString ( $ expected , $ actual ) ; }
Test support of wildcards in include paths.
Test support of wildcards in include paths .