forked from json-api-php/json-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegrationTest.php
More file actions
69 lines (63 loc) · 1.86 KB
/
Copy pathIntegrationTest.php
File metadata and controls
69 lines (63 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
*
* * This file is part of JSON:API implementation for PHP.
* *
* * (c) Alexey Karapetov <karapetov@gmail.com>
* *
* * For the full copyright and license information, please view the LICENSE
* * file that was distributed with this source code.
*
*/
declare(strict_types=1);
namespace JsonApiPhp\JsonApi\Test;
use JsonApiPhp\JsonApi\Document\Document;
use JsonApiPhp\JsonApi\Document\Resource\Relationship\Linkage;
use JsonApiPhp\JsonApi\Document\Resource\Relationship\Relationship;
use JsonApiPhp\JsonApi\Document\Resource\ResourceObject;
use JsonApiPhp\JsonApi\Document\Resource\ResourceId;
use PHPUnit\Framework\TestCase;
class IntegrationTest extends TestCase
{
public function testFromTheReadmeFile()
{
$json = <<<JSON
{
"data": {
"type": "articles",
"id": "1",
"attributes": {
"title": "Rails is Omakase"
},
"relationships": {
"author": {
"data": {
"type": "people",
"id": "9"
},
"links": {
"self": "\/articles\/1\/relationships\/author",
"related": "\/articles\/1\/author"
}
}
}
}
}
JSON;
$articles = new ResourceObject('articles', '1');
$author = Relationship::fromLinkage(
Linkage::fromSingleResourceId(
new ResourceId('people', '9')
)
);
$author->setLink('self', '/articles/1/relationships/author');
$author->setLink('related', '/articles/1/author');
$articles->setRelationship('author', $author);
$articles->setAttribute('title', 'Rails is Omakase');
$doc = Document::fromResource($articles);
$this->assertEquals(
$json,
json_encode($doc, JSON_PRETTY_PRINT)
);
}
}