public function testRelationshipsSubset()
    {
        $content = <<<JSON_API
{
    "data": {
        "type": "posts",
        "id": "123",
        "relationships": {
            "author": {
                "data": {
                    "type": "users",
                    "id": "123"
                }
            },
            "comments": {
                "data": [
                    {"type": "comments", "id": 1},
                    {"type": "comments", "id": 2}
                ]
            }
        }
    }
}
JSON_API;
        $resource = DocumentTester::create($content)->assertResource();
        $resource->assertRelationshipsSubset(['author' => ['data' => ['type' => 'users', 'id' => '123']], 'comments' => []]);
        $this->willFail(function () use($resource) {
            $resource->assertRelationshipsSubset(['author' => ['data' => ['id' => '456']]]);
        });
    }
예제 #2
0
    public function testErrorParameter()
    {
        $content = <<<JSON_API
{
    "errors": [
        {"source": {"parameter": "filter.foo"}}
    ]
}
JSON_API;
        $error = DocumentTester::create($content)->assertErrors()->assertOne()->assertParameter('filter.foo');
        $this->willFail(function () use($error) {
            $error->assertParameter('filter.bar');
        });
    }
    public function testPolymorphicTypes()
    {
        $content = <<<JSON_API
{
    "data": [
        {
            "type": "posts",
            "id": "1",
            "attributes": {
                "type": "My first post"
            }
        },
        {
            "type": "posts",
            "id": "2",
            "attributes": {
                "type": "My second post"
            }
        },
        {
            "type": "comments",
            "id": "99",
            "attributes": {
                "content": "This is my comment"
            }
        }
    ]
}
JSON_API;
        $document = DocumentTester::create($content);
        $collection = $document->assertResourceCollection()->assertTypes(['posts', 'comments']);
        $this->willFail(function () use($collection) {
            $collection->assertTypes(['posts', 'users']);
        });
        return $collection;
    }