1 | <?php |
||
20 | class Assert |
||
21 | { |
||
22 | use TypeAssertTrait; |
||
23 | use ObjectAssertTrait; |
||
24 | use CollectionAssertTrait; |
||
25 | |||
26 | /** |
||
27 | * An array of operators mapping to assertions. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | public static $operators = [ |
||
32 | '==' => 'loosely->equal', |
||
33 | '===' => 'equal', |
||
34 | '>' => 'above', |
||
35 | '>=' => 'least', |
||
36 | '<' => 'below', |
||
37 | '<=' => 'most', |
||
38 | '!=' => 'not->loosely->equal', |
||
39 | '!==' => 'not->equal', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * @var Assertion |
||
44 | */ |
||
45 | protected $assertion; |
||
46 | |||
47 | /** |
||
48 | * @param Assertion $assertion |
||
49 | */ |
||
50 | public function __construct(Assertion $assertion = null) |
||
57 | |||
58 | /** |
||
59 | * Perform an a loose equality assertion. |
||
60 | * |
||
61 | * @param mixed $actual |
||
62 | * @param mixed $expected |
||
63 | * @param string $message |
||
64 | */ |
||
65 | public function equal($actual, $expected, $message = '') |
||
71 | |||
72 | /** |
||
73 | * Perform a negated loose equality assertion. |
||
74 | * |
||
75 | * @param mixed $actual |
||
76 | * @param mixed $expected |
||
77 | * @param string $message |
||
78 | */ |
||
79 | public function notEqual($actual, $expected, $message = '') |
||
85 | |||
86 | /** |
||
87 | * Performs a throw assertion. |
||
88 | * |
||
89 | * @param callable $fn |
||
90 | * @param $exceptionType |
||
91 | * @param string $exceptionMessage |
||
92 | * @param string $message |
||
93 | */ |
||
94 | public function throws(callable $fn, $exceptionType, $exceptionMessage = '', $message = '') |
||
100 | |||
101 | /** |
||
102 | * Performs a negated throw assertion. |
||
103 | * |
||
104 | * @param callable $fn |
||
105 | * @param $exceptionType |
||
106 | * @param string $exceptionMessage |
||
107 | * @param string $message |
||
108 | */ |
||
109 | public function doesNotThrow(callable $fn, $exceptionType, $exceptionMessage = '', $message = '') |
||
115 | |||
116 | /** |
||
117 | * Perform an ok assertion. |
||
118 | * |
||
119 | * @param mixed $object |
||
120 | * @param string $message |
||
121 | */ |
||
122 | public function ok($object, $message = '') |
||
128 | |||
129 | /** |
||
130 | * Perform a negated assertion. |
||
131 | * |
||
132 | * @param mixed $object |
||
133 | * @param string $message |
||
134 | */ |
||
135 | public function notOk($object, $message = '') |
||
141 | |||
142 | /** |
||
143 | * Perform a strict equality assertion. |
||
144 | * |
||
145 | * @param mixed $actual |
||
146 | * @param mixed $expected |
||
147 | * @param string $message |
||
148 | */ |
||
149 | public function strictEqual($actual, $expected, $message = '') |
||
155 | |||
156 | /** |
||
157 | * Perform a negated strict equality assertion. |
||
158 | * |
||
159 | * @param mixed $actual |
||
160 | * @param mixed $expected |
||
161 | * @param string $message |
||
162 | */ |
||
163 | public function notStrictEqual($actual, $expected, $message = '') |
||
169 | |||
170 | /** |
||
171 | * Perform a pattern assertion. |
||
172 | * |
||
173 | * @param string $value |
||
174 | * @param string $pattern |
||
175 | * @param string $message |
||
176 | */ |
||
177 | public function match($value, $pattern, $message = '') |
||
183 | |||
184 | /** |
||
185 | * Perform a negated pattern assertion. |
||
186 | * |
||
187 | * @param string $value |
||
188 | * @param string $pattern |
||
189 | * @param string $message |
||
190 | */ |
||
191 | public function notMatch($value, $pattern, $message = '') |
||
197 | |||
198 | /** |
||
199 | * Compare two values using the given operator. |
||
200 | * |
||
201 | * @param mixed $left |
||
202 | * @param string $operator |
||
203 | * @param mixed $right |
||
204 | * @param string $message |
||
205 | */ |
||
206 | public function operator($left, $operator, $right, $message = '') |
||
215 | |||
216 | /** |
||
217 | * Defined to allow use of reserved words for methods. |
||
218 | * |
||
219 | * @param $method |
||
220 | * @param $args |
||
221 | */ |
||
222 | public function __call($method, $args) |
||
233 | } |
||
234 |