1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VGirol\JsonApiAssert\Asserts\Structure; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Assertions relating to the relationships object |
9
|
|
|
*/ |
10
|
|
|
trait AssertRelationshipsObject |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Asserts that a json fragment is a valid relationships object. |
14
|
|
|
* |
15
|
|
|
* It will do the following checks : |
16
|
|
|
* 1) asserts that the relationships object is not an array of objects (@see assertIsNotArrayOfObjects). |
17
|
|
|
* 2) asserts that each relationship of the collection has a valid name (@see assertIsValidMemberName) |
18
|
|
|
* and is a valid relationship object (@see assertIsValidRelationshipObject). |
19
|
|
|
* |
20
|
|
|
* @param array $json |
21
|
|
|
* @param boolean $strict If true, unsafe characters are not allowed when checking members name. |
22
|
|
|
* |
23
|
|
|
* @return void |
24
|
|
|
* @throws \PHPUnit\Framework\AssertionFailedError |
25
|
|
|
*/ |
26
|
12 |
|
public static function assertIsValidRelationshipsObject($json, bool $strict): void |
27
|
|
|
{ |
28
|
12 |
|
static::askService('validateRelationshipsObject', $json, $strict); |
29
|
3 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Asserts that a json fragment is a valid relationship object. |
33
|
|
|
* |
34
|
|
|
* It will do the following checks : |
35
|
|
|
* 1) asserts that the relationship object contains at least one of the following member : "links", "data", "meta" |
36
|
|
|
* (@see assertContainsAtLeastOneMember). |
37
|
|
|
* |
38
|
|
|
* Optionaly, if presents, it will checks : |
39
|
|
|
* 2) asserts that the data member is valid (@see assertIsValidResourceLinkage). |
40
|
|
|
* 3) asserts that the links member is valid (@see assertIsValidRelationshipLinksObject). |
41
|
|
|
* 4) asserts that the meta object is valid (@see assertIsValidMetaObject). |
42
|
|
|
* |
43
|
|
|
* @param array $json |
44
|
|
|
* @param boolean $strict If true, unsafe characters are not allowed when checking members name. |
45
|
|
|
* |
46
|
|
|
* @return void |
47
|
|
|
* @throws \PHPUnit\Framework\AssertionFailedError |
48
|
|
|
*/ |
49
|
30 |
|
public static function assertIsValidRelationshipObject($json, bool $strict): void |
50
|
|
|
{ |
51
|
30 |
|
static::askService('validateRelationshipObject', $json, $strict); |
52
|
12 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Asserts that a json fragment is a valid link object extracted from a relationship object. |
56
|
|
|
* |
57
|
|
|
* It will do the following checks : |
58
|
|
|
* 1) asserts that the links object is valid (@see assertIsValidLinksObject) |
59
|
|
|
* with the following allowed members : "self", "related" |
60
|
|
|
* and eventually pagination links ("first", "last", "prev" and "next"). |
61
|
|
|
* |
62
|
|
|
* @param array $json |
63
|
|
|
* @param boolean $withPagination |
64
|
|
|
* @param boolean $strict If true, unsafe characters are not allowed when checking members name. |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
* @throws \PHPUnit\Framework\AssertionFailedError |
68
|
|
|
*/ |
69
|
12 |
|
public static function assertIsValidRelationshipLinksObject($json, bool $withPagination, bool $strict): void |
70
|
|
|
{ |
71
|
12 |
|
static::askService('validateRelationshipLinksObject', $json, $withPagination, $strict); |
72
|
6 |
|
} |
73
|
|
|
} |
74
|
|
|
|