|
19 | 19 | use JsonApiPhp\JsonApi\Test\HasAssertEqualsAsJson; |
20 | 20 | use PHPUnit\Framework\TestCase; |
21 | 21 |
|
| 22 | +/** |
| 23 | + * Relationships |
| 24 | + * |
| 25 | + * The value of the relationships key MUST be an object (a “relationships object”). |
| 26 | + * Members of the relationships object (“relationships”) represent references |
| 27 | + * from the resource object in which it’s defined to other resource objects. |
| 28 | + * |
| 29 | + * Relationships may be to-one or to-many. |
| 30 | + * |
| 31 | + * A “relationship object” MUST contain at least one of the following: |
| 32 | + * |
| 33 | + * - links: a links object containing at least one of the following: |
| 34 | + * - self: a link for the relationship itself (a “relationship link”). |
| 35 | + * This link allows the client to directly manipulate the relationship. |
| 36 | + * For example, removing an author through an article’s relationship URL would disconnect the person |
| 37 | + * from the article without deleting the people resource itself. When fetched successfully, this link |
| 38 | + * returns the linkage for the related resources as its primary data. (See Fetching Relationships.) |
| 39 | + * - related: a related resource link |
| 40 | + * - data: resource linkage |
| 41 | + * - meta: a meta object that contains non-standard meta-information about the relationship. |
| 42 | + * |
| 43 | + * A relationship object that represents a to-many relationship MAY also contain |
| 44 | + * pagination links under the links member, as described below. |
| 45 | + * |
| 46 | + * @see http://jsonapi.org/format/#document-resource-object-relationships |
| 47 | + * @see RelationshipTest::testCanCreateFromSelfLink() |
| 48 | + * @see RelationshipTest::testCanCreateFromRelatedLink()) |
| 49 | + * @see RelationshipTest::testCanCreateFromLinkage()) |
| 50 | + * @see RelationshipTest::testCanCreateFromMeta()) |
| 51 | + */ |
22 | 52 | class RelationshipTest extends TestCase |
23 | 53 | { |
24 | 54 | use HasAssertEqualsAsJson; |
25 | 55 |
|
26 | | - public function testCanCreateFromMeta() |
27 | | - { |
28 | | - $this->assertEqualsAsJson( |
29 | | - [ |
30 | | - 'meta' => [ |
31 | | - 'a' => 'b', |
32 | | - ] |
33 | | - ], |
34 | | - Relationship::fromMeta(['a' => 'b']) |
35 | | - ); |
36 | | - } |
37 | | - |
38 | 56 | public function testCanCreateFromSelfLink() |
39 | 57 | { |
40 | 58 | $this->assertEqualsAsJson( |
@@ -68,4 +86,16 @@ public function testCanCreateFromLinkage() |
68 | 86 | Relationship::fromLinkage(Linkage::nullLinkage()) |
69 | 87 | ); |
70 | 88 | } |
| 89 | + |
| 90 | + public function testCanCreateFromMeta() |
| 91 | + { |
| 92 | + $this->assertEqualsAsJson( |
| 93 | + [ |
| 94 | + 'meta' => [ |
| 95 | + 'a' => 'b', |
| 96 | + ] |
| 97 | + ], |
| 98 | + Relationship::fromMeta(['a' => 'b']) |
| 99 | + ); |
| 100 | + } |
71 | 101 | } |
0 commit comments