|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace VGirol\JsonApiAssert\Asserts\Structure; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Assertions relating to the attributes object |
|
9
|
|
|
*/ |
|
10
|
|
|
trait AssertAttributesObject |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Asserts that a json fragment is a valid attributes object. |
|
14
|
|
|
* |
|
15
|
|
|
* It will do the following checks : |
|
16
|
|
|
* 1) asserts that attributes object is not an array of objects (@see assertIsNotArrayOfObjects). |
|
17
|
|
|
* 2) asserts that attributes object has no member with forbidden name (@see assertFieldHasNoForbiddenMemberName). |
|
18
|
|
|
* 3) asserts that each member name of the attributes object is valid (@see assertIsValidMemberName). |
|
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
|
18 |
|
public static function assertIsValidAttributesObject($json, bool $strict): void |
|
27
|
|
|
{ |
|
28
|
18 |
|
static::askService('validateAttributesObject', $json, $strict); |
|
29
|
6 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Asserts that a field object has no forbidden member name. |
|
33
|
|
|
* |
|
34
|
|
|
* Asserts that a field object (i.e., a resource object’s attributes or one of its relationships) |
|
35
|
|
|
* has no forbidden member name. |
|
36
|
|
|
* |
|
37
|
|
|
* It will do the following checks : |
|
38
|
|
|
* 1) asserts that each member name of the field is not a forbidden name (@see assertIsNotForbiddenMemberName). |
|
39
|
|
|
* 2) if the field has nested objects, it will checks each all. |
|
40
|
|
|
* |
|
41
|
|
|
* @param mixed $field |
|
42
|
|
|
* |
|
43
|
|
|
* @return void |
|
44
|
|
|
* @throws \PHPUnit\Framework\AssertionFailedError |
|
45
|
|
|
*/ |
|
46
|
9 |
|
public static function assertFieldHasNoForbiddenMemberName($field): void |
|
47
|
|
|
{ |
|
48
|
9 |
|
static::askService('fieldHasNoForbiddenMemberName', $field); |
|
49
|
3 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Asserts that a member name is not forbidden (like "relationships" or "links"). |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $name |
|
55
|
|
|
* |
|
56
|
|
|
* @return void |
|
57
|
|
|
* @throws \PHPUnit\Framework\AssertionFailedError |
|
58
|
|
|
*/ |
|
59
|
12 |
|
public static function assertIsNotForbiddenMemberName($name): void |
|
60
|
|
|
{ |
|
61
|
12 |
|
static::askService('isNotForbiddenMemberName', $name); |
|
62
|
3 |
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|