1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VGirol\JsonApiAssert\Asserts\Structure; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Assertions relating to the resource linkage |
9
|
|
|
*/ |
10
|
|
|
trait AssertResourceLinkage |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Asserts that a json fragment is a valid resource linkage object. |
14
|
|
|
* |
15
|
|
|
* It will do the following checks : |
16
|
|
|
* 1) asserts that the provided resource linkage is either an object, an array of objects or the `null` value. |
17
|
|
|
* 2) asserts that the resource linkage or the collection of resource linkage is valid |
18
|
|
|
* (@see assertIsValidResourceIdentifierObject). |
19
|
|
|
* |
20
|
|
|
* @param array|null $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
|
60 |
|
public static function assertIsValidResourceLinkage($json, bool $strict): void |
27
|
|
|
{ |
28
|
60 |
|
static::askService('validateResourceLinkage', $json, $strict); |
29
|
45 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Asserts that a json fragment is a valid resource identifier object. |
33
|
|
|
* |
34
|
|
|
* It will do the following checks : |
35
|
|
|
* 1) asserts that the resource as "id" (@see assertResourceIdMember) |
36
|
|
|
* and "type" (@see assertResourceTypeMember) members. |
37
|
|
|
* 2) asserts that it contains only the following allowed members : "id", "type" and "meta" |
38
|
|
|
* (@see assertContainsOnlyAllowedMembers). |
39
|
|
|
* |
40
|
|
|
* Optionaly, if presents, it will checks : |
41
|
|
|
* 3) asserts that the meta object is valid (@see assertIsValidMetaObject). |
42
|
|
|
* |
43
|
|
|
* @param array $resource |
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
|
24 |
|
public static function assertIsValidResourceIdentifierObject($resource, bool $strict): void |
50
|
|
|
{ |
51
|
24 |
|
static::askService('validateResourceIdentifierObject', $resource, $strict); |
52
|
3 |
|
} |
53
|
|
|
} |
54
|
|
|
|