1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VGirol\JsonApiAssert\Asserts\Structure; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Assertions relating to the links object |
9
|
|
|
*/ |
10
|
|
|
trait AssertLinksObject |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Asserts that a json fragment is a valid links object. |
14
|
|
|
* |
15
|
|
|
* It will do the following checks : |
16
|
|
|
* 1) asserts that it contains only allowed members (@see assertContainsOnlyAllowedMembers). |
17
|
|
|
* 2) asserts that each member of the links object is a valid link object (@see assertIsValidLinkObject). |
18
|
|
|
* |
19
|
|
|
* @param array $json |
20
|
|
|
* @param array<string> $allowedMembers |
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
|
15 |
|
public static function assertIsValidLinksObject($json, array $allowedMembers, bool $strict): void |
27
|
|
|
{ |
28
|
15 |
|
static::askService('validateLinksObject', $json, $allowedMembers, $strict); |
29
|
3 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Asserts that a json fragment is a valid link object. |
33
|
|
|
* |
34
|
|
|
* It will do the following checks : |
35
|
|
|
* 1) asserts that the link object is a string, an array or the `null` value. |
36
|
|
|
* 2) in case it is an array : |
37
|
|
|
* 3) asserts that it has the "href" member. |
38
|
|
|
* 4) asserts that it contains only the following allowed members : "href" and "meta" |
39
|
|
|
* (@see assertContainsOnlyAllowedMembers). |
40
|
|
|
* 5) if present, asserts that the "meta" object is valid (@see assertIsValidMetaObject). |
41
|
|
|
* |
42
|
|
|
* @param array|string|null $json |
43
|
|
|
* @param boolean $strict If true, unsafe characters are not allowed when checking members name. |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
* @throws \PHPUnit\Framework\AssertionFailedError |
47
|
|
|
*/ |
48
|
24 |
|
public static function assertIsValidLinkObject($json, bool $strict): void |
49
|
|
|
{ |
50
|
24 |
|
static::askService('validateLinkObject', $json, $strict); |
51
|
9 |
|
} |
52
|
|
|
} |
53
|
|
|
|