1
|
|
|
<?php |
2
|
|
|
/******************************************************************************* |
3
|
|
|
* This file is part of the GraphQL Bundle package. |
4
|
|
|
* |
5
|
|
|
* (c) YnloUltratech <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
******************************************************************************/ |
10
|
|
|
|
11
|
|
|
namespace Ynlo\GraphQLBundle\Test\Assert; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @method Response getResponse() |
17
|
|
|
* |
18
|
|
|
* @requires JsonHelperTrait |
19
|
|
|
*/ |
20
|
|
|
trait JsonAssertTrait |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @param string|array $json |
24
|
|
|
* @param string $type |
25
|
|
|
* @param string $path |
26
|
|
|
*/ |
27
|
|
|
public static function assertJsonValueInternalType($json, $type, $path) |
28
|
|
|
{ |
29
|
|
|
static::assertInternalType($type, static::getJsonPathValue($json, $path)); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string|array $json |
34
|
|
|
* @param string $type |
35
|
|
|
* @param string $path |
36
|
|
|
*/ |
37
|
|
|
public static function assertJsonValueNotInternalType($json, $type, $path) |
38
|
|
|
{ |
39
|
|
|
static::assertNotInternalType($type, static::getJsonPathValue($json, $path)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string|array $json |
44
|
|
|
* @param mixed $expected |
45
|
|
|
* @param string $path |
46
|
|
|
*/ |
47
|
|
|
public static function assertJsonValueEquals($json, $expected, $path) |
48
|
|
|
{ |
49
|
|
|
static::assertEquals($expected, static::getJsonPathValue($json, $path)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string|array $json |
54
|
|
|
* @param string $path |
55
|
|
|
*/ |
56
|
|
|
public static function assertJsonValueIsFalse($json, $path) |
57
|
|
|
{ |
58
|
|
|
static::assertFalse(static::getJsonPathValue($json, $path)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string|array $json |
63
|
|
|
* @param string $path |
64
|
|
|
*/ |
65
|
|
|
public static function assertJsonValueIsTrue($json, $path) |
66
|
|
|
{ |
67
|
|
|
static::assertTrue(static::getJsonPathValue($json, $path)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string|array $json |
72
|
|
|
* @param mixed $expected |
73
|
|
|
* @param string $path |
74
|
|
|
*/ |
75
|
|
|
public static function assertJsonValueNotEquals($json, $expected, $path) |
76
|
|
|
{ |
77
|
|
|
static::assertNotEquals($expected, static::getJsonPathValue($json, $path)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string|array $json |
82
|
|
|
* @param string $path |
83
|
|
|
*/ |
84
|
|
|
public static function assertJsonValueIsNull($json, $path) |
85
|
|
|
{ |
86
|
|
|
static::assertNull(static::getJsonPathValue($json, $path)); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string|array $json |
91
|
|
|
* @param mixed $expected |
92
|
|
|
* @param string $path |
93
|
|
|
*/ |
94
|
|
|
public static function assertJsonArraySubset($json, $expected, $path) |
95
|
|
|
{ |
96
|
|
|
static::assertArraySubset($expected, static::getJsonPathValue($json, $path)); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string|array $json |
101
|
|
|
* @param string $format |
102
|
|
|
* @param string $path |
103
|
|
|
*/ |
104
|
|
|
public static function assertJsonValueMatchesFormat($json, $format, $path) |
105
|
|
|
{ |
106
|
|
|
$value = static::getJsonPathValue($json, $path); |
107
|
|
|
static::assertStringMatchesFormat($format, $value); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param string|array $json |
112
|
|
|
* @param string $format |
113
|
|
|
* @param string $path |
114
|
|
|
*/ |
115
|
|
|
public static function assertJsonValueNotMatchesFormat($json, $format, $path) |
116
|
|
|
{ |
117
|
|
|
$value = static::getJsonPathValue($json, $path); |
118
|
|
|
static::assertStringNotMatchesFormat($format, $value); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param string|array $json |
123
|
|
|
* @param string $pattern |
124
|
|
|
* @param string $path |
125
|
|
|
*/ |
126
|
|
|
public static function assertJsonValueRegExp($json, $pattern, $path) |
127
|
|
|
{ |
128
|
|
|
$value = static::getJsonPathValue($json, $path); |
129
|
|
|
static::assertRegExp($pattern, $value); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string|array $json |
134
|
|
|
* @param string $pattern |
135
|
|
|
* @param string $path |
136
|
|
|
*/ |
137
|
|
|
public static function assertJsonValueNotRegExp($json, $pattern, $path) |
138
|
|
|
{ |
139
|
|
|
$value = static::getJsonPathValue($json, $path); |
140
|
|
|
static::assertNotRegExp($pattern, $value); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|