|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace VGirol\JsonApiAssert\Asserts\Structure; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Assertions relating to the errors object |
|
9
|
|
|
*/ |
|
10
|
|
|
trait AssertErrorsObject |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Asserts that a json fragment is a valid errors object. |
|
14
|
|
|
* |
|
15
|
|
|
* It will do the following checks : |
|
16
|
|
|
* 1) asserts that the errors object is an array of objects (@see assertIsArrayOfObjects). |
|
17
|
|
|
* 2) asserts that each error object of the collection is valid (@see assertIsValidErrorObject). |
|
18
|
|
|
* |
|
19
|
|
|
* @param array $json |
|
20
|
|
|
* @param boolean $strict If true, unsafe characters are not allowed when checking members name. |
|
21
|
|
|
* |
|
22
|
|
|
* @return void |
|
23
|
|
|
* @throws \PHPUnit\Framework\AssertionFailedError |
|
24
|
|
|
*/ |
|
25
|
30 |
|
public static function assertIsValidErrorsObject($json, bool $strict): void |
|
26
|
|
|
{ |
|
27
|
30 |
|
static::askService('validateErrorsObject', $json, $strict); |
|
28
|
18 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Asserts that a json fragment is a valid error object. |
|
32
|
|
|
* |
|
33
|
|
|
* It will do the following checks : |
|
34
|
|
|
* 1) asserts that the error object is not empty. |
|
35
|
|
|
* 2) asserts it contains only the following allowed members : |
|
36
|
|
|
* "id", "links", "status", "code", "title", "details", "source", "meta" (@see assertContainsOnlyAllowedMembers). |
|
37
|
|
|
* |
|
38
|
|
|
* Optionaly, if presents, it will checks : |
|
39
|
|
|
* 3) asserts that the "status" member is a string. |
|
40
|
|
|
* 4) asserts that the "code" member is a string. |
|
41
|
|
|
* 5) asserts that the "title" member is a string. |
|
42
|
|
|
* 6) asserts that the "details" member is a string. |
|
43
|
|
|
* 7) asserts that the "source" member is valid(@see assertIsValidErrorSourceObject). |
|
44
|
|
|
* 8) asserts that the "links" member is valid(@see assertIsValidErrorLinksObject). |
|
45
|
|
|
* 9) asserts that the "meta" member is valid(@see assertIsValidMetaObject). |
|
46
|
|
|
* |
|
47
|
|
|
* @param array $json |
|
48
|
|
|
* @param boolean $strict If true, unsafe characters are not allowed when checking members name. |
|
49
|
|
|
* |
|
50
|
|
|
* @return void |
|
51
|
|
|
* @throws \PHPUnit\Framework\AssertionFailedError |
|
52
|
|
|
*/ |
|
53
|
42 |
|
public static function assertIsValidErrorObject($json, bool $strict): void |
|
54
|
|
|
{ |
|
55
|
42 |
|
static::askService('validateErrorObject', $json, $strict); |
|
56
|
3 |
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Asserts that a json fragment is a valid error links object. |
|
60
|
|
|
* |
|
61
|
|
|
* It will do the following checks : |
|
62
|
|
|
* 1) asserts that le links object is valid (@see assertIsValidLinksObject with only "about" member allowed). |
|
63
|
|
|
* |
|
64
|
|
|
* @param array $json |
|
65
|
|
|
* @param boolean $strict If true, unsafe characters are not allowed when checking members name. |
|
66
|
|
|
* |
|
67
|
|
|
* @return void |
|
68
|
|
|
* @throws \PHPUnit\Framework\AssertionFailedError |
|
69
|
|
|
*/ |
|
70
|
6 |
|
public static function assertIsValidErrorLinksObject($json, bool $strict): void |
|
71
|
|
|
{ |
|
72
|
6 |
|
static::askService('validateErrorLinksObject', $json, $strict); |
|
73
|
3 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Asserts that a json fragment is a valid error source object. |
|
77
|
|
|
* |
|
78
|
|
|
* It will do the following checks : |
|
79
|
|
|
* 1) if the "pointer" member is present, asserts it is a string starting with a "/" character. |
|
80
|
|
|
* 2) if the "parameter" member is present, asserts that it is a string. |
|
81
|
|
|
* |
|
82
|
|
|
* @param array $json |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
* @throws \PHPUnit\Framework\AssertionFailedError |
|
86
|
|
|
*/ |
|
87
|
18 |
|
public static function assertIsValidErrorSourceObject($json): void |
|
88
|
|
|
{ |
|
89
|
18 |
|
static::askService('validateErrorSourceObject', $json); |
|
90
|
6 |
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|