1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
* This file is part of PHPUnit. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Bergmann <[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
|
|
|
* This file is added for benchmark purposes only!!! |
11
|
|
|
*/ |
12
|
|
|
namespace PHPUnit\Framework; |
13
|
|
|
|
14
|
|
|
use ArrayAccess; |
15
|
|
|
use Countable; |
16
|
|
|
use DOMDocument; |
17
|
|
|
use DOMElement; |
18
|
|
|
use PHPUnit\Framework\Constraint\ArrayHasKey; |
19
|
|
|
use PHPUnit\Framework\Constraint\ArraySubset; |
20
|
|
|
use PHPUnit\Framework\Constraint\Attribute; |
21
|
|
|
use PHPUnit\Framework\Constraint\Callback; |
22
|
|
|
use PHPUnit\Framework\Constraint\ClassHasAttribute; |
23
|
|
|
use PHPUnit\Framework\Constraint\ClassHasStaticAttribute; |
24
|
|
|
use PHPUnit\Framework\Constraint\Constraint; |
25
|
|
|
use PHPUnit\Framework\Constraint\Count; |
26
|
|
|
use PHPUnit\Framework\Constraint\DirectoryExists; |
27
|
|
|
use PHPUnit\Framework\Constraint\FileExists; |
28
|
|
|
use PHPUnit\Framework\Constraint\GreaterThan; |
29
|
|
|
use PHPUnit\Framework\Constraint\IsAnything; |
30
|
|
|
use PHPUnit\Framework\Constraint\IsEmpty; |
31
|
|
|
use PHPUnit\Framework\Constraint\IsEqual; |
32
|
|
|
use PHPUnit\Framework\Constraint\IsFalse; |
33
|
|
|
use PHPUnit\Framework\Constraint\IsFinite; |
34
|
|
|
use PHPUnit\Framework\Constraint\IsIdentical; |
35
|
|
|
use PHPUnit\Framework\Constraint\IsInfinite; |
36
|
|
|
use PHPUnit\Framework\Constraint\IsInstanceOf; |
37
|
|
|
use PHPUnit\Framework\Constraint\IsJson; |
38
|
|
|
use PHPUnit\Framework\Constraint\IsNan; |
39
|
|
|
use PHPUnit\Framework\Constraint\IsNull; |
40
|
|
|
use PHPUnit\Framework\Constraint\IsReadable; |
41
|
|
|
use PHPUnit\Framework\Constraint\IsTrue; |
42
|
|
|
use PHPUnit\Framework\Constraint\IsType; |
43
|
|
|
use PHPUnit\Framework\Constraint\IsWritable; |
44
|
|
|
use PHPUnit\Framework\Constraint\JsonMatches; |
45
|
|
|
use PHPUnit\Framework\Constraint\LessThan; |
46
|
|
|
use PHPUnit\Framework\Constraint\LogicalAnd; |
47
|
|
|
use PHPUnit\Framework\Constraint\LogicalNot; |
48
|
|
|
use PHPUnit\Framework\Constraint\LogicalOr; |
49
|
|
|
use PHPUnit\Framework\Constraint\LogicalXor; |
50
|
|
|
use PHPUnit\Framework\Constraint\ObjectHasAttribute; |
51
|
|
|
use PHPUnit\Framework\Constraint\RegularExpression; |
52
|
|
|
use PHPUnit\Framework\Constraint\SameSize; |
53
|
|
|
use PHPUnit\Framework\Constraint\StringContains; |
54
|
|
|
use PHPUnit\Framework\Constraint\StringEndsWith; |
55
|
|
|
use PHPUnit\Framework\Constraint\StringMatchesFormatDescription; |
56
|
|
|
use PHPUnit\Framework\Constraint\StringStartsWith; |
57
|
|
|
use PHPUnit\Framework\Constraint\TraversableContains; |
58
|
|
|
use PHPUnit\Framework\Constraint\TraversableContainsOnly; |
59
|
|
|
use PHPUnit\Util\InvalidArgumentHelper; |
60
|
|
|
use PHPUnit\Util\Type; |
61
|
|
|
use PHPUnit\Util\Xml; |
62
|
|
|
use ReflectionClass; |
63
|
|
|
use ReflectionException; |
64
|
|
|
use ReflectionObject; |
65
|
|
|
use Traversable; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* A set of assertion methods. |
69
|
|
|
*/ |
70
|
|
|
abstract class Assert |
71
|
|
|
{ |
72
|
|
|
/** |
73
|
|
|
* @var int |
74
|
|
|
*/ |
75
|
|
|
private static $count = 0; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Asserts that an array has a specified key. |
79
|
|
|
* |
80
|
|
|
* @param int|string $key |
81
|
|
|
* @param array|ArrayAccess $array |
82
|
|
|
* |
83
|
|
|
* @throws ExpectationFailedException |
84
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
85
|
|
|
* @throws Exception |
86
|
|
|
*/ |
87
|
|
|
public static function assertArrayHasKey($key, $array, string $message = ''): void |
88
|
|
|
{ |
89
|
|
|
if (!(\is_int($key) || \is_string($key))) { |
90
|
|
|
throw InvalidArgumentHelper::factory( |
91
|
|
|
1, |
92
|
|
|
'integer or string' |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if (!(\is_array($array) || $array instanceof ArrayAccess)) { |
97
|
|
|
throw InvalidArgumentHelper::factory( |
98
|
|
|
2, |
99
|
|
|
'array or ArrayAccess' |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$constraint = new ArrayHasKey($key); |
104
|
|
|
|
105
|
|
|
static::assertThat($array, $constraint, $message); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Asserts that an array has a specified subset. |
110
|
|
|
* |
111
|
|
|
* @param array|ArrayAccess $subset |
112
|
|
|
* @param array|ArrayAccess $array |
113
|
|
|
* |
114
|
|
|
* @throws ExpectationFailedException |
115
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
116
|
|
|
* @throws Exception |
117
|
|
|
* |
118
|
|
|
* @codeCoverageIgnore |
119
|
|
|
* |
120
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3494 |
121
|
|
|
*/ |
122
|
|
|
public static function assertArraySubset($subset, $array, bool $checkForObjectIdentity = false, string $message = ''): void |
123
|
|
|
{ |
124
|
|
|
self::createWarning('assertArraySubset() is deprecated and will be removed in PHPUnit 9.'); |
125
|
|
|
|
126
|
|
|
if (!(\is_array($subset) || $subset instanceof ArrayAccess)) { |
127
|
|
|
throw InvalidArgumentHelper::factory( |
128
|
|
|
1, |
129
|
|
|
'array or ArrayAccess' |
130
|
|
|
); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
if (!(\is_array($array) || $array instanceof ArrayAccess)) { |
134
|
|
|
throw InvalidArgumentHelper::factory( |
135
|
|
|
2, |
136
|
|
|
'array or ArrayAccess' |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$constraint = new ArraySubset($subset, $checkForObjectIdentity); |
141
|
|
|
|
142
|
|
|
static::assertThat($array, $constraint, $message); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Asserts that an array does not have a specified key. |
147
|
|
|
* |
148
|
|
|
* @param int|string $key |
149
|
|
|
* @param array|ArrayAccess $array |
150
|
|
|
* |
151
|
|
|
* @throws ExpectationFailedException |
152
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
153
|
|
|
* @throws Exception |
154
|
|
|
*/ |
155
|
|
|
public static function assertArrayNotHasKey($key, $array, string $message = ''): void |
156
|
|
|
{ |
157
|
|
|
if (!(\is_int($key) || \is_string($key))) { |
158
|
|
|
throw InvalidArgumentHelper::factory( |
159
|
|
|
1, |
160
|
|
|
'integer or string' |
161
|
|
|
); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
if (!(\is_array($array) || $array instanceof ArrayAccess)) { |
165
|
|
|
throw InvalidArgumentHelper::factory( |
166
|
|
|
2, |
167
|
|
|
'array or ArrayAccess' |
168
|
|
|
); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$constraint = new LogicalNot( |
172
|
|
|
new ArrayHasKey($key) |
173
|
|
|
); |
174
|
|
|
|
175
|
|
|
static::assertThat($array, $constraint, $message); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Asserts that a haystack contains a needle. |
180
|
|
|
* |
181
|
|
|
* @throws ExpectationFailedException |
182
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
183
|
|
|
* @throws Exception |
184
|
|
|
*/ |
185
|
|
|
public static function assertContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void |
186
|
|
|
{ |
187
|
|
|
// @codeCoverageIgnoreStart |
188
|
|
|
if (\is_string($haystack)) { |
189
|
|
|
self::createWarning('Using assertContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringContainsString() or assertStringContainsStringIgnoringCase() instead.'); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if (!$checkForObjectIdentity) { |
193
|
|
|
self::createWarning('The optional $checkForObjectIdentity parameter of assertContains() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertContainsEquals() instead.'); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
if ($checkForNonObjectIdentity) { |
197
|
|
|
self::createWarning('The optional $checkForNonObjectIdentity parameter of assertContains() is deprecated and will be removed in PHPUnit 9.'); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
if ($ignoreCase) { |
201
|
|
|
self::createWarning('The optional $ignoreCase parameter of assertContains() is deprecated and will be removed in PHPUnit 9.'); |
202
|
|
|
} |
203
|
|
|
// @codeCoverageIgnoreEnd |
204
|
|
|
|
205
|
|
|
if (\is_array($haystack) || |
206
|
|
|
(\is_object($haystack) && $haystack instanceof Traversable)) { |
207
|
|
|
$constraint = new TraversableContains( |
208
|
|
|
$needle, |
209
|
|
|
$checkForObjectIdentity, |
210
|
|
|
$checkForNonObjectIdentity |
211
|
|
|
); |
212
|
|
|
} elseif (\is_string($haystack)) { |
213
|
|
|
if (!\is_string($needle)) { |
214
|
|
|
throw InvalidArgumentHelper::factory( |
215
|
|
|
1, |
216
|
|
|
'string' |
217
|
|
|
); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
$constraint = new StringContains( |
221
|
|
|
$needle, |
222
|
|
|
$ignoreCase |
223
|
|
|
); |
224
|
|
|
} else { |
225
|
|
|
throw InvalidArgumentHelper::factory( |
226
|
|
|
2, |
227
|
|
|
'array, traversable or string' |
228
|
|
|
); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
static::assertThat($haystack, $constraint, $message); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public static function assertContainsEquals($needle, iterable $haystack, string $message = ''): void |
235
|
|
|
{ |
236
|
|
|
$constraint = new TraversableContains($needle, false, false); |
237
|
|
|
|
238
|
|
|
static::assertThat($haystack, $constraint, $message); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Asserts that a haystack that is stored in a static attribute of a class |
243
|
|
|
* or an attribute of an object contains a needle. |
244
|
|
|
* |
245
|
|
|
* @param object|string $haystackClassOrObject |
246
|
|
|
* |
247
|
|
|
* @throws ExpectationFailedException |
248
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
249
|
|
|
* @throws ReflectionException |
250
|
|
|
* @throws Exception |
251
|
|
|
* |
252
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
253
|
|
|
* @codeCoverageIgnore |
254
|
|
|
*/ |
255
|
|
|
public static function assertAttributeContains($needle, string $haystackAttributeName, $haystackClassOrObject, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void |
256
|
|
|
{ |
257
|
|
|
self::createWarning('assertAttributeContains() is deprecated and will be removed in PHPUnit 9.'); |
258
|
|
|
|
259
|
|
|
static::assertContains( |
260
|
|
|
$needle, |
261
|
|
|
static::readAttribute($haystackClassOrObject, $haystackAttributeName), |
262
|
|
|
$message, |
263
|
|
|
$ignoreCase, |
264
|
|
|
$checkForObjectIdentity, |
265
|
|
|
$checkForNonObjectIdentity |
266
|
|
|
); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Asserts that a haystack does not contain a needle. |
271
|
|
|
* |
272
|
|
|
* @throws ExpectationFailedException |
273
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
274
|
|
|
* @throws Exception |
275
|
|
|
*/ |
276
|
|
|
public static function assertNotContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void |
277
|
|
|
{ |
278
|
|
|
// @codeCoverageIgnoreStart |
279
|
|
|
if (\is_string($haystack)) { |
280
|
|
|
self::createWarning('Using assertNotContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringNotContainsString() or assertStringNotContainsStringIgnoringCase() instead.'); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
if (!$checkForObjectIdentity) { |
284
|
|
|
self::createWarning('The optional $checkForObjectIdentity parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertNotContainsEquals() instead.'); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
if ($checkForNonObjectIdentity) { |
288
|
|
|
self::createWarning('The optional $checkForNonObjectIdentity parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9.'); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
if ($ignoreCase) { |
292
|
|
|
self::createWarning('The optional $ignoreCase parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9.'); |
293
|
|
|
} |
294
|
|
|
// @codeCoverageIgnoreEnd |
295
|
|
|
|
296
|
|
|
if (\is_array($haystack) || |
297
|
|
|
(\is_object($haystack) && $haystack instanceof Traversable)) { |
298
|
|
|
$constraint = new LogicalNot( |
299
|
|
|
new TraversableContains( |
300
|
|
|
$needle, |
301
|
|
|
$checkForObjectIdentity, |
302
|
|
|
$checkForNonObjectIdentity |
303
|
|
|
) |
304
|
|
|
); |
305
|
|
|
} elseif (\is_string($haystack)) { |
306
|
|
|
if (!\is_string($needle)) { |
307
|
|
|
throw InvalidArgumentHelper::factory( |
308
|
|
|
1, |
309
|
|
|
'string' |
310
|
|
|
); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
$constraint = new LogicalNot( |
314
|
|
|
new StringContains( |
315
|
|
|
$needle, |
316
|
|
|
$ignoreCase |
317
|
|
|
) |
318
|
|
|
); |
319
|
|
|
} else { |
320
|
|
|
throw InvalidArgumentHelper::factory( |
321
|
|
|
2, |
322
|
|
|
'array, traversable or string' |
323
|
|
|
); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
static::assertThat($haystack, $constraint, $message); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
public static function assertNotContainsEquals($needle, iterable $haystack, string $message = ''): void |
330
|
|
|
{ |
331
|
|
|
$constraint = new LogicalNot(new TraversableContains($needle, false, false)); |
332
|
|
|
|
333
|
|
|
static::assertThat($haystack, $constraint, $message); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Asserts that a haystack that is stored in a static attribute of a class |
338
|
|
|
* or an attribute of an object does not contain a needle. |
339
|
|
|
* |
340
|
|
|
* @param object|string $haystackClassOrObject |
341
|
|
|
* |
342
|
|
|
* @throws ExpectationFailedException |
343
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
344
|
|
|
* @throws ReflectionException |
345
|
|
|
* @throws Exception |
346
|
|
|
* |
347
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
348
|
|
|
* @codeCoverageIgnore |
349
|
|
|
*/ |
350
|
|
|
public static function assertAttributeNotContains($needle, string $haystackAttributeName, $haystackClassOrObject, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void |
351
|
|
|
{ |
352
|
|
|
self::createWarning('assertAttributeNotContains() is deprecated and will be removed in PHPUnit 9.'); |
353
|
|
|
|
354
|
|
|
static::assertNotContains( |
355
|
|
|
$needle, |
356
|
|
|
static::readAttribute($haystackClassOrObject, $haystackAttributeName), |
357
|
|
|
$message, |
358
|
|
|
$ignoreCase, |
359
|
|
|
$checkForObjectIdentity, |
360
|
|
|
$checkForNonObjectIdentity |
361
|
|
|
); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* Asserts that a haystack contains only values of a given type. |
366
|
|
|
* |
367
|
|
|
* @throws ExpectationFailedException |
368
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
369
|
|
|
*/ |
370
|
|
|
public static function assertContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void |
371
|
|
|
{ |
372
|
|
|
if ($isNativeType === null) { |
373
|
|
|
$isNativeType = Type::isType($type); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
static::assertThat( |
377
|
|
|
$haystack, |
378
|
|
|
new TraversableContainsOnly( |
379
|
|
|
$type, |
380
|
|
|
$isNativeType |
381
|
|
|
), |
382
|
|
|
$message |
383
|
|
|
); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Asserts that a haystack contains only instances of a given class name. |
388
|
|
|
* |
389
|
|
|
* @throws ExpectationFailedException |
390
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
391
|
|
|
*/ |
392
|
|
|
public static function assertContainsOnlyInstancesOf(string $className, iterable $haystack, string $message = ''): void |
393
|
|
|
{ |
394
|
|
|
static::assertThat( |
395
|
|
|
$haystack, |
396
|
|
|
new TraversableContainsOnly( |
397
|
|
|
$className, |
398
|
|
|
false |
399
|
|
|
), |
400
|
|
|
$message |
401
|
|
|
); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* Asserts that a haystack that is stored in a static attribute of a class |
406
|
|
|
* or an attribute of an object contains only values of a given type. |
407
|
|
|
* |
408
|
|
|
* @param object|string $haystackClassOrObject |
409
|
|
|
* @param bool $isNativeType |
410
|
|
|
* |
411
|
|
|
* @throws ExpectationFailedException |
412
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
413
|
|
|
* @throws ReflectionException |
414
|
|
|
* @throws Exception |
415
|
|
|
* |
416
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
417
|
|
|
* @codeCoverageIgnore |
418
|
|
|
*/ |
419
|
|
|
public static function assertAttributeContainsOnly(string $type, string $haystackAttributeName, $haystackClassOrObject, ?bool $isNativeType = null, string $message = ''): void |
420
|
|
|
{ |
421
|
|
|
self::createWarning('assertAttributeContainsOnly() is deprecated and will be removed in PHPUnit 9.'); |
422
|
|
|
|
423
|
|
|
static::assertContainsOnly( |
424
|
|
|
$type, |
425
|
|
|
static::readAttribute($haystackClassOrObject, $haystackAttributeName), |
426
|
|
|
$isNativeType, |
427
|
|
|
$message |
428
|
|
|
); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Asserts that a haystack does not contain only values of a given type. |
433
|
|
|
* |
434
|
|
|
* @throws ExpectationFailedException |
435
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
436
|
|
|
*/ |
437
|
|
|
public static function assertNotContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void |
438
|
|
|
{ |
439
|
|
|
if ($isNativeType === null) { |
440
|
|
|
$isNativeType = Type::isType($type); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
static::assertThat( |
444
|
|
|
$haystack, |
445
|
|
|
new LogicalNot( |
446
|
|
|
new TraversableContainsOnly( |
447
|
|
|
$type, |
448
|
|
|
$isNativeType |
449
|
|
|
) |
450
|
|
|
), |
451
|
|
|
$message |
452
|
|
|
); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* Asserts that a haystack that is stored in a static attribute of a class |
457
|
|
|
* or an attribute of an object does not contain only values of a given |
458
|
|
|
* type. |
459
|
|
|
* |
460
|
|
|
* @param object|string $haystackClassOrObject |
461
|
|
|
* @param bool $isNativeType |
462
|
|
|
* |
463
|
|
|
* @throws ExpectationFailedException |
464
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
465
|
|
|
* @throws ReflectionException |
466
|
|
|
* @throws Exception |
467
|
|
|
* |
468
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
469
|
|
|
* @codeCoverageIgnore |
470
|
|
|
*/ |
471
|
|
|
public static function assertAttributeNotContainsOnly(string $type, string $haystackAttributeName, $haystackClassOrObject, ?bool $isNativeType = null, string $message = ''): void |
472
|
|
|
{ |
473
|
|
|
self::createWarning('assertAttributeNotContainsOnly() is deprecated and will be removed in PHPUnit 9.'); |
474
|
|
|
|
475
|
|
|
static::assertNotContainsOnly( |
476
|
|
|
$type, |
477
|
|
|
static::readAttribute($haystackClassOrObject, $haystackAttributeName), |
478
|
|
|
$isNativeType, |
479
|
|
|
$message |
480
|
|
|
); |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* Asserts the number of elements of an array, Countable or Traversable. |
485
|
|
|
* |
486
|
|
|
* @param Countable|iterable $haystack |
487
|
|
|
* |
488
|
|
|
* @throws ExpectationFailedException |
489
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
490
|
|
|
* @throws Exception |
491
|
|
|
*/ |
492
|
|
|
public static function assertCount(int $expectedCount, $haystack, string $message = ''): void |
493
|
|
|
{ |
494
|
|
|
if (!$haystack instanceof Countable && !\is_iterable($haystack)) { |
495
|
|
|
throw InvalidArgumentHelper::factory(2, 'countable or iterable'); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
static::assertThat( |
499
|
|
|
$haystack, |
500
|
|
|
new Count($expectedCount), |
501
|
|
|
$message |
502
|
|
|
); |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* Asserts the number of elements of an array, Countable or Traversable |
507
|
|
|
* that is stored in an attribute. |
508
|
|
|
* |
509
|
|
|
* @param object|string $haystackClassOrObject |
510
|
|
|
* |
511
|
|
|
* @throws ExpectationFailedException |
512
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
513
|
|
|
* @throws ReflectionException |
514
|
|
|
* @throws Exception |
515
|
|
|
* |
516
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
517
|
|
|
* @codeCoverageIgnore |
518
|
|
|
*/ |
519
|
|
|
public static function assertAttributeCount(int $expectedCount, string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void |
520
|
|
|
{ |
521
|
|
|
self::createWarning('assertAttributeCount() is deprecated and will be removed in PHPUnit 9.'); |
522
|
|
|
|
523
|
|
|
static::assertCount( |
524
|
|
|
$expectedCount, |
525
|
|
|
static::readAttribute($haystackClassOrObject, $haystackAttributeName), |
526
|
|
|
$message |
527
|
|
|
); |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
/** |
531
|
|
|
* Asserts the number of elements of an array, Countable or Traversable. |
532
|
|
|
* |
533
|
|
|
* @param Countable|iterable $haystack |
534
|
|
|
* |
535
|
|
|
* @throws ExpectationFailedException |
536
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
537
|
|
|
* @throws Exception |
538
|
|
|
*/ |
539
|
|
|
public static function assertNotCount(int $expectedCount, $haystack, string $message = ''): void |
540
|
|
|
{ |
541
|
|
|
if (!$haystack instanceof Countable && !\is_iterable($haystack)) { |
542
|
|
|
throw InvalidArgumentHelper::factory(2, 'countable or iterable'); |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
$constraint = new LogicalNot( |
546
|
|
|
new Count($expectedCount) |
547
|
|
|
); |
548
|
|
|
|
549
|
|
|
static::assertThat($haystack, $constraint, $message); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
/** |
553
|
|
|
* Asserts the number of elements of an array, Countable or Traversable |
554
|
|
|
* that is stored in an attribute. |
555
|
|
|
* |
556
|
|
|
* @param object|string $haystackClassOrObject |
557
|
|
|
* |
558
|
|
|
* @throws ExpectationFailedException |
559
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
560
|
|
|
* @throws ReflectionException |
561
|
|
|
* @throws Exception |
562
|
|
|
* |
563
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
564
|
|
|
* @codeCoverageIgnore |
565
|
|
|
*/ |
566
|
|
|
public static function assertAttributeNotCount(int $expectedCount, string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void |
567
|
|
|
{ |
568
|
|
|
self::createWarning('assertAttributeNotCount() is deprecated and will be removed in PHPUnit 9.'); |
569
|
|
|
|
570
|
|
|
static::assertNotCount( |
571
|
|
|
$expectedCount, |
572
|
|
|
static::readAttribute($haystackClassOrObject, $haystackAttributeName), |
573
|
|
|
$message |
574
|
|
|
); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
/** |
578
|
|
|
* Asserts that two variables are equal. |
579
|
|
|
* |
580
|
|
|
* @throws ExpectationFailedException |
581
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
582
|
|
|
*/ |
583
|
|
|
public static function assertEquals($expected, $actual, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): void |
584
|
|
|
{ |
585
|
|
|
// @codeCoverageIgnoreStart |
586
|
|
|
if ($delta !== 0.0) { |
587
|
|
|
self::createWarning('The optional $delta parameter of assertEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertEqualsWithDelta() instead.'); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
if ($maxDepth !== 10) { |
591
|
|
|
self::createWarning('The optional $maxDepth parameter of assertEquals() is deprecated and will be removed in PHPUnit 9.'); |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
if ($canonicalize) { |
595
|
|
|
self::createWarning('The optional $canonicalize parameter of assertEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertEqualsCanonicalizing() instead.'); |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
if ($ignoreCase) { |
599
|
|
|
self::createWarning('The optional $ignoreCase parameter of assertEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertEqualsIgnoringCase() instead.'); |
600
|
|
|
} |
601
|
|
|
// @codeCoverageIgnoreEnd |
602
|
|
|
|
603
|
|
|
$constraint = new IsEqual( |
604
|
|
|
$expected, |
605
|
|
|
$delta, |
606
|
|
|
$maxDepth, |
607
|
|
|
$canonicalize, |
608
|
|
|
$ignoreCase |
609
|
|
|
); |
610
|
|
|
|
611
|
|
|
static::assertThat($actual, $constraint, $message); |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
/** |
615
|
|
|
* Asserts that two variables are equal (canonicalizing). |
616
|
|
|
* |
617
|
|
|
* @throws ExpectationFailedException |
618
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
619
|
|
|
*/ |
620
|
|
|
public static function assertEqualsCanonicalizing($expected, $actual, string $message = ''): void |
621
|
|
|
{ |
622
|
|
|
$constraint = new IsEqual( |
623
|
|
|
$expected, |
624
|
|
|
0.0, |
625
|
|
|
10, |
626
|
|
|
true, |
627
|
|
|
false |
628
|
|
|
); |
629
|
|
|
|
630
|
|
|
static::assertThat($actual, $constraint, $message); |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
/** |
634
|
|
|
* Asserts that two variables are equal (ignoring case). |
635
|
|
|
* |
636
|
|
|
* @throws ExpectationFailedException |
637
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
638
|
|
|
*/ |
639
|
|
|
public static function assertEqualsIgnoringCase($expected, $actual, string $message = ''): void |
640
|
|
|
{ |
641
|
|
|
$constraint = new IsEqual( |
642
|
|
|
$expected, |
643
|
|
|
0.0, |
644
|
|
|
10, |
645
|
|
|
false, |
646
|
|
|
true |
647
|
|
|
); |
648
|
|
|
|
649
|
|
|
static::assertThat($actual, $constraint, $message); |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
/** |
653
|
|
|
* Asserts that two variables are equal (with delta). |
654
|
|
|
* |
655
|
|
|
* @throws ExpectationFailedException |
656
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
657
|
|
|
*/ |
658
|
|
|
public static function assertEqualsWithDelta($expected, $actual, float $delta, string $message = ''): void |
659
|
|
|
{ |
660
|
|
|
$constraint = new IsEqual( |
661
|
|
|
$expected, |
662
|
|
|
$delta |
663
|
|
|
); |
664
|
|
|
|
665
|
|
|
static::assertThat($actual, $constraint, $message); |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* Asserts that a variable is equal to an attribute of an object. |
670
|
|
|
* |
671
|
|
|
* @param object|string $actualClassOrObject |
672
|
|
|
* |
673
|
|
|
* @throws ExpectationFailedException |
674
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
675
|
|
|
* @throws ReflectionException |
676
|
|
|
* @throws Exception |
677
|
|
|
* |
678
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
679
|
|
|
* @codeCoverageIgnore |
680
|
|
|
*/ |
681
|
|
|
public static function assertAttributeEquals($expected, string $actualAttributeName, $actualClassOrObject, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): void |
682
|
|
|
{ |
683
|
|
|
self::createWarning('assertAttributeEquals() is deprecated and will be removed in PHPUnit 9.'); |
684
|
|
|
|
685
|
|
|
static::assertEquals( |
686
|
|
|
$expected, |
687
|
|
|
static::readAttribute($actualClassOrObject, $actualAttributeName), |
688
|
|
|
$message, |
689
|
|
|
$delta, |
690
|
|
|
$maxDepth, |
691
|
|
|
$canonicalize, |
692
|
|
|
$ignoreCase |
693
|
|
|
); |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
/** |
697
|
|
|
* Asserts that two variables are not equal. |
698
|
|
|
* |
699
|
|
|
* @param float $delta |
700
|
|
|
* @param int $maxDepth |
701
|
|
|
* @param bool $canonicalize |
702
|
|
|
* @param bool $ignoreCase |
703
|
|
|
* |
704
|
|
|
* @throws ExpectationFailedException |
705
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
706
|
|
|
*/ |
707
|
|
|
public static function assertNotEquals($expected, $actual, string $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false): void |
708
|
|
|
{ |
709
|
|
|
// @codeCoverageIgnoreStart |
710
|
|
|
if ($delta !== 0.0) { |
711
|
|
|
self::createWarning('The optional $delta parameter of assertNotEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertNotEqualsWithDelta() instead.'); |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
if ($maxDepth !== 10) { |
715
|
|
|
self::createWarning('The optional $maxDepth parameter of assertNotEquals() is deprecated and will be removed in PHPUnit 9.'); |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
if ($canonicalize) { |
719
|
|
|
self::createWarning('The optional $canonicalize parameter of assertNotEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertNotEqualsCanonicalizing() instead.'); |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
if ($ignoreCase) { |
723
|
|
|
self::createWarning('The optional $ignoreCase parameter of assertNotEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertNotEqualsIgnoringCase() instead.'); |
724
|
|
|
} |
725
|
|
|
// @codeCoverageIgnoreEnd |
726
|
|
|
|
727
|
|
|
$constraint = new LogicalNot( |
728
|
|
|
new IsEqual( |
729
|
|
|
$expected, |
730
|
|
|
$delta, |
731
|
|
|
$maxDepth, |
732
|
|
|
$canonicalize, |
733
|
|
|
$ignoreCase |
734
|
|
|
) |
735
|
|
|
); |
736
|
|
|
|
737
|
|
|
static::assertThat($actual, $constraint, $message); |
738
|
|
|
} |
739
|
|
|
|
740
|
|
|
/** |
741
|
|
|
* Asserts that two variables are not equal (canonicalizing). |
742
|
|
|
* |
743
|
|
|
* @throws ExpectationFailedException |
744
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
745
|
|
|
*/ |
746
|
|
|
public static function assertNotEqualsCanonicalizing($expected, $actual, string $message = ''): void |
747
|
|
|
{ |
748
|
|
|
$constraint = new LogicalNot( |
749
|
|
|
new IsEqual( |
750
|
|
|
$expected, |
751
|
|
|
0.0, |
752
|
|
|
10, |
753
|
|
|
true, |
754
|
|
|
false |
755
|
|
|
) |
756
|
|
|
); |
757
|
|
|
|
758
|
|
|
static::assertThat($actual, $constraint, $message); |
759
|
|
|
} |
760
|
|
|
|
761
|
|
|
/** |
762
|
|
|
* Asserts that two variables are not equal (ignoring case). |
763
|
|
|
* |
764
|
|
|
* @throws ExpectationFailedException |
765
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
766
|
|
|
*/ |
767
|
|
|
public static function assertNotEqualsIgnoringCase($expected, $actual, string $message = ''): void |
768
|
|
|
{ |
769
|
|
|
$constraint = new LogicalNot( |
770
|
|
|
new IsEqual( |
771
|
|
|
$expected, |
772
|
|
|
0.0, |
773
|
|
|
10, |
774
|
|
|
false, |
775
|
|
|
true |
776
|
|
|
) |
777
|
|
|
); |
778
|
|
|
|
779
|
|
|
static::assertThat($actual, $constraint, $message); |
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
/** |
783
|
|
|
* Asserts that two variables are not equal (with delta). |
784
|
|
|
* |
785
|
|
|
* @throws ExpectationFailedException |
786
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
787
|
|
|
*/ |
788
|
|
|
public static function assertNotEqualsWithDelta($expected, $actual, float $delta, string $message = ''): void |
789
|
|
|
{ |
790
|
|
|
$constraint = new LogicalNot( |
791
|
|
|
new IsEqual( |
792
|
|
|
$expected, |
793
|
|
|
$delta |
794
|
|
|
) |
795
|
|
|
); |
796
|
|
|
|
797
|
|
|
static::assertThat($actual, $constraint, $message); |
798
|
|
|
} |
799
|
|
|
|
800
|
|
|
/** |
801
|
|
|
* Asserts that a variable is not equal to an attribute of an object. |
802
|
|
|
* |
803
|
|
|
* @param object|string $actualClassOrObject |
804
|
|
|
* |
805
|
|
|
* @throws ExpectationFailedException |
806
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
807
|
|
|
* @throws ReflectionException |
808
|
|
|
* @throws Exception |
809
|
|
|
* |
810
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
811
|
|
|
* @codeCoverageIgnore |
812
|
|
|
*/ |
813
|
|
|
public static function assertAttributeNotEquals($expected, string $actualAttributeName, $actualClassOrObject, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): void |
814
|
|
|
{ |
815
|
|
|
self::createWarning('assertAttributeNotEquals() is deprecated and will be removed in PHPUnit 9.'); |
816
|
|
|
|
817
|
|
|
static::assertNotEquals( |
818
|
|
|
$expected, |
819
|
|
|
static::readAttribute($actualClassOrObject, $actualAttributeName), |
820
|
|
|
$message, |
821
|
|
|
$delta, |
822
|
|
|
$maxDepth, |
823
|
|
|
$canonicalize, |
824
|
|
|
$ignoreCase |
825
|
|
|
); |
826
|
|
|
} |
827
|
|
|
|
828
|
|
|
/** |
829
|
|
|
* Asserts that a variable is empty. |
830
|
|
|
* |
831
|
|
|
* @throws ExpectationFailedException |
832
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
833
|
|
|
*/ |
834
|
|
|
public static function assertEmpty($actual, string $message = ''): void |
835
|
|
|
{ |
836
|
|
|
static::assertThat($actual, static::isEmpty(), $message); |
837
|
|
|
} |
838
|
|
|
|
839
|
|
|
/** |
840
|
|
|
* Asserts that a static attribute of a class or an attribute of an object |
841
|
|
|
* is empty. |
842
|
|
|
* |
843
|
|
|
* @param object|string $haystackClassOrObject |
844
|
|
|
* |
845
|
|
|
* @throws ExpectationFailedException |
846
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
847
|
|
|
* @throws ReflectionException |
848
|
|
|
* @throws Exception |
849
|
|
|
* |
850
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
851
|
|
|
* @codeCoverageIgnore |
852
|
|
|
*/ |
853
|
|
|
public static function assertAttributeEmpty(string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void |
854
|
|
|
{ |
855
|
|
|
self::createWarning('assertAttributeEmpty() is deprecated and will be removed in PHPUnit 9.'); |
856
|
|
|
|
857
|
|
|
static::assertEmpty( |
858
|
|
|
static::readAttribute($haystackClassOrObject, $haystackAttributeName), |
859
|
|
|
$message |
860
|
|
|
); |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
/** |
864
|
|
|
* Asserts that a variable is not empty. |
865
|
|
|
* |
866
|
|
|
* @throws ExpectationFailedException |
867
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
868
|
|
|
*/ |
869
|
|
|
public static function assertNotEmpty($actual, string $message = ''): void |
870
|
|
|
{ |
871
|
|
|
static::assertThat($actual, static::logicalNot(static::isEmpty()), $message); |
872
|
|
|
} |
873
|
|
|
|
874
|
|
|
/** |
875
|
|
|
* Asserts that a static attribute of a class or an attribute of an object |
876
|
|
|
* is not empty. |
877
|
|
|
* |
878
|
|
|
* @param object|string $haystackClassOrObject |
879
|
|
|
* |
880
|
|
|
* @throws ExpectationFailedException |
881
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
882
|
|
|
* @throws ReflectionException |
883
|
|
|
* @throws Exception |
884
|
|
|
* |
885
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
886
|
|
|
* @codeCoverageIgnore |
887
|
|
|
*/ |
888
|
|
|
public static function assertAttributeNotEmpty(string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void |
889
|
|
|
{ |
890
|
|
|
self::createWarning('assertAttributeNotEmpty() is deprecated and will be removed in PHPUnit 9.'); |
891
|
|
|
|
892
|
|
|
static::assertNotEmpty( |
893
|
|
|
static::readAttribute($haystackClassOrObject, $haystackAttributeName), |
894
|
|
|
$message |
895
|
|
|
); |
896
|
|
|
} |
897
|
|
|
|
898
|
|
|
/** |
899
|
|
|
* Asserts that a value is greater than another value. |
900
|
|
|
* |
901
|
|
|
* @throws ExpectationFailedException |
902
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
903
|
|
|
*/ |
904
|
|
|
public static function assertGreaterThan($expected, $actual, string $message = ''): void |
905
|
|
|
{ |
906
|
|
|
static::assertThat($actual, static::greaterThan($expected), $message); |
907
|
|
|
} |
908
|
|
|
|
909
|
|
|
/** |
910
|
|
|
* Asserts that an attribute is greater than another value. |
911
|
|
|
* |
912
|
|
|
* @param object|string $actualClassOrObject |
913
|
|
|
* |
914
|
|
|
* @throws ExpectationFailedException |
915
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
916
|
|
|
* @throws ReflectionException |
917
|
|
|
* @throws Exception |
918
|
|
|
* |
919
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
920
|
|
|
* @codeCoverageIgnore |
921
|
|
|
*/ |
922
|
|
|
public static function assertAttributeGreaterThan($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void |
923
|
|
|
{ |
924
|
|
|
self::createWarning('assertAttributeGreaterThan() is deprecated and will be removed in PHPUnit 9.'); |
925
|
|
|
|
926
|
|
|
static::assertGreaterThan( |
927
|
|
|
$expected, |
928
|
|
|
static::readAttribute($actualClassOrObject, $actualAttributeName), |
929
|
|
|
$message |
930
|
|
|
); |
931
|
|
|
} |
932
|
|
|
|
933
|
|
|
/** |
934
|
|
|
* Asserts that a value is greater than or equal to another value. |
935
|
|
|
* |
936
|
|
|
* @throws ExpectationFailedException |
937
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
938
|
|
|
*/ |
939
|
|
|
public static function assertGreaterThanOrEqual($expected, $actual, string $message = ''): void |
940
|
|
|
{ |
941
|
|
|
static::assertThat( |
942
|
|
|
$actual, |
943
|
|
|
static::greaterThanOrEqual($expected), |
944
|
|
|
$message |
945
|
|
|
); |
946
|
|
|
} |
947
|
|
|
|
948
|
|
|
/** |
949
|
|
|
* Asserts that an attribute is greater than or equal to another value. |
950
|
|
|
* |
951
|
|
|
* @param object|string $actualClassOrObject |
952
|
|
|
* |
953
|
|
|
* @throws ExpectationFailedException |
954
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
955
|
|
|
* @throws ReflectionException |
956
|
|
|
* @throws Exception |
957
|
|
|
* |
958
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
959
|
|
|
* @codeCoverageIgnore |
960
|
|
|
*/ |
961
|
|
|
public static function assertAttributeGreaterThanOrEqual($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void |
962
|
|
|
{ |
963
|
|
|
self::createWarning('assertAttributeGreaterThanOrEqual() is deprecated and will be removed in PHPUnit 9.'); |
964
|
|
|
|
965
|
|
|
static::assertGreaterThanOrEqual( |
966
|
|
|
$expected, |
967
|
|
|
static::readAttribute($actualClassOrObject, $actualAttributeName), |
968
|
|
|
$message |
969
|
|
|
); |
970
|
|
|
} |
971
|
|
|
|
972
|
|
|
/** |
973
|
|
|
* Asserts that a value is smaller than another value. |
974
|
|
|
* |
975
|
|
|
* @throws ExpectationFailedException |
976
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
977
|
|
|
*/ |
978
|
|
|
public static function assertLessThan($expected, $actual, string $message = ''): void |
979
|
|
|
{ |
980
|
|
|
static::assertThat($actual, static::lessThan($expected), $message); |
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
/** |
984
|
|
|
* Asserts that an attribute is smaller than another value. |
985
|
|
|
* |
986
|
|
|
* @param object|string $actualClassOrObject |
987
|
|
|
* |
988
|
|
|
* @throws ExpectationFailedException |
989
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
990
|
|
|
* @throws ReflectionException |
991
|
|
|
* @throws Exception |
992
|
|
|
* |
993
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
994
|
|
|
* @codeCoverageIgnore |
995
|
|
|
*/ |
996
|
|
|
public static function assertAttributeLessThan($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void |
997
|
|
|
{ |
998
|
|
|
self::createWarning('assertAttributeLessThan() is deprecated and will be removed in PHPUnit 9.'); |
999
|
|
|
|
1000
|
|
|
static::assertLessThan( |
1001
|
|
|
$expected, |
1002
|
|
|
static::readAttribute($actualClassOrObject, $actualAttributeName), |
1003
|
|
|
$message |
1004
|
|
|
); |
1005
|
|
|
} |
1006
|
|
|
|
1007
|
|
|
/** |
1008
|
|
|
* Asserts that a value is smaller than or equal to another value. |
1009
|
|
|
* |
1010
|
|
|
* @throws ExpectationFailedException |
1011
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1012
|
|
|
*/ |
1013
|
|
|
public static function assertLessThanOrEqual($expected, $actual, string $message = ''): void |
1014
|
|
|
{ |
1015
|
|
|
static::assertThat($actual, static::lessThanOrEqual($expected), $message); |
1016
|
|
|
} |
1017
|
|
|
|
1018
|
|
|
/** |
1019
|
|
|
* Asserts that an attribute is smaller than or equal to another value. |
1020
|
|
|
* |
1021
|
|
|
* @param object|string $actualClassOrObject |
1022
|
|
|
* |
1023
|
|
|
* @throws ExpectationFailedException |
1024
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1025
|
|
|
* @throws ReflectionException |
1026
|
|
|
* @throws Exception |
1027
|
|
|
* |
1028
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
1029
|
|
|
* @codeCoverageIgnore |
1030
|
|
|
*/ |
1031
|
|
|
public static function assertAttributeLessThanOrEqual($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void |
1032
|
|
|
{ |
1033
|
|
|
self::createWarning('assertAttributeLessThanOrEqual() is deprecated and will be removed in PHPUnit 9.'); |
1034
|
|
|
|
1035
|
|
|
static::assertLessThanOrEqual( |
1036
|
|
|
$expected, |
1037
|
|
|
static::readAttribute($actualClassOrObject, $actualAttributeName), |
1038
|
|
|
$message |
1039
|
|
|
); |
1040
|
|
|
} |
1041
|
|
|
|
1042
|
|
|
/** |
1043
|
|
|
* Asserts that the contents of one file is equal to the contents of another |
1044
|
|
|
* file. |
1045
|
|
|
* |
1046
|
|
|
* @throws ExpectationFailedException |
1047
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1048
|
|
|
*/ |
1049
|
|
|
public static function assertFileEquals(string $expected, string $actual, string $message = '', bool $canonicalize = false, bool $ignoreCase = false): void |
1050
|
|
|
{ |
1051
|
|
|
static::assertFileExists($expected, $message); |
1052
|
|
|
static::assertFileExists($actual, $message); |
1053
|
|
|
|
1054
|
|
|
$constraint = new IsEqual( |
1055
|
|
|
\file_get_contents($expected), |
1056
|
|
|
0.0, |
1057
|
|
|
10, |
1058
|
|
|
$canonicalize, |
1059
|
|
|
$ignoreCase |
1060
|
|
|
); |
1061
|
|
|
|
1062
|
|
|
static::assertThat(\file_get_contents($actual), $constraint, $message); |
1063
|
|
|
} |
1064
|
|
|
|
1065
|
|
|
/** |
1066
|
|
|
* Asserts that the contents of one file is not equal to the contents of |
1067
|
|
|
* another file. |
1068
|
|
|
* |
1069
|
|
|
* @throws ExpectationFailedException |
1070
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1071
|
|
|
*/ |
1072
|
|
|
public static function assertFileNotEquals(string $expected, string $actual, string $message = '', bool $canonicalize = false, bool $ignoreCase = false): void |
1073
|
|
|
{ |
1074
|
|
|
static::assertFileExists($expected, $message); |
1075
|
|
|
static::assertFileExists($actual, $message); |
1076
|
|
|
|
1077
|
|
|
$constraint = new LogicalNot( |
1078
|
|
|
new IsEqual( |
1079
|
|
|
\file_get_contents($expected), |
1080
|
|
|
0.0, |
1081
|
|
|
10, |
1082
|
|
|
$canonicalize, |
1083
|
|
|
$ignoreCase |
1084
|
|
|
) |
1085
|
|
|
); |
1086
|
|
|
|
1087
|
|
|
static::assertThat(\file_get_contents($actual), $constraint, $message); |
1088
|
|
|
} |
1089
|
|
|
|
1090
|
|
|
/** |
1091
|
|
|
* Asserts that the contents of a string is equal |
1092
|
|
|
* to the contents of a file. |
1093
|
|
|
* |
1094
|
|
|
* @throws ExpectationFailedException |
1095
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1096
|
|
|
*/ |
1097
|
|
|
public static function assertStringEqualsFile(string $expectedFile, string $actualString, string $message = '', bool $canonicalize = false, bool $ignoreCase = false): void |
1098
|
|
|
{ |
1099
|
|
|
static::assertFileExists($expectedFile, $message); |
1100
|
|
|
|
1101
|
|
|
$constraint = new IsEqual( |
1102
|
|
|
\file_get_contents($expectedFile), |
1103
|
|
|
0.0, |
1104
|
|
|
10, |
1105
|
|
|
$canonicalize, |
1106
|
|
|
$ignoreCase |
1107
|
|
|
); |
1108
|
|
|
|
1109
|
|
|
static::assertThat($actualString, $constraint, $message); |
1110
|
|
|
} |
1111
|
|
|
|
1112
|
|
|
/** |
1113
|
|
|
* Asserts that the contents of a string is not equal |
1114
|
|
|
* to the contents of a file. |
1115
|
|
|
* |
1116
|
|
|
* @throws ExpectationFailedException |
1117
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1118
|
|
|
*/ |
1119
|
|
|
public static function assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = '', bool $canonicalize = false, bool $ignoreCase = false): void |
1120
|
|
|
{ |
1121
|
|
|
static::assertFileExists($expectedFile, $message); |
1122
|
|
|
|
1123
|
|
|
$constraint = new LogicalNot( |
1124
|
|
|
new IsEqual( |
1125
|
|
|
\file_get_contents($expectedFile), |
1126
|
|
|
0.0, |
1127
|
|
|
10, |
1128
|
|
|
$canonicalize, |
1129
|
|
|
$ignoreCase |
1130
|
|
|
) |
1131
|
|
|
); |
1132
|
|
|
|
1133
|
|
|
static::assertThat($actualString, $constraint, $message); |
1134
|
|
|
} |
1135
|
|
|
|
1136
|
|
|
/** |
1137
|
|
|
* Asserts that a file/dir is readable. |
1138
|
|
|
* |
1139
|
|
|
* @throws ExpectationFailedException |
1140
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1141
|
|
|
*/ |
1142
|
|
|
public static function assertIsReadable(string $filename, string $message = ''): void |
1143
|
|
|
{ |
1144
|
|
|
static::assertThat($filename, new IsReadable, $message); |
1145
|
|
|
} |
1146
|
|
|
|
1147
|
|
|
/** |
1148
|
|
|
* Asserts that a file/dir exists and is not readable. |
1149
|
|
|
* |
1150
|
|
|
* @throws ExpectationFailedException |
1151
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1152
|
|
|
*/ |
1153
|
|
|
public static function assertNotIsReadable(string $filename, string $message = ''): void |
1154
|
|
|
{ |
1155
|
|
|
static::assertThat($filename, new LogicalNot(new IsReadable), $message); |
1156
|
|
|
} |
1157
|
|
|
|
1158
|
|
|
/** |
1159
|
|
|
* Asserts that a file/dir exists and is writable. |
1160
|
|
|
* |
1161
|
|
|
* @throws ExpectationFailedException |
1162
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1163
|
|
|
*/ |
1164
|
|
|
public static function assertIsWritable(string $filename, string $message = ''): void |
1165
|
|
|
{ |
1166
|
|
|
static::assertThat($filename, new IsWritable, $message); |
1167
|
|
|
} |
1168
|
|
|
|
1169
|
|
|
/** |
1170
|
|
|
* Asserts that a file/dir exists and is not writable. |
1171
|
|
|
* |
1172
|
|
|
* @throws ExpectationFailedException |
1173
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1174
|
|
|
*/ |
1175
|
|
|
public static function assertNotIsWritable(string $filename, string $message = ''): void |
1176
|
|
|
{ |
1177
|
|
|
static::assertThat($filename, new LogicalNot(new IsWritable), $message); |
1178
|
|
|
} |
1179
|
|
|
|
1180
|
|
|
/** |
1181
|
|
|
* Asserts that a directory exists. |
1182
|
|
|
* |
1183
|
|
|
* @throws ExpectationFailedException |
1184
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1185
|
|
|
*/ |
1186
|
|
|
public static function assertDirectoryExists(string $directory, string $message = ''): void |
1187
|
|
|
{ |
1188
|
|
|
static::assertThat($directory, new DirectoryExists, $message); |
1189
|
|
|
} |
1190
|
|
|
|
1191
|
|
|
/** |
1192
|
|
|
* Asserts that a directory does not exist. |
1193
|
|
|
* |
1194
|
|
|
* @throws ExpectationFailedException |
1195
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1196
|
|
|
*/ |
1197
|
|
|
public static function assertDirectoryNotExists(string $directory, string $message = ''): void |
1198
|
|
|
{ |
1199
|
|
|
static::assertThat($directory, new LogicalNot(new DirectoryExists), $message); |
1200
|
|
|
} |
1201
|
|
|
|
1202
|
|
|
/** |
1203
|
|
|
* Asserts that a directory exists and is readable. |
1204
|
|
|
* |
1205
|
|
|
* @throws ExpectationFailedException |
1206
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1207
|
|
|
*/ |
1208
|
|
|
public static function assertDirectoryIsReadable(string $directory, string $message = ''): void |
1209
|
|
|
{ |
1210
|
|
|
self::assertDirectoryExists($directory, $message); |
1211
|
|
|
self::assertIsReadable($directory, $message); |
1212
|
|
|
} |
1213
|
|
|
|
1214
|
|
|
/** |
1215
|
|
|
* Asserts that a directory exists and is not readable. |
1216
|
|
|
* |
1217
|
|
|
* @throws ExpectationFailedException |
1218
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1219
|
|
|
*/ |
1220
|
|
|
public static function assertDirectoryNotIsReadable(string $directory, string $message = ''): void |
1221
|
|
|
{ |
1222
|
|
|
self::assertDirectoryExists($directory, $message); |
1223
|
|
|
self::assertNotIsReadable($directory, $message); |
1224
|
|
|
} |
1225
|
|
|
|
1226
|
|
|
/** |
1227
|
|
|
* Asserts that a directory exists and is writable. |
1228
|
|
|
* |
1229
|
|
|
* @throws ExpectationFailedException |
1230
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1231
|
|
|
*/ |
1232
|
|
|
public static function assertDirectoryIsWritable(string $directory, string $message = ''): void |
1233
|
|
|
{ |
1234
|
|
|
self::assertDirectoryExists($directory, $message); |
1235
|
|
|
self::assertIsWritable($directory, $message); |
1236
|
|
|
} |
1237
|
|
|
|
1238
|
|
|
/** |
1239
|
|
|
* Asserts that a directory exists and is not writable. |
1240
|
|
|
* |
1241
|
|
|
* @throws ExpectationFailedException |
1242
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1243
|
|
|
*/ |
1244
|
|
|
public static function assertDirectoryNotIsWritable(string $directory, string $message = ''): void |
1245
|
|
|
{ |
1246
|
|
|
self::assertDirectoryExists($directory, $message); |
1247
|
|
|
self::assertNotIsWritable($directory, $message); |
1248
|
|
|
} |
1249
|
|
|
|
1250
|
|
|
/** |
1251
|
|
|
* Asserts that a file exists. |
1252
|
|
|
* |
1253
|
|
|
* @throws ExpectationFailedException |
1254
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1255
|
|
|
*/ |
1256
|
|
|
public static function assertFileExists(string $filename, string $message = ''): void |
1257
|
|
|
{ |
1258
|
|
|
static::assertThat($filename, new FileExists, $message); |
1259
|
|
|
} |
1260
|
|
|
|
1261
|
|
|
/** |
1262
|
|
|
* Asserts that a file does not exist. |
1263
|
|
|
* |
1264
|
|
|
* @throws ExpectationFailedException |
1265
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1266
|
|
|
*/ |
1267
|
|
|
public static function assertFileNotExists(string $filename, string $message = ''): void |
1268
|
|
|
{ |
1269
|
|
|
static::assertThat($filename, new LogicalNot(new FileExists), $message); |
1270
|
|
|
} |
1271
|
|
|
|
1272
|
|
|
/** |
1273
|
|
|
* Asserts that a file exists and is readable. |
1274
|
|
|
* |
1275
|
|
|
* @throws ExpectationFailedException |
1276
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1277
|
|
|
*/ |
1278
|
|
|
public static function assertFileIsReadable(string $file, string $message = ''): void |
1279
|
|
|
{ |
1280
|
|
|
self::assertFileExists($file, $message); |
1281
|
|
|
self::assertIsReadable($file, $message); |
1282
|
|
|
} |
1283
|
|
|
|
1284
|
|
|
/** |
1285
|
|
|
* Asserts that a file exists and is not readable. |
1286
|
|
|
* |
1287
|
|
|
* @throws ExpectationFailedException |
1288
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1289
|
|
|
*/ |
1290
|
|
|
public static function assertFileNotIsReadable(string $file, string $message = ''): void |
1291
|
|
|
{ |
1292
|
|
|
self::assertFileExists($file, $message); |
1293
|
|
|
self::assertNotIsReadable($file, $message); |
1294
|
|
|
} |
1295
|
|
|
|
1296
|
|
|
/** |
1297
|
|
|
* Asserts that a file exists and is writable. |
1298
|
|
|
* |
1299
|
|
|
* @throws ExpectationFailedException |
1300
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1301
|
|
|
*/ |
1302
|
|
|
public static function assertFileIsWritable(string $file, string $message = ''): void |
1303
|
|
|
{ |
1304
|
|
|
self::assertFileExists($file, $message); |
1305
|
|
|
self::assertIsWritable($file, $message); |
1306
|
|
|
} |
1307
|
|
|
|
1308
|
|
|
/** |
1309
|
|
|
* Asserts that a file exists and is not writable. |
1310
|
|
|
* |
1311
|
|
|
* @throws ExpectationFailedException |
1312
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1313
|
|
|
*/ |
1314
|
|
|
public static function assertFileNotIsWritable(string $file, string $message = ''): void |
1315
|
|
|
{ |
1316
|
|
|
self::assertFileExists($file, $message); |
1317
|
|
|
self::assertNotIsWritable($file, $message); |
1318
|
|
|
} |
1319
|
|
|
|
1320
|
|
|
/** |
1321
|
|
|
* Asserts that a condition is true. |
1322
|
|
|
* |
1323
|
|
|
* @throws ExpectationFailedException |
1324
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1325
|
|
|
*/ |
1326
|
|
|
public static function assertTrue($condition, string $message = ''): void |
1327
|
|
|
{ |
1328
|
|
|
static::assertThat($condition, static::isTrue(), $message); |
1329
|
|
|
} |
1330
|
|
|
|
1331
|
|
|
/** |
1332
|
|
|
* Asserts that a condition is not true. |
1333
|
|
|
* |
1334
|
|
|
* @throws ExpectationFailedException |
1335
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1336
|
|
|
*/ |
1337
|
|
|
public static function assertNotTrue($condition, string $message = ''): void |
1338
|
|
|
{ |
1339
|
|
|
static::assertThat($condition, static::logicalNot(static::isTrue()), $message); |
1340
|
|
|
} |
1341
|
|
|
|
1342
|
|
|
/** |
1343
|
|
|
* Asserts that a condition is false. |
1344
|
|
|
* |
1345
|
|
|
* @throws ExpectationFailedException |
1346
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1347
|
|
|
*/ |
1348
|
|
|
public static function assertFalse($condition, string $message = ''): void |
1349
|
|
|
{ |
1350
|
|
|
static::assertThat($condition, static::isFalse(), $message); |
1351
|
|
|
} |
1352
|
|
|
|
1353
|
|
|
/** |
1354
|
|
|
* Asserts that a condition is not false. |
1355
|
|
|
* |
1356
|
|
|
* @throws ExpectationFailedException |
1357
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1358
|
|
|
*/ |
1359
|
|
|
public static function assertNotFalse($condition, string $message = ''): void |
1360
|
|
|
{ |
1361
|
|
|
static::assertThat($condition, static::logicalNot(static::isFalse()), $message); |
1362
|
|
|
} |
1363
|
|
|
|
1364
|
|
|
/** |
1365
|
|
|
* Asserts that a variable is null. |
1366
|
|
|
* |
1367
|
|
|
* @throws ExpectationFailedException |
1368
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1369
|
|
|
*/ |
1370
|
|
|
public static function assertNull($actual, string $message = ''): void |
1371
|
|
|
{ |
1372
|
|
|
static::assertThat($actual, static::isNull(), $message); |
1373
|
|
|
} |
1374
|
|
|
|
1375
|
|
|
/** |
1376
|
|
|
* Asserts that a variable is not null. |
1377
|
|
|
* |
1378
|
|
|
* @throws ExpectationFailedException |
1379
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1380
|
|
|
*/ |
1381
|
|
|
public static function assertNotNull($actual, string $message = ''): void |
1382
|
|
|
{ |
1383
|
|
|
static::assertThat($actual, static::logicalNot(static::isNull()), $message); |
1384
|
|
|
} |
1385
|
|
|
|
1386
|
|
|
/** |
1387
|
|
|
* Asserts that a variable is finite. |
1388
|
|
|
* |
1389
|
|
|
* @throws ExpectationFailedException |
1390
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1391
|
|
|
*/ |
1392
|
|
|
public static function assertFinite($actual, string $message = ''): void |
1393
|
|
|
{ |
1394
|
|
|
static::assertThat($actual, static::isFinite(), $message); |
1395
|
|
|
} |
1396
|
|
|
|
1397
|
|
|
/** |
1398
|
|
|
* Asserts that a variable is infinite. |
1399
|
|
|
* |
1400
|
|
|
* @throws ExpectationFailedException |
1401
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1402
|
|
|
*/ |
1403
|
|
|
public static function assertInfinite($actual, string $message = ''): void |
1404
|
|
|
{ |
1405
|
|
|
static::assertThat($actual, static::isInfinite(), $message); |
1406
|
|
|
} |
1407
|
|
|
|
1408
|
|
|
/** |
1409
|
|
|
* Asserts that a variable is nan. |
1410
|
|
|
* |
1411
|
|
|
* @throws ExpectationFailedException |
1412
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1413
|
|
|
*/ |
1414
|
|
|
public static function assertNan($actual, string $message = ''): void |
1415
|
|
|
{ |
1416
|
|
|
static::assertThat($actual, static::isNan(), $message); |
1417
|
|
|
} |
1418
|
|
|
|
1419
|
|
|
/** |
1420
|
|
|
* Asserts that a class has a specified attribute. |
1421
|
|
|
* |
1422
|
|
|
* @throws ExpectationFailedException |
1423
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1424
|
|
|
* @throws Exception |
1425
|
|
|
*/ |
1426
|
|
|
public static function assertClassHasAttribute(string $attributeName, string $className, string $message = ''): void |
1427
|
|
|
{ |
1428
|
|
|
if (!self::isValidClassAttributeName($attributeName)) { |
1429
|
|
|
throw InvalidArgumentHelper::factory(1, 'valid attribute name'); |
1430
|
|
|
} |
1431
|
|
|
|
1432
|
|
|
if (!\class_exists($className)) { |
1433
|
|
|
throw InvalidArgumentHelper::factory(2, 'class name', $className); |
1434
|
|
|
} |
1435
|
|
|
|
1436
|
|
|
static::assertThat($className, new ClassHasAttribute($attributeName), $message); |
1437
|
|
|
} |
1438
|
|
|
|
1439
|
|
|
/** |
1440
|
|
|
* Asserts that a class does not have a specified attribute. |
1441
|
|
|
* |
1442
|
|
|
* @throws ExpectationFailedException |
1443
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1444
|
|
|
* @throws Exception |
1445
|
|
|
*/ |
1446
|
|
|
public static function assertClassNotHasAttribute(string $attributeName, string $className, string $message = ''): void |
1447
|
|
|
{ |
1448
|
|
|
if (!self::isValidClassAttributeName($attributeName)) { |
1449
|
|
|
throw InvalidArgumentHelper::factory(1, 'valid attribute name'); |
1450
|
|
|
} |
1451
|
|
|
|
1452
|
|
|
if (!\class_exists($className)) { |
1453
|
|
|
throw InvalidArgumentHelper::factory(2, 'class name', $className); |
1454
|
|
|
} |
1455
|
|
|
|
1456
|
|
|
static::assertThat( |
1457
|
|
|
$className, |
1458
|
|
|
new LogicalNot( |
1459
|
|
|
new ClassHasAttribute($attributeName) |
1460
|
|
|
), |
1461
|
|
|
$message |
1462
|
|
|
); |
1463
|
|
|
} |
1464
|
|
|
|
1465
|
|
|
/** |
1466
|
|
|
* Asserts that a class has a specified static attribute. |
1467
|
|
|
* |
1468
|
|
|
* @throws ExpectationFailedException |
1469
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1470
|
|
|
* @throws Exception |
1471
|
|
|
*/ |
1472
|
|
|
public static function assertClassHasStaticAttribute(string $attributeName, string $className, string $message = ''): void |
1473
|
|
|
{ |
1474
|
|
|
if (!self::isValidClassAttributeName($attributeName)) { |
1475
|
|
|
throw InvalidArgumentHelper::factory(1, 'valid attribute name'); |
1476
|
|
|
} |
1477
|
|
|
|
1478
|
|
|
if (!\class_exists($className)) { |
1479
|
|
|
throw InvalidArgumentHelper::factory(2, 'class name', $className); |
1480
|
|
|
} |
1481
|
|
|
|
1482
|
|
|
static::assertThat( |
1483
|
|
|
$className, |
1484
|
|
|
new ClassHasStaticAttribute($attributeName), |
1485
|
|
|
$message |
1486
|
|
|
); |
1487
|
|
|
} |
1488
|
|
|
|
1489
|
|
|
/** |
1490
|
|
|
* Asserts that a class does not have a specified static attribute. |
1491
|
|
|
* |
1492
|
|
|
* @throws ExpectationFailedException |
1493
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1494
|
|
|
* @throws Exception |
1495
|
|
|
*/ |
1496
|
|
|
public static function assertClassNotHasStaticAttribute(string $attributeName, string $className, string $message = ''): void |
1497
|
|
|
{ |
1498
|
|
|
if (!self::isValidClassAttributeName($attributeName)) { |
1499
|
|
|
throw InvalidArgumentHelper::factory(1, 'valid attribute name'); |
1500
|
|
|
} |
1501
|
|
|
|
1502
|
|
|
if (!\class_exists($className)) { |
1503
|
|
|
throw InvalidArgumentHelper::factory(2, 'class name', $className); |
1504
|
|
|
} |
1505
|
|
|
|
1506
|
|
|
static::assertThat( |
1507
|
|
|
$className, |
1508
|
|
|
new LogicalNot( |
1509
|
|
|
new ClassHasStaticAttribute($attributeName) |
1510
|
|
|
), |
1511
|
|
|
$message |
1512
|
|
|
); |
1513
|
|
|
} |
1514
|
|
|
|
1515
|
|
|
/** |
1516
|
|
|
* Asserts that an object has a specified attribute. |
1517
|
|
|
* |
1518
|
|
|
* @param object $object |
1519
|
|
|
* |
1520
|
|
|
* @throws ExpectationFailedException |
1521
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1522
|
|
|
* @throws Exception |
1523
|
|
|
*/ |
1524
|
|
|
public static function assertObjectHasAttribute(string $attributeName, $object, string $message = ''): void |
1525
|
|
|
{ |
1526
|
|
|
if (!self::isValidObjectAttributeName($attributeName)) { |
1527
|
|
|
throw InvalidArgumentHelper::factory(1, 'valid attribute name'); |
1528
|
|
|
} |
1529
|
|
|
|
1530
|
|
|
if (!\is_object($object)) { |
1531
|
|
|
throw InvalidArgumentHelper::factory(2, 'object'); |
1532
|
|
|
} |
1533
|
|
|
|
1534
|
|
|
static::assertThat( |
1535
|
|
|
$object, |
1536
|
|
|
new ObjectHasAttribute($attributeName), |
1537
|
|
|
$message |
1538
|
|
|
); |
1539
|
|
|
} |
1540
|
|
|
|
1541
|
|
|
/** |
1542
|
|
|
* Asserts that an object does not have a specified attribute. |
1543
|
|
|
* |
1544
|
|
|
* @param object $object |
1545
|
|
|
* |
1546
|
|
|
* @throws ExpectationFailedException |
1547
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1548
|
|
|
* @throws Exception |
1549
|
|
|
*/ |
1550
|
|
|
public static function assertObjectNotHasAttribute(string $attributeName, $object, string $message = ''): void |
1551
|
|
|
{ |
1552
|
|
|
if (!self::isValidObjectAttributeName($attributeName)) { |
1553
|
|
|
throw InvalidArgumentHelper::factory(1, 'valid attribute name'); |
1554
|
|
|
} |
1555
|
|
|
|
1556
|
|
|
if (!\is_object($object)) { |
1557
|
|
|
throw InvalidArgumentHelper::factory(2, 'object'); |
1558
|
|
|
} |
1559
|
|
|
|
1560
|
|
|
static::assertThat( |
1561
|
|
|
$object, |
1562
|
|
|
new LogicalNot( |
1563
|
|
|
new ObjectHasAttribute($attributeName) |
1564
|
|
|
), |
1565
|
|
|
$message |
1566
|
|
|
); |
1567
|
|
|
} |
1568
|
|
|
|
1569
|
|
|
/** |
1570
|
|
|
* Asserts that two variables have the same type and value. |
1571
|
|
|
* Used on objects, it asserts that two variables reference |
1572
|
|
|
* the same object. |
1573
|
|
|
* |
1574
|
|
|
* @throws ExpectationFailedException |
1575
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1576
|
|
|
*/ |
1577
|
|
|
public static function assertSame($expected, $actual, string $message = ''): void |
1578
|
|
|
{ |
1579
|
|
|
static::assertThat( |
1580
|
|
|
$actual, |
1581
|
|
|
new IsIdentical($expected), |
1582
|
|
|
$message |
1583
|
|
|
); |
1584
|
|
|
} |
1585
|
|
|
|
1586
|
|
|
/** |
1587
|
|
|
* Asserts that a variable and an attribute of an object have the same type |
1588
|
|
|
* and value. |
1589
|
|
|
* |
1590
|
|
|
* @param object|string $actualClassOrObject |
1591
|
|
|
* |
1592
|
|
|
* @throws ExpectationFailedException |
1593
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1594
|
|
|
* @throws ReflectionException |
1595
|
|
|
* @throws Exception |
1596
|
|
|
* |
1597
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
1598
|
|
|
* @codeCoverageIgnore |
1599
|
|
|
*/ |
1600
|
|
|
public static function assertAttributeSame($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void |
1601
|
|
|
{ |
1602
|
|
|
self::createWarning('assertAttributeSame() is deprecated and will be removed in PHPUnit 9.'); |
1603
|
|
|
|
1604
|
|
|
static::assertSame( |
1605
|
|
|
$expected, |
1606
|
|
|
static::readAttribute($actualClassOrObject, $actualAttributeName), |
1607
|
|
|
$message |
1608
|
|
|
); |
1609
|
|
|
} |
1610
|
|
|
|
1611
|
|
|
/** |
1612
|
|
|
* Asserts that two variables do not have the same type and value. |
1613
|
|
|
* Used on objects, it asserts that two variables do not reference |
1614
|
|
|
* the same object. |
1615
|
|
|
* |
1616
|
|
|
* @throws ExpectationFailedException |
1617
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1618
|
|
|
*/ |
1619
|
|
|
public static function assertNotSame($expected, $actual, string $message = ''): void |
1620
|
|
|
{ |
1621
|
|
|
if (\is_bool($expected) && \is_bool($actual)) { |
1622
|
|
|
static::assertNotEquals($expected, $actual, $message); |
1623
|
|
|
} |
1624
|
|
|
|
1625
|
|
|
static::assertThat( |
1626
|
|
|
$actual, |
1627
|
|
|
new LogicalNot( |
1628
|
|
|
new IsIdentical($expected) |
1629
|
|
|
), |
1630
|
|
|
$message |
1631
|
|
|
); |
1632
|
|
|
} |
1633
|
|
|
|
1634
|
|
|
/** |
1635
|
|
|
* Asserts that a variable and an attribute of an object do not have the |
1636
|
|
|
* same type and value. |
1637
|
|
|
* |
1638
|
|
|
* @param object|string $actualClassOrObject |
1639
|
|
|
* |
1640
|
|
|
* @throws ExpectationFailedException |
1641
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1642
|
|
|
* @throws ReflectionException |
1643
|
|
|
* @throws Exception |
1644
|
|
|
* |
1645
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
1646
|
|
|
* @codeCoverageIgnore |
1647
|
|
|
*/ |
1648
|
|
|
public static function assertAttributeNotSame($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void |
1649
|
|
|
{ |
1650
|
|
|
self::createWarning('assertAttributeNotSame() is deprecated and will be removed in PHPUnit 9.'); |
1651
|
|
|
|
1652
|
|
|
static::assertNotSame( |
1653
|
|
|
$expected, |
1654
|
|
|
static::readAttribute($actualClassOrObject, $actualAttributeName), |
1655
|
|
|
$message |
1656
|
|
|
); |
1657
|
|
|
} |
1658
|
|
|
|
1659
|
|
|
/** |
1660
|
|
|
* Asserts that a variable is of a given type. |
1661
|
|
|
* |
1662
|
|
|
* @throws ExpectationFailedException |
1663
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1664
|
|
|
* @throws Exception |
1665
|
|
|
*/ |
1666
|
|
|
public static function assertInstanceOf(string $expected, $actual, string $message = ''): void |
1667
|
|
|
{ |
1668
|
|
|
if (!\class_exists($expected) && !\interface_exists($expected)) { |
1669
|
|
|
throw InvalidArgumentHelper::factory(1, 'class or interface name'); |
1670
|
|
|
} |
1671
|
|
|
|
1672
|
|
|
static::assertThat( |
1673
|
|
|
$actual, |
1674
|
|
|
new IsInstanceOf($expected), |
1675
|
|
|
$message |
1676
|
|
|
); |
1677
|
|
|
} |
1678
|
|
|
|
1679
|
|
|
/** |
1680
|
|
|
* Asserts that an attribute is of a given type. |
1681
|
|
|
* |
1682
|
|
|
* @param object|string $classOrObject |
1683
|
|
|
* |
1684
|
|
|
* @throws ExpectationFailedException |
1685
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1686
|
|
|
* @throws ReflectionException |
1687
|
|
|
* @throws Exception |
1688
|
|
|
* |
1689
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
1690
|
|
|
* @codeCoverageIgnore |
1691
|
|
|
*/ |
1692
|
|
|
public static function assertAttributeInstanceOf(string $expected, string $attributeName, $classOrObject, string $message = ''): void |
1693
|
|
|
{ |
1694
|
|
|
self::createWarning('assertAttributeInstanceOf() is deprecated and will be removed in PHPUnit 9.'); |
1695
|
|
|
|
1696
|
|
|
static::assertInstanceOf( |
1697
|
|
|
$expected, |
1698
|
|
|
static::readAttribute($classOrObject, $attributeName), |
1699
|
|
|
$message |
1700
|
|
|
); |
1701
|
|
|
} |
1702
|
|
|
|
1703
|
|
|
/** |
1704
|
|
|
* Asserts that a variable is not of a given type. |
1705
|
|
|
* |
1706
|
|
|
* @throws ExpectationFailedException |
1707
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1708
|
|
|
* @throws Exception |
1709
|
|
|
*/ |
1710
|
|
|
public static function assertNotInstanceOf(string $expected, $actual, string $message = ''): void |
1711
|
|
|
{ |
1712
|
|
|
if (!\class_exists($expected) && !\interface_exists($expected)) { |
1713
|
|
|
throw InvalidArgumentHelper::factory(1, 'class or interface name'); |
1714
|
|
|
} |
1715
|
|
|
|
1716
|
|
|
static::assertThat( |
1717
|
|
|
$actual, |
1718
|
|
|
new LogicalNot( |
1719
|
|
|
new IsInstanceOf($expected) |
1720
|
|
|
), |
1721
|
|
|
$message |
1722
|
|
|
); |
1723
|
|
|
} |
1724
|
|
|
|
1725
|
|
|
/** |
1726
|
|
|
* Asserts that an attribute is of a given type. |
1727
|
|
|
* |
1728
|
|
|
* @param object|string $classOrObject |
1729
|
|
|
* |
1730
|
|
|
* @throws ExpectationFailedException |
1731
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1732
|
|
|
* @throws ReflectionException |
1733
|
|
|
* @throws Exception |
1734
|
|
|
* |
1735
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
1736
|
|
|
* @codeCoverageIgnore |
1737
|
|
|
*/ |
1738
|
|
|
public static function assertAttributeNotInstanceOf(string $expected, string $attributeName, $classOrObject, string $message = ''): void |
1739
|
|
|
{ |
1740
|
|
|
self::createWarning('assertAttributeNotInstanceOf() is deprecated and will be removed in PHPUnit 9.'); |
1741
|
|
|
|
1742
|
|
|
static::assertNotInstanceOf( |
1743
|
|
|
$expected, |
1744
|
|
|
static::readAttribute($classOrObject, $attributeName), |
1745
|
|
|
$message |
1746
|
|
|
); |
1747
|
|
|
} |
1748
|
|
|
|
1749
|
|
|
/** |
1750
|
|
|
* Asserts that a variable is of a given type. |
1751
|
|
|
* |
1752
|
|
|
* @throws ExpectationFailedException |
1753
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1754
|
|
|
* |
1755
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3369 |
1756
|
|
|
* @codeCoverageIgnore |
1757
|
|
|
*/ |
1758
|
|
|
public static function assertInternalType(string $expected, $actual, string $message = ''): void |
1759
|
|
|
{ |
1760
|
|
|
self::createWarning('assertInternalType() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertIsArray(), assertIsBool(), assertIsFloat(), assertIsInt(), assertIsNumeric(), assertIsObject(), assertIsResource(), assertIsString(), assertIsScalar(), assertIsCallable(), or assertIsIterable() instead.'); |
1761
|
|
|
|
1762
|
|
|
static::assertThat( |
1763
|
|
|
$actual, |
1764
|
|
|
new IsType($expected), |
1765
|
|
|
$message |
1766
|
|
|
); |
1767
|
|
|
} |
1768
|
|
|
|
1769
|
|
|
/** |
1770
|
|
|
* Asserts that an attribute is of a given type. |
1771
|
|
|
* |
1772
|
|
|
* @param object|string $classOrObject |
1773
|
|
|
* |
1774
|
|
|
* @throws ExpectationFailedException |
1775
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1776
|
|
|
* @throws ReflectionException |
1777
|
|
|
* @throws Exception |
1778
|
|
|
* |
1779
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
1780
|
|
|
* @codeCoverageIgnore |
1781
|
|
|
*/ |
1782
|
|
|
public static function assertAttributeInternalType(string $expected, string $attributeName, $classOrObject, string $message = ''): void |
1783
|
|
|
{ |
1784
|
|
|
self::createWarning('assertAttributeInternalType() is deprecated and will be removed in PHPUnit 9.'); |
1785
|
|
|
|
1786
|
|
|
static::assertInternalType( |
1787
|
|
|
$expected, |
1788
|
|
|
static::readAttribute($classOrObject, $attributeName), |
1789
|
|
|
$message |
1790
|
|
|
); |
1791
|
|
|
} |
1792
|
|
|
|
1793
|
|
|
/** |
1794
|
|
|
* Asserts that a variable is of type array. |
1795
|
|
|
* |
1796
|
|
|
* @throws ExpectationFailedException |
1797
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1798
|
|
|
*/ |
1799
|
|
|
public static function assertIsArray($actual, string $message = ''): void |
1800
|
|
|
{ |
1801
|
|
|
static::assertThat( |
1802
|
|
|
$actual, |
1803
|
|
|
new IsType(IsType::TYPE_ARRAY), |
1804
|
|
|
$message |
1805
|
|
|
); |
1806
|
|
|
} |
1807
|
|
|
|
1808
|
|
|
/** |
1809
|
|
|
* Asserts that a variable is of type bool. |
1810
|
|
|
* |
1811
|
|
|
* @throws ExpectationFailedException |
1812
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1813
|
|
|
*/ |
1814
|
|
|
public static function assertIsBool($actual, string $message = ''): void |
1815
|
|
|
{ |
1816
|
|
|
static::assertThat( |
1817
|
|
|
$actual, |
1818
|
|
|
new IsType(IsType::TYPE_BOOL), |
1819
|
|
|
$message |
1820
|
|
|
); |
1821
|
|
|
} |
1822
|
|
|
|
1823
|
|
|
/** |
1824
|
|
|
* Asserts that a variable is of type float. |
1825
|
|
|
* |
1826
|
|
|
* @throws ExpectationFailedException |
1827
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1828
|
|
|
*/ |
1829
|
|
|
public static function assertIsFloat($actual, string $message = ''): void |
1830
|
|
|
{ |
1831
|
|
|
static::assertThat( |
1832
|
|
|
$actual, |
1833
|
|
|
new IsType(IsType::TYPE_FLOAT), |
1834
|
|
|
$message |
1835
|
|
|
); |
1836
|
|
|
} |
1837
|
|
|
|
1838
|
|
|
/** |
1839
|
|
|
* Asserts that a variable is of type int. |
1840
|
|
|
* |
1841
|
|
|
* @throws ExpectationFailedException |
1842
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1843
|
|
|
*/ |
1844
|
|
|
public static function assertIsInt($actual, string $message = ''): void |
1845
|
|
|
{ |
1846
|
|
|
static::assertThat( |
1847
|
|
|
$actual, |
1848
|
|
|
new IsType(IsType::TYPE_INT), |
1849
|
|
|
$message |
1850
|
|
|
); |
1851
|
|
|
} |
1852
|
|
|
|
1853
|
|
|
/** |
1854
|
|
|
* Asserts that a variable is of type numeric. |
1855
|
|
|
* |
1856
|
|
|
* @throws ExpectationFailedException |
1857
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1858
|
|
|
*/ |
1859
|
|
|
public static function assertIsNumeric($actual, string $message = ''): void |
1860
|
|
|
{ |
1861
|
|
|
static::assertThat( |
1862
|
|
|
$actual, |
1863
|
|
|
new IsType(IsType::TYPE_NUMERIC), |
1864
|
|
|
$message |
1865
|
|
|
); |
1866
|
|
|
} |
1867
|
|
|
|
1868
|
|
|
/** |
1869
|
|
|
* Asserts that a variable is of type object. |
1870
|
|
|
* |
1871
|
|
|
* @throws ExpectationFailedException |
1872
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1873
|
|
|
*/ |
1874
|
|
|
public static function assertIsObject($actual, string $message = ''): void |
1875
|
|
|
{ |
1876
|
|
|
static::assertThat( |
1877
|
|
|
$actual, |
1878
|
|
|
new IsType(IsType::TYPE_OBJECT), |
1879
|
|
|
$message |
1880
|
|
|
); |
1881
|
|
|
} |
1882
|
|
|
|
1883
|
|
|
/** |
1884
|
|
|
* Asserts that a variable is of type resource. |
1885
|
|
|
* |
1886
|
|
|
* @throws ExpectationFailedException |
1887
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1888
|
|
|
*/ |
1889
|
|
|
public static function assertIsResource($actual, string $message = ''): void |
1890
|
|
|
{ |
1891
|
|
|
static::assertThat( |
1892
|
|
|
$actual, |
1893
|
|
|
new IsType(IsType::TYPE_RESOURCE), |
1894
|
|
|
$message |
1895
|
|
|
); |
1896
|
|
|
} |
1897
|
|
|
|
1898
|
|
|
/** |
1899
|
|
|
* Asserts that a variable is of type string. |
1900
|
|
|
* |
1901
|
|
|
* @throws ExpectationFailedException |
1902
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1903
|
|
|
*/ |
1904
|
|
|
public static function assertIsString($actual, string $message = ''): void |
1905
|
|
|
{ |
1906
|
|
|
static::assertThat( |
1907
|
|
|
$actual, |
1908
|
|
|
new IsType(IsType::TYPE_STRING), |
1909
|
|
|
$message |
1910
|
|
|
); |
1911
|
|
|
} |
1912
|
|
|
|
1913
|
|
|
/** |
1914
|
|
|
* Asserts that a variable is of type scalar. |
1915
|
|
|
* |
1916
|
|
|
* @throws ExpectationFailedException |
1917
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1918
|
|
|
*/ |
1919
|
|
|
public static function assertIsScalar($actual, string $message = ''): void |
1920
|
|
|
{ |
1921
|
|
|
static::assertThat( |
1922
|
|
|
$actual, |
1923
|
|
|
new IsType(IsType::TYPE_SCALAR), |
1924
|
|
|
$message |
1925
|
|
|
); |
1926
|
|
|
} |
1927
|
|
|
|
1928
|
|
|
/** |
1929
|
|
|
* Asserts that a variable is of type callable. |
1930
|
|
|
* |
1931
|
|
|
* @throws ExpectationFailedException |
1932
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1933
|
|
|
*/ |
1934
|
|
|
public static function assertIsCallable($actual, string $message = ''): void |
1935
|
|
|
{ |
1936
|
|
|
static::assertThat( |
1937
|
|
|
$actual, |
1938
|
|
|
new IsType(IsType::TYPE_CALLABLE), |
1939
|
|
|
$message |
1940
|
|
|
); |
1941
|
|
|
} |
1942
|
|
|
|
1943
|
|
|
/** |
1944
|
|
|
* Asserts that a variable is of type iterable. |
1945
|
|
|
* |
1946
|
|
|
* @throws ExpectationFailedException |
1947
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1948
|
|
|
*/ |
1949
|
|
|
public static function assertIsIterable($actual, string $message = ''): void |
1950
|
|
|
{ |
1951
|
|
|
static::assertThat( |
1952
|
|
|
$actual, |
1953
|
|
|
new IsType(IsType::TYPE_ITERABLE), |
1954
|
|
|
$message |
1955
|
|
|
); |
1956
|
|
|
} |
1957
|
|
|
|
1958
|
|
|
/** |
1959
|
|
|
* Asserts that a variable is not of a given type. |
1960
|
|
|
* |
1961
|
|
|
* @throws ExpectationFailedException |
1962
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1963
|
|
|
* |
1964
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3369 |
1965
|
|
|
* @codeCoverageIgnore |
1966
|
|
|
*/ |
1967
|
|
|
public static function assertNotInternalType(string $expected, $actual, string $message = ''): void |
1968
|
|
|
{ |
1969
|
|
|
self::createWarning('assertNotInternalType() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertIsNotArray(), assertIsNotBool(), assertIsNotFloat(), assertIsNotInt(), assertIsNotNumeric(), assertIsNotObject(), assertIsNotResource(), assertIsNotString(), assertIsNotScalar(), assertIsNotCallable(), or assertIsNotIterable() instead.'); |
1970
|
|
|
|
1971
|
|
|
static::assertThat( |
1972
|
|
|
$actual, |
1973
|
|
|
new LogicalNot( |
1974
|
|
|
new IsType($expected) |
1975
|
|
|
), |
1976
|
|
|
$message |
1977
|
|
|
); |
1978
|
|
|
} |
1979
|
|
|
|
1980
|
|
|
/** |
1981
|
|
|
* Asserts that a variable is not of type array. |
1982
|
|
|
* |
1983
|
|
|
* @throws ExpectationFailedException |
1984
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
1985
|
|
|
*/ |
1986
|
|
|
public static function assertIsNotArray($actual, string $message = ''): void |
1987
|
|
|
{ |
1988
|
|
|
static::assertThat( |
1989
|
|
|
$actual, |
1990
|
|
|
new LogicalNot(new IsType(IsType::TYPE_ARRAY)), |
1991
|
|
|
$message |
1992
|
|
|
); |
1993
|
|
|
} |
1994
|
|
|
|
1995
|
|
|
/** |
1996
|
|
|
* Asserts that a variable is not of type bool. |
1997
|
|
|
* |
1998
|
|
|
* @throws ExpectationFailedException |
1999
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2000
|
|
|
*/ |
2001
|
|
|
public static function assertIsNotBool($actual, string $message = ''): void |
2002
|
|
|
{ |
2003
|
|
|
static::assertThat( |
2004
|
|
|
$actual, |
2005
|
|
|
new LogicalNot(new IsType(IsType::TYPE_BOOL)), |
2006
|
|
|
$message |
2007
|
|
|
); |
2008
|
|
|
} |
2009
|
|
|
|
2010
|
|
|
/** |
2011
|
|
|
* Asserts that a variable is not of type float. |
2012
|
|
|
* |
2013
|
|
|
* @throws ExpectationFailedException |
2014
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2015
|
|
|
*/ |
2016
|
|
|
public static function assertIsNotFloat($actual, string $message = ''): void |
2017
|
|
|
{ |
2018
|
|
|
static::assertThat( |
2019
|
|
|
$actual, |
2020
|
|
|
new LogicalNot(new IsType(IsType::TYPE_FLOAT)), |
2021
|
|
|
$message |
2022
|
|
|
); |
2023
|
|
|
} |
2024
|
|
|
|
2025
|
|
|
/** |
2026
|
|
|
* Asserts that a variable is not of type int. |
2027
|
|
|
* |
2028
|
|
|
* @throws ExpectationFailedException |
2029
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2030
|
|
|
*/ |
2031
|
|
|
public static function assertIsNotInt($actual, string $message = ''): void |
2032
|
|
|
{ |
2033
|
|
|
static::assertThat( |
2034
|
|
|
$actual, |
2035
|
|
|
new LogicalNot(new IsType(IsType::TYPE_INT)), |
2036
|
|
|
$message |
2037
|
|
|
); |
2038
|
|
|
} |
2039
|
|
|
|
2040
|
|
|
/** |
2041
|
|
|
* Asserts that a variable is not of type numeric. |
2042
|
|
|
* |
2043
|
|
|
* @throws ExpectationFailedException |
2044
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2045
|
|
|
*/ |
2046
|
|
|
public static function assertIsNotNumeric($actual, string $message = ''): void |
2047
|
|
|
{ |
2048
|
|
|
static::assertThat( |
2049
|
|
|
$actual, |
2050
|
|
|
new LogicalNot(new IsType(IsType::TYPE_NUMERIC)), |
2051
|
|
|
$message |
2052
|
|
|
); |
2053
|
|
|
} |
2054
|
|
|
|
2055
|
|
|
/** |
2056
|
|
|
* Asserts that a variable is not of type object. |
2057
|
|
|
* |
2058
|
|
|
* @throws ExpectationFailedException |
2059
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2060
|
|
|
*/ |
2061
|
|
|
public static function assertIsNotObject($actual, string $message = ''): void |
2062
|
|
|
{ |
2063
|
|
|
static::assertThat( |
2064
|
|
|
$actual, |
2065
|
|
|
new LogicalNot(new IsType(IsType::TYPE_OBJECT)), |
2066
|
|
|
$message |
2067
|
|
|
); |
2068
|
|
|
} |
2069
|
|
|
|
2070
|
|
|
/** |
2071
|
|
|
* Asserts that a variable is not of type resource. |
2072
|
|
|
* |
2073
|
|
|
* @throws ExpectationFailedException |
2074
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2075
|
|
|
*/ |
2076
|
|
|
public static function assertIsNotResource($actual, string $message = ''): void |
2077
|
|
|
{ |
2078
|
|
|
static::assertThat( |
2079
|
|
|
$actual, |
2080
|
|
|
new LogicalNot(new IsType(IsType::TYPE_RESOURCE)), |
2081
|
|
|
$message |
2082
|
|
|
); |
2083
|
|
|
} |
2084
|
|
|
|
2085
|
|
|
/** |
2086
|
|
|
* Asserts that a variable is not of type string. |
2087
|
|
|
* |
2088
|
|
|
* @throws ExpectationFailedException |
2089
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2090
|
|
|
*/ |
2091
|
|
|
public static function assertIsNotString($actual, string $message = ''): void |
2092
|
|
|
{ |
2093
|
|
|
static::assertThat( |
2094
|
|
|
$actual, |
2095
|
|
|
new LogicalNot(new IsType(IsType::TYPE_STRING)), |
2096
|
|
|
$message |
2097
|
|
|
); |
2098
|
|
|
} |
2099
|
|
|
|
2100
|
|
|
/** |
2101
|
|
|
* Asserts that a variable is not of type scalar. |
2102
|
|
|
* |
2103
|
|
|
* @throws ExpectationFailedException |
2104
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2105
|
|
|
*/ |
2106
|
|
|
public static function assertIsNotScalar($actual, string $message = ''): void |
2107
|
|
|
{ |
2108
|
|
|
static::assertThat( |
2109
|
|
|
$actual, |
2110
|
|
|
new LogicalNot(new IsType(IsType::TYPE_SCALAR)), |
2111
|
|
|
$message |
2112
|
|
|
); |
2113
|
|
|
} |
2114
|
|
|
|
2115
|
|
|
/** |
2116
|
|
|
* Asserts that a variable is not of type callable. |
2117
|
|
|
* |
2118
|
|
|
* @throws ExpectationFailedException |
2119
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2120
|
|
|
*/ |
2121
|
|
|
public static function assertIsNotCallable($actual, string $message = ''): void |
2122
|
|
|
{ |
2123
|
|
|
static::assertThat( |
2124
|
|
|
$actual, |
2125
|
|
|
new LogicalNot(new IsType(IsType::TYPE_CALLABLE)), |
2126
|
|
|
$message |
2127
|
|
|
); |
2128
|
|
|
} |
2129
|
|
|
|
2130
|
|
|
/** |
2131
|
|
|
* Asserts that a variable is not of type iterable. |
2132
|
|
|
* |
2133
|
|
|
* @throws ExpectationFailedException |
2134
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2135
|
|
|
*/ |
2136
|
|
|
public static function assertIsNotIterable($actual, string $message = ''): void |
2137
|
|
|
{ |
2138
|
|
|
static::assertThat( |
2139
|
|
|
$actual, |
2140
|
|
|
new LogicalNot(new IsType(IsType::TYPE_ITERABLE)), |
2141
|
|
|
$message |
2142
|
|
|
); |
2143
|
|
|
} |
2144
|
|
|
|
2145
|
|
|
/** |
2146
|
|
|
* Asserts that an attribute is of a given type. |
2147
|
|
|
* |
2148
|
|
|
* @param object|string $classOrObject |
2149
|
|
|
* |
2150
|
|
|
* @throws ExpectationFailedException |
2151
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2152
|
|
|
* @throws ReflectionException |
2153
|
|
|
* @throws Exception |
2154
|
|
|
* |
2155
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
2156
|
|
|
* @codeCoverageIgnore |
2157
|
|
|
*/ |
2158
|
|
|
public static function assertAttributeNotInternalType(string $expected, string $attributeName, $classOrObject, string $message = ''): void |
2159
|
|
|
{ |
2160
|
|
|
self::createWarning('assertAttributeNotInternalType() is deprecated and will be removed in PHPUnit 9.'); |
2161
|
|
|
|
2162
|
|
|
static::assertNotInternalType( |
2163
|
|
|
$expected, |
2164
|
|
|
static::readAttribute($classOrObject, $attributeName), |
2165
|
|
|
$message |
2166
|
|
|
); |
2167
|
|
|
} |
2168
|
|
|
|
2169
|
|
|
/** |
2170
|
|
|
* Asserts that a string matches a given regular expression. |
2171
|
|
|
* |
2172
|
|
|
* @throws ExpectationFailedException |
2173
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2174
|
|
|
*/ |
2175
|
|
|
public static function assertRegExp(string $pattern, string $string, string $message = ''): void |
2176
|
|
|
{ |
2177
|
|
|
static::assertThat($string, new RegularExpression($pattern), $message); |
2178
|
|
|
} |
2179
|
|
|
|
2180
|
|
|
/** |
2181
|
|
|
* Asserts that a string does not match a given regular expression. |
2182
|
|
|
* |
2183
|
|
|
* @throws ExpectationFailedException |
2184
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2185
|
|
|
*/ |
2186
|
|
|
public static function assertNotRegExp(string $pattern, string $string, string $message = ''): void |
2187
|
|
|
{ |
2188
|
|
|
static::assertThat( |
2189
|
|
|
$string, |
2190
|
|
|
new LogicalNot( |
2191
|
|
|
new RegularExpression($pattern) |
2192
|
|
|
), |
2193
|
|
|
$message |
2194
|
|
|
); |
2195
|
|
|
} |
2196
|
|
|
|
2197
|
|
|
/** |
2198
|
|
|
* Assert that the size of two arrays (or `Countable` or `Traversable` objects) |
2199
|
|
|
* is the same. |
2200
|
|
|
* |
2201
|
|
|
* @param Countable|iterable $expected |
2202
|
|
|
* @param Countable|iterable $actual |
2203
|
|
|
* |
2204
|
|
|
* @throws ExpectationFailedException |
2205
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2206
|
|
|
* @throws Exception |
2207
|
|
|
*/ |
2208
|
|
|
public static function assertSameSize($expected, $actual, string $message = ''): void |
2209
|
|
|
{ |
2210
|
|
|
if (!$expected instanceof Countable && !\is_iterable($expected)) { |
2211
|
|
|
throw InvalidArgumentHelper::factory(1, 'countable or iterable'); |
2212
|
|
|
} |
2213
|
|
|
|
2214
|
|
|
if (!$actual instanceof Countable && !\is_iterable($actual)) { |
2215
|
|
|
throw InvalidArgumentHelper::factory(2, 'countable or iterable'); |
2216
|
|
|
} |
2217
|
|
|
|
2218
|
|
|
static::assertThat( |
2219
|
|
|
$actual, |
2220
|
|
|
new SameSize($expected), |
2221
|
|
|
$message |
2222
|
|
|
); |
2223
|
|
|
} |
2224
|
|
|
|
2225
|
|
|
/** |
2226
|
|
|
* Assert that the size of two arrays (or `Countable` or `Traversable` objects) |
2227
|
|
|
* is not the same. |
2228
|
|
|
* |
2229
|
|
|
* @param Countable|iterable $expected |
2230
|
|
|
* @param Countable|iterable $actual |
2231
|
|
|
* |
2232
|
|
|
* @throws ExpectationFailedException |
2233
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2234
|
|
|
* @throws Exception |
2235
|
|
|
*/ |
2236
|
|
|
public static function assertNotSameSize($expected, $actual, string $message = ''): void |
2237
|
|
|
{ |
2238
|
|
|
if (!$expected instanceof Countable && !\is_iterable($expected)) { |
2239
|
|
|
throw InvalidArgumentHelper::factory(1, 'countable or iterable'); |
2240
|
|
|
} |
2241
|
|
|
|
2242
|
|
|
if (!$actual instanceof Countable && !\is_iterable($actual)) { |
2243
|
|
|
throw InvalidArgumentHelper::factory(2, 'countable or iterable'); |
2244
|
|
|
} |
2245
|
|
|
|
2246
|
|
|
static::assertThat( |
2247
|
|
|
$actual, |
2248
|
|
|
new LogicalNot( |
2249
|
|
|
new SameSize($expected) |
2250
|
|
|
), |
2251
|
|
|
$message |
2252
|
|
|
); |
2253
|
|
|
} |
2254
|
|
|
|
2255
|
|
|
/** |
2256
|
|
|
* Asserts that a string matches a given format string. |
2257
|
|
|
* |
2258
|
|
|
* @throws ExpectationFailedException |
2259
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2260
|
|
|
*/ |
2261
|
|
|
public static function assertStringMatchesFormat(string $format, string $string, string $message = ''): void |
2262
|
|
|
{ |
2263
|
|
|
static::assertThat($string, new StringMatchesFormatDescription($format), $message); |
2264
|
|
|
} |
2265
|
|
|
|
2266
|
|
|
/** |
2267
|
|
|
* Asserts that a string does not match a given format string. |
2268
|
|
|
* |
2269
|
|
|
* @throws ExpectationFailedException |
2270
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2271
|
|
|
*/ |
2272
|
|
|
public static function assertStringNotMatchesFormat(string $format, string $string, string $message = ''): void |
2273
|
|
|
{ |
2274
|
|
|
static::assertThat( |
2275
|
|
|
$string, |
2276
|
|
|
new LogicalNot( |
2277
|
|
|
new StringMatchesFormatDescription($format) |
2278
|
|
|
), |
2279
|
|
|
$message |
2280
|
|
|
); |
2281
|
|
|
} |
2282
|
|
|
|
2283
|
|
|
/** |
2284
|
|
|
* Asserts that a string matches a given format file. |
2285
|
|
|
* |
2286
|
|
|
* @throws ExpectationFailedException |
2287
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2288
|
|
|
*/ |
2289
|
|
|
public static function assertStringMatchesFormatFile(string $formatFile, string $string, string $message = ''): void |
2290
|
|
|
{ |
2291
|
|
|
static::assertFileExists($formatFile, $message); |
2292
|
|
|
|
2293
|
|
|
static::assertThat( |
2294
|
|
|
$string, |
2295
|
|
|
new StringMatchesFormatDescription( |
2296
|
|
|
\file_get_contents($formatFile) |
2297
|
|
|
), |
2298
|
|
|
$message |
2299
|
|
|
); |
2300
|
|
|
} |
2301
|
|
|
|
2302
|
|
|
/** |
2303
|
|
|
* Asserts that a string does not match a given format string. |
2304
|
|
|
* |
2305
|
|
|
* @throws ExpectationFailedException |
2306
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2307
|
|
|
*/ |
2308
|
|
|
public static function assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = ''): void |
2309
|
|
|
{ |
2310
|
|
|
static::assertFileExists($formatFile, $message); |
2311
|
|
|
|
2312
|
|
|
static::assertThat( |
2313
|
|
|
$string, |
2314
|
|
|
new LogicalNot( |
2315
|
|
|
new StringMatchesFormatDescription( |
2316
|
|
|
\file_get_contents($formatFile) |
2317
|
|
|
) |
2318
|
|
|
), |
2319
|
|
|
$message |
2320
|
|
|
); |
2321
|
|
|
} |
2322
|
|
|
|
2323
|
|
|
/** |
2324
|
|
|
* Asserts that a string starts with a given prefix. |
2325
|
|
|
* |
2326
|
|
|
* @throws ExpectationFailedException |
2327
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2328
|
|
|
*/ |
2329
|
|
|
public static function assertStringStartsWith(string $prefix, string $string, string $message = ''): void |
2330
|
|
|
{ |
2331
|
|
|
static::assertThat($string, new StringStartsWith($prefix), $message); |
2332
|
|
|
} |
2333
|
|
|
|
2334
|
|
|
/** |
2335
|
|
|
* Asserts that a string starts not with a given prefix. |
2336
|
|
|
* |
2337
|
|
|
* @param string $prefix |
2338
|
|
|
* @param string $string |
2339
|
|
|
* |
2340
|
|
|
* @throws ExpectationFailedException |
2341
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2342
|
|
|
*/ |
2343
|
|
|
public static function assertStringStartsNotWith($prefix, $string, string $message = ''): void |
2344
|
|
|
{ |
2345
|
|
|
static::assertThat( |
2346
|
|
|
$string, |
2347
|
|
|
new LogicalNot( |
2348
|
|
|
new StringStartsWith($prefix) |
2349
|
|
|
), |
2350
|
|
|
$message |
2351
|
|
|
); |
2352
|
|
|
} |
2353
|
|
|
|
2354
|
|
|
/** |
2355
|
|
|
* @throws ExpectationFailedException |
2356
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2357
|
|
|
*/ |
2358
|
|
|
public static function assertStringContainsString(string $needle, string $haystack, string $message = ''): void |
2359
|
|
|
{ |
2360
|
|
|
$constraint = new StringContains($needle, false); |
2361
|
|
|
|
2362
|
|
|
static::assertThat($haystack, $constraint, $message); |
2363
|
|
|
} |
2364
|
|
|
|
2365
|
|
|
/** |
2366
|
|
|
* @throws ExpectationFailedException |
2367
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2368
|
|
|
*/ |
2369
|
|
|
public static function assertStringContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void |
2370
|
|
|
{ |
2371
|
|
|
$constraint = new StringContains($needle, true); |
2372
|
|
|
|
2373
|
|
|
static::assertThat($haystack, $constraint, $message); |
2374
|
|
|
} |
2375
|
|
|
|
2376
|
|
|
/** |
2377
|
|
|
* @throws ExpectationFailedException |
2378
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2379
|
|
|
*/ |
2380
|
|
|
public static function assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void |
2381
|
|
|
{ |
2382
|
|
|
$constraint = new LogicalNot(new StringContains($needle)); |
2383
|
|
|
|
2384
|
|
|
static::assertThat($haystack, $constraint, $message); |
2385
|
|
|
} |
2386
|
|
|
|
2387
|
|
|
/** |
2388
|
|
|
* @throws ExpectationFailedException |
2389
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2390
|
|
|
*/ |
2391
|
|
|
public static function assertStringNotContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void |
2392
|
|
|
{ |
2393
|
|
|
$constraint = new LogicalNot(new StringContains($needle, true)); |
2394
|
|
|
|
2395
|
|
|
static::assertThat($haystack, $constraint, $message); |
2396
|
|
|
} |
2397
|
|
|
|
2398
|
|
|
/** |
2399
|
|
|
* Asserts that a string ends with a given suffix. |
2400
|
|
|
* |
2401
|
|
|
* @throws ExpectationFailedException |
2402
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2403
|
|
|
*/ |
2404
|
|
|
public static function assertStringEndsWith(string $suffix, string $string, string $message = ''): void |
2405
|
|
|
{ |
2406
|
|
|
static::assertThat($string, new StringEndsWith($suffix), $message); |
2407
|
|
|
} |
2408
|
|
|
|
2409
|
|
|
/** |
2410
|
|
|
* Asserts that a string ends not with a given suffix. |
2411
|
|
|
* |
2412
|
|
|
* @throws ExpectationFailedException |
2413
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2414
|
|
|
*/ |
2415
|
|
|
public static function assertStringEndsNotWith(string $suffix, string $string, string $message = ''): void |
2416
|
|
|
{ |
2417
|
|
|
static::assertThat( |
2418
|
|
|
$string, |
2419
|
|
|
new LogicalNot( |
2420
|
|
|
new StringEndsWith($suffix) |
2421
|
|
|
), |
2422
|
|
|
$message |
2423
|
|
|
); |
2424
|
|
|
} |
2425
|
|
|
|
2426
|
|
|
/** |
2427
|
|
|
* Asserts that two XML files are equal. |
2428
|
|
|
* |
2429
|
|
|
* @throws ExpectationFailedException |
2430
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2431
|
|
|
* @throws Exception |
2432
|
|
|
*/ |
2433
|
|
|
public static function assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void |
2434
|
|
|
{ |
2435
|
|
|
$expected = Xml::loadFile($expectedFile); |
2436
|
|
|
$actual = Xml::loadFile($actualFile); |
2437
|
|
|
|
2438
|
|
|
static::assertEquals($expected, $actual, $message); |
2439
|
|
|
} |
2440
|
|
|
|
2441
|
|
|
/** |
2442
|
|
|
* Asserts that two XML files are not equal. |
2443
|
|
|
* |
2444
|
|
|
* @throws ExpectationFailedException |
2445
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2446
|
|
|
* @throws Exception |
2447
|
|
|
*/ |
2448
|
|
|
public static function assertXmlFileNotEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void |
2449
|
|
|
{ |
2450
|
|
|
$expected = Xml::loadFile($expectedFile); |
2451
|
|
|
$actual = Xml::loadFile($actualFile); |
2452
|
|
|
|
2453
|
|
|
static::assertNotEquals($expected, $actual, $message); |
2454
|
|
|
} |
2455
|
|
|
|
2456
|
|
|
/** |
2457
|
|
|
* Asserts that two XML documents are equal. |
2458
|
|
|
* |
2459
|
|
|
* @param DOMDocument|string $actualXml |
2460
|
|
|
* |
2461
|
|
|
* @throws ExpectationFailedException |
2462
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2463
|
|
|
* @throws Exception |
2464
|
|
|
*/ |
2465
|
|
|
public static function assertXmlStringEqualsXmlFile(string $expectedFile, $actualXml, string $message = ''): void |
2466
|
|
|
{ |
2467
|
|
|
$expected = Xml::loadFile($expectedFile); |
2468
|
|
|
$actual = Xml::load($actualXml); |
2469
|
|
|
|
2470
|
|
|
static::assertEquals($expected, $actual, $message); |
2471
|
|
|
} |
2472
|
|
|
|
2473
|
|
|
/** |
2474
|
|
|
* Asserts that two XML documents are not equal. |
2475
|
|
|
* |
2476
|
|
|
* @param DOMDocument|string $actualXml |
2477
|
|
|
* |
2478
|
|
|
* @throws ExpectationFailedException |
2479
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2480
|
|
|
* @throws Exception |
2481
|
|
|
*/ |
2482
|
|
|
public static function assertXmlStringNotEqualsXmlFile(string $expectedFile, $actualXml, string $message = ''): void |
2483
|
|
|
{ |
2484
|
|
|
$expected = Xml::loadFile($expectedFile); |
2485
|
|
|
$actual = Xml::load($actualXml); |
2486
|
|
|
|
2487
|
|
|
static::assertNotEquals($expected, $actual, $message); |
2488
|
|
|
} |
2489
|
|
|
|
2490
|
|
|
/** |
2491
|
|
|
* Asserts that two XML documents are equal. |
2492
|
|
|
* |
2493
|
|
|
* @param DOMDocument|string $expectedXml |
2494
|
|
|
* @param DOMDocument|string $actualXml |
2495
|
|
|
* |
2496
|
|
|
* @throws ExpectationFailedException |
2497
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2498
|
|
|
* @throws Exception |
2499
|
|
|
*/ |
2500
|
|
|
public static function assertXmlStringEqualsXmlString($expectedXml, $actualXml, string $message = ''): void |
2501
|
|
|
{ |
2502
|
|
|
$expected = Xml::load($expectedXml); |
2503
|
|
|
$actual = Xml::load($actualXml); |
2504
|
|
|
|
2505
|
|
|
static::assertEquals($expected, $actual, $message); |
2506
|
|
|
} |
2507
|
|
|
|
2508
|
|
|
/** |
2509
|
|
|
* Asserts that two XML documents are not equal. |
2510
|
|
|
* |
2511
|
|
|
* @param DOMDocument|string $expectedXml |
2512
|
|
|
* @param DOMDocument|string $actualXml |
2513
|
|
|
* |
2514
|
|
|
* @throws ExpectationFailedException |
2515
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2516
|
|
|
* @throws Exception |
2517
|
|
|
*/ |
2518
|
|
|
public static function assertXmlStringNotEqualsXmlString($expectedXml, $actualXml, string $message = ''): void |
2519
|
|
|
{ |
2520
|
|
|
$expected = Xml::load($expectedXml); |
2521
|
|
|
$actual = Xml::load($actualXml); |
2522
|
|
|
|
2523
|
|
|
static::assertNotEquals($expected, $actual, $message); |
2524
|
|
|
} |
2525
|
|
|
|
2526
|
|
|
/** |
2527
|
|
|
* Asserts that a hierarchy of DOMElements matches. |
2528
|
|
|
* |
2529
|
|
|
* @throws AssertionFailedError |
2530
|
|
|
* @throws ExpectationFailedException |
2531
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2532
|
|
|
*/ |
2533
|
|
|
public static function assertEqualXMLStructure(DOMElement $expectedElement, DOMElement $actualElement, bool $checkAttributes = false, string $message = ''): void |
2534
|
|
|
{ |
2535
|
|
|
$expectedElement = Xml::import($expectedElement); |
2536
|
|
|
$actualElement = Xml::import($actualElement); |
2537
|
|
|
|
2538
|
|
|
static::assertSame( |
2539
|
|
|
$expectedElement->tagName, |
2540
|
|
|
$actualElement->tagName, |
2541
|
|
|
$message |
2542
|
|
|
); |
2543
|
|
|
|
2544
|
|
|
if ($checkAttributes) { |
2545
|
|
|
static::assertSame( |
2546
|
|
|
$expectedElement->attributes->length, |
2547
|
|
|
$actualElement->attributes->length, |
2548
|
|
|
\sprintf( |
2549
|
|
|
'%s%sNumber of attributes on node "%s" does not match', |
2550
|
|
|
$message, |
2551
|
|
|
!empty($message) ? "\n" : '', |
2552
|
|
|
$expectedElement->tagName |
2553
|
|
|
) |
2554
|
|
|
); |
2555
|
|
|
|
2556
|
|
|
for ($i = 0; $i < $expectedElement->attributes->length; $i++) { |
2557
|
|
|
$expectedAttribute = $expectedElement->attributes->item($i); |
2558
|
|
|
$actualAttribute = $actualElement->attributes->getNamedItem($expectedAttribute->name); |
2559
|
|
|
|
2560
|
|
|
\assert($expectedAttribute instanceof \DOMAttr); |
2561
|
|
|
|
2562
|
|
|
if (!$actualAttribute) { |
2563
|
|
|
static::fail( |
2564
|
|
|
\sprintf( |
2565
|
|
|
'%s%sCould not find attribute "%s" on node "%s"', |
2566
|
|
|
$message, |
2567
|
|
|
!empty($message) ? "\n" : '', |
2568
|
|
|
$expectedAttribute->name, |
2569
|
|
|
$expectedElement->tagName |
2570
|
|
|
) |
2571
|
|
|
); |
2572
|
|
|
} |
2573
|
|
|
} |
2574
|
|
|
} |
2575
|
|
|
|
2576
|
|
|
Xml::removeCharacterDataNodes($expectedElement); |
2577
|
|
|
Xml::removeCharacterDataNodes($actualElement); |
2578
|
|
|
|
2579
|
|
|
static::assertSame( |
2580
|
|
|
$expectedElement->childNodes->length, |
2581
|
|
|
$actualElement->childNodes->length, |
2582
|
|
|
\sprintf( |
2583
|
|
|
'%s%sNumber of child nodes of "%s" differs', |
2584
|
|
|
$message, |
2585
|
|
|
!empty($message) ? "\n" : '', |
2586
|
|
|
$expectedElement->tagName |
2587
|
|
|
) |
2588
|
|
|
); |
2589
|
|
|
|
2590
|
|
|
for ($i = 0; $i < $expectedElement->childNodes->length; $i++) { |
2591
|
|
|
static::assertEqualXMLStructure( |
2592
|
|
|
$expectedElement->childNodes->item($i), |
2593
|
|
|
$actualElement->childNodes->item($i), |
2594
|
|
|
$checkAttributes, |
2595
|
|
|
$message |
2596
|
|
|
); |
2597
|
|
|
} |
2598
|
|
|
} |
2599
|
|
|
|
2600
|
|
|
/** |
2601
|
|
|
* Evaluates a PHPUnit\Framework\Constraint matcher object. |
2602
|
|
|
* |
2603
|
|
|
* @throws ExpectationFailedException |
2604
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2605
|
|
|
*/ |
2606
|
|
|
public static function assertThat($value, Constraint $constraint, string $message = ''): void |
2607
|
|
|
{ |
2608
|
|
|
self::$count += \count($constraint); |
2609
|
|
|
|
2610
|
|
|
$constraint->evaluate($value, $message); |
2611
|
|
|
} |
2612
|
|
|
|
2613
|
|
|
/** |
2614
|
|
|
* Asserts that a string is a valid JSON string. |
2615
|
|
|
* |
2616
|
|
|
* @throws ExpectationFailedException |
2617
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2618
|
|
|
*/ |
2619
|
|
|
public static function assertJson(string $actualJson, string $message = ''): void |
2620
|
|
|
{ |
2621
|
|
|
static::assertThat($actualJson, static::isJson(), $message); |
2622
|
|
|
} |
2623
|
|
|
|
2624
|
|
|
/** |
2625
|
|
|
* Asserts that two given JSON encoded objects or arrays are equal. |
2626
|
|
|
* |
2627
|
|
|
* @throws ExpectationFailedException |
2628
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2629
|
|
|
*/ |
2630
|
|
|
public static function assertJsonStringEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void |
2631
|
|
|
{ |
2632
|
|
|
static::assertJson($expectedJson, $message); |
2633
|
|
|
static::assertJson($actualJson, $message); |
2634
|
|
|
|
2635
|
|
|
static::assertThat($actualJson, new JsonMatches($expectedJson), $message); |
2636
|
|
|
} |
2637
|
|
|
|
2638
|
|
|
/** |
2639
|
|
|
* Asserts that two given JSON encoded objects or arrays are not equal. |
2640
|
|
|
* |
2641
|
|
|
* @param string $expectedJson |
2642
|
|
|
* @param string $actualJson |
2643
|
|
|
* |
2644
|
|
|
* @throws ExpectationFailedException |
2645
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2646
|
|
|
*/ |
2647
|
|
|
public static function assertJsonStringNotEqualsJsonString($expectedJson, $actualJson, string $message = ''): void |
2648
|
|
|
{ |
2649
|
|
|
static::assertJson($expectedJson, $message); |
2650
|
|
|
static::assertJson($actualJson, $message); |
2651
|
|
|
|
2652
|
|
|
static::assertThat( |
2653
|
|
|
$actualJson, |
2654
|
|
|
new LogicalNot( |
2655
|
|
|
new JsonMatches($expectedJson) |
2656
|
|
|
), |
2657
|
|
|
$message |
2658
|
|
|
); |
2659
|
|
|
} |
2660
|
|
|
|
2661
|
|
|
/** |
2662
|
|
|
* Asserts that the generated JSON encoded object and the content of the given file are equal. |
2663
|
|
|
* |
2664
|
|
|
* @throws ExpectationFailedException |
2665
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2666
|
|
|
*/ |
2667
|
|
|
public static function assertJsonStringEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void |
2668
|
|
|
{ |
2669
|
|
|
static::assertFileExists($expectedFile, $message); |
2670
|
|
|
$expectedJson = \file_get_contents($expectedFile); |
2671
|
|
|
|
2672
|
|
|
static::assertJson($expectedJson, $message); |
2673
|
|
|
static::assertJson($actualJson, $message); |
2674
|
|
|
|
2675
|
|
|
static::assertThat($actualJson, new JsonMatches($expectedJson), $message); |
2676
|
|
|
} |
2677
|
|
|
|
2678
|
|
|
/** |
2679
|
|
|
* Asserts that the generated JSON encoded object and the content of the given file are not equal. |
2680
|
|
|
* |
2681
|
|
|
* @throws ExpectationFailedException |
2682
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2683
|
|
|
*/ |
2684
|
|
|
public static function assertJsonStringNotEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void |
2685
|
|
|
{ |
2686
|
|
|
static::assertFileExists($expectedFile, $message); |
2687
|
|
|
$expectedJson = \file_get_contents($expectedFile); |
2688
|
|
|
|
2689
|
|
|
static::assertJson($expectedJson, $message); |
2690
|
|
|
static::assertJson($actualJson, $message); |
2691
|
|
|
|
2692
|
|
|
static::assertThat( |
2693
|
|
|
$actualJson, |
2694
|
|
|
new LogicalNot( |
2695
|
|
|
new JsonMatches($expectedJson) |
2696
|
|
|
), |
2697
|
|
|
$message |
2698
|
|
|
); |
2699
|
|
|
} |
2700
|
|
|
|
2701
|
|
|
/** |
2702
|
|
|
* Asserts that two JSON files are equal. |
2703
|
|
|
* |
2704
|
|
|
* @throws ExpectationFailedException |
2705
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2706
|
|
|
*/ |
2707
|
|
|
public static function assertJsonFileEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void |
2708
|
|
|
{ |
2709
|
|
|
static::assertFileExists($expectedFile, $message); |
2710
|
|
|
static::assertFileExists($actualFile, $message); |
2711
|
|
|
|
2712
|
|
|
$actualJson = \file_get_contents($actualFile); |
2713
|
|
|
$expectedJson = \file_get_contents($expectedFile); |
2714
|
|
|
|
2715
|
|
|
static::assertJson($expectedJson, $message); |
2716
|
|
|
static::assertJson($actualJson, $message); |
2717
|
|
|
|
2718
|
|
|
$constraintExpected = new JsonMatches( |
2719
|
|
|
$expectedJson |
2720
|
|
|
); |
2721
|
|
|
|
2722
|
|
|
$constraintActual = new JsonMatches($actualJson); |
2723
|
|
|
|
2724
|
|
|
static::assertThat($expectedJson, $constraintActual, $message); |
2725
|
|
|
static::assertThat($actualJson, $constraintExpected, $message); |
2726
|
|
|
} |
2727
|
|
|
|
2728
|
|
|
/** |
2729
|
|
|
* Asserts that two JSON files are not equal. |
2730
|
|
|
* |
2731
|
|
|
* @throws ExpectationFailedException |
2732
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2733
|
|
|
*/ |
2734
|
|
|
public static function assertJsonFileNotEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void |
2735
|
|
|
{ |
2736
|
|
|
static::assertFileExists($expectedFile, $message); |
2737
|
|
|
static::assertFileExists($actualFile, $message); |
2738
|
|
|
|
2739
|
|
|
$actualJson = \file_get_contents($actualFile); |
2740
|
|
|
$expectedJson = \file_get_contents($expectedFile); |
2741
|
|
|
|
2742
|
|
|
static::assertJson($expectedJson, $message); |
2743
|
|
|
static::assertJson($actualJson, $message); |
2744
|
|
|
|
2745
|
|
|
$constraintExpected = new JsonMatches( |
2746
|
|
|
$expectedJson |
2747
|
|
|
); |
2748
|
|
|
|
2749
|
|
|
$constraintActual = new JsonMatches($actualJson); |
2750
|
|
|
|
2751
|
|
|
static::assertThat($expectedJson, new LogicalNot($constraintActual), $message); |
2752
|
|
|
static::assertThat($actualJson, new LogicalNot($constraintExpected), $message); |
2753
|
|
|
} |
2754
|
|
|
|
2755
|
|
|
/** |
2756
|
|
|
* @throws Exception |
2757
|
|
|
*/ |
2758
|
|
|
public static function logicalAnd(): LogicalAnd |
2759
|
|
|
{ |
2760
|
|
|
$constraints = \func_get_args(); |
2761
|
|
|
|
2762
|
|
|
$constraint = new LogicalAnd; |
2763
|
|
|
$constraint->setConstraints($constraints); |
2764
|
|
|
|
2765
|
|
|
return $constraint; |
2766
|
|
|
} |
2767
|
|
|
|
2768
|
|
|
public static function logicalOr(): LogicalOr |
2769
|
|
|
{ |
2770
|
|
|
$constraints = \func_get_args(); |
2771
|
|
|
|
2772
|
|
|
$constraint = new LogicalOr; |
2773
|
|
|
$constraint->setConstraints($constraints); |
2774
|
|
|
|
2775
|
|
|
return $constraint; |
2776
|
|
|
} |
2777
|
|
|
|
2778
|
|
|
public static function logicalNot(Constraint $constraint): LogicalNot |
2779
|
|
|
{ |
2780
|
|
|
return new LogicalNot($constraint); |
2781
|
|
|
} |
2782
|
|
|
|
2783
|
|
|
public static function logicalXor(): LogicalXor |
2784
|
|
|
{ |
2785
|
|
|
$constraints = \func_get_args(); |
2786
|
|
|
|
2787
|
|
|
$constraint = new LogicalXor; |
2788
|
|
|
$constraint->setConstraints($constraints); |
2789
|
|
|
|
2790
|
|
|
return $constraint; |
2791
|
|
|
} |
2792
|
|
|
|
2793
|
|
|
public static function anything(): IsAnything |
2794
|
|
|
{ |
2795
|
|
|
return new IsAnything; |
2796
|
|
|
} |
2797
|
|
|
|
2798
|
|
|
public static function isTrue(): IsTrue |
2799
|
|
|
{ |
2800
|
|
|
return new IsTrue; |
2801
|
|
|
} |
2802
|
|
|
|
2803
|
|
|
public static function callback(callable $callback): Callback |
2804
|
|
|
{ |
2805
|
|
|
return new Callback($callback); |
2806
|
|
|
} |
2807
|
|
|
|
2808
|
|
|
public static function isFalse(): IsFalse |
2809
|
|
|
{ |
2810
|
|
|
return new IsFalse; |
2811
|
|
|
} |
2812
|
|
|
|
2813
|
|
|
public static function isJson(): IsJson |
2814
|
|
|
{ |
2815
|
|
|
return new IsJson; |
2816
|
|
|
} |
2817
|
|
|
|
2818
|
|
|
public static function isNull(): IsNull |
2819
|
|
|
{ |
2820
|
|
|
return new IsNull; |
2821
|
|
|
} |
2822
|
|
|
|
2823
|
|
|
public static function isFinite(): IsFinite |
2824
|
|
|
{ |
2825
|
|
|
return new IsFinite; |
2826
|
|
|
} |
2827
|
|
|
|
2828
|
|
|
public static function isInfinite(): IsInfinite |
2829
|
|
|
{ |
2830
|
|
|
return new IsInfinite; |
2831
|
|
|
} |
2832
|
|
|
|
2833
|
|
|
public static function isNan(): IsNan |
2834
|
|
|
{ |
2835
|
|
|
return new IsNan; |
2836
|
|
|
} |
2837
|
|
|
|
2838
|
|
|
/** |
2839
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
2840
|
|
|
* @codeCoverageIgnore |
2841
|
|
|
*/ |
2842
|
|
|
public static function attribute(Constraint $constraint, string $attributeName): Attribute |
2843
|
|
|
{ |
2844
|
|
|
self::createWarning('attribute() is deprecated and will be removed in PHPUnit 9.'); |
2845
|
|
|
|
2846
|
|
|
return new Attribute($constraint, $attributeName); |
2847
|
|
|
} |
2848
|
|
|
|
2849
|
|
|
public static function contains($value, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): TraversableContains |
2850
|
|
|
{ |
2851
|
|
|
return new TraversableContains($value, $checkForObjectIdentity, $checkForNonObjectIdentity); |
2852
|
|
|
} |
2853
|
|
|
|
2854
|
|
|
public static function containsOnly(string $type): TraversableContainsOnly |
2855
|
|
|
{ |
2856
|
|
|
return new TraversableContainsOnly($type); |
2857
|
|
|
} |
2858
|
|
|
|
2859
|
|
|
public static function containsOnlyInstancesOf(string $className): TraversableContainsOnly |
2860
|
|
|
{ |
2861
|
|
|
return new TraversableContainsOnly($className, false); |
2862
|
|
|
} |
2863
|
|
|
|
2864
|
|
|
/** |
2865
|
|
|
* @param int|string $key |
2866
|
|
|
*/ |
2867
|
|
|
public static function arrayHasKey($key): ArrayHasKey |
2868
|
|
|
{ |
2869
|
|
|
return new ArrayHasKey($key); |
2870
|
|
|
} |
2871
|
|
|
|
2872
|
|
|
public static function equalTo($value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): IsEqual |
2873
|
|
|
{ |
2874
|
|
|
return new IsEqual($value, $delta, $maxDepth, $canonicalize, $ignoreCase); |
2875
|
|
|
} |
2876
|
|
|
|
2877
|
|
|
/** |
2878
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
2879
|
|
|
* @codeCoverageIgnore |
2880
|
|
|
*/ |
2881
|
|
|
public static function attributeEqualTo(string $attributeName, $value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): Attribute |
2882
|
|
|
{ |
2883
|
|
|
self::createWarning('attributeEqualTo() is deprecated and will be removed in PHPUnit 9.'); |
2884
|
|
|
|
2885
|
|
|
return static::attribute( |
2886
|
|
|
static::equalTo( |
2887
|
|
|
$value, |
2888
|
|
|
$delta, |
2889
|
|
|
$maxDepth, |
2890
|
|
|
$canonicalize, |
2891
|
|
|
$ignoreCase |
2892
|
|
|
), |
2893
|
|
|
$attributeName |
2894
|
|
|
); |
2895
|
|
|
} |
2896
|
|
|
|
2897
|
|
|
public static function isEmpty(): IsEmpty |
2898
|
|
|
{ |
2899
|
|
|
return new IsEmpty; |
2900
|
|
|
} |
2901
|
|
|
|
2902
|
|
|
public static function isWritable(): IsWritable |
2903
|
|
|
{ |
2904
|
|
|
return new IsWritable; |
2905
|
|
|
} |
2906
|
|
|
|
2907
|
|
|
public static function isReadable(): IsReadable |
2908
|
|
|
{ |
2909
|
|
|
return new IsReadable; |
2910
|
|
|
} |
2911
|
|
|
|
2912
|
|
|
public static function directoryExists(): DirectoryExists |
2913
|
|
|
{ |
2914
|
|
|
return new DirectoryExists; |
2915
|
|
|
} |
2916
|
|
|
|
2917
|
|
|
public static function fileExists(): FileExists |
2918
|
|
|
{ |
2919
|
|
|
return new FileExists; |
2920
|
|
|
} |
2921
|
|
|
|
2922
|
|
|
public static function greaterThan($value): GreaterThan |
2923
|
|
|
{ |
2924
|
|
|
return new GreaterThan($value); |
2925
|
|
|
} |
2926
|
|
|
|
2927
|
|
|
public static function greaterThanOrEqual($value): LogicalOr |
2928
|
|
|
{ |
2929
|
|
|
return static::logicalOr( |
2930
|
|
|
new IsEqual($value), |
2931
|
|
|
new GreaterThan($value) |
2932
|
|
|
); |
2933
|
|
|
} |
2934
|
|
|
|
2935
|
|
|
public static function classHasAttribute(string $attributeName): ClassHasAttribute |
2936
|
|
|
{ |
2937
|
|
|
return new ClassHasAttribute($attributeName); |
2938
|
|
|
} |
2939
|
|
|
|
2940
|
|
|
public static function classHasStaticAttribute(string $attributeName): ClassHasStaticAttribute |
2941
|
|
|
{ |
2942
|
|
|
return new ClassHasStaticAttribute($attributeName); |
2943
|
|
|
} |
2944
|
|
|
|
2945
|
|
|
public static function objectHasAttribute($attributeName): ObjectHasAttribute |
2946
|
|
|
{ |
2947
|
|
|
return new ObjectHasAttribute($attributeName); |
2948
|
|
|
} |
2949
|
|
|
|
2950
|
|
|
public static function identicalTo($value): IsIdentical |
2951
|
|
|
{ |
2952
|
|
|
return new IsIdentical($value); |
2953
|
|
|
} |
2954
|
|
|
|
2955
|
|
|
public static function isInstanceOf(string $className): IsInstanceOf |
2956
|
|
|
{ |
2957
|
|
|
return new IsInstanceOf($className); |
2958
|
|
|
} |
2959
|
|
|
|
2960
|
|
|
public static function isType(string $type): IsType |
2961
|
|
|
{ |
2962
|
|
|
return new IsType($type); |
2963
|
|
|
} |
2964
|
|
|
|
2965
|
|
|
public static function lessThan($value): LessThan |
2966
|
|
|
{ |
2967
|
|
|
return new LessThan($value); |
2968
|
|
|
} |
2969
|
|
|
|
2970
|
|
|
public static function lessThanOrEqual($value): LogicalOr |
2971
|
|
|
{ |
2972
|
|
|
return static::logicalOr( |
2973
|
|
|
new IsEqual($value), |
2974
|
|
|
new LessThan($value) |
2975
|
|
|
); |
2976
|
|
|
} |
2977
|
|
|
|
2978
|
|
|
public static function matchesRegularExpression(string $pattern): RegularExpression |
2979
|
|
|
{ |
2980
|
|
|
return new RegularExpression($pattern); |
2981
|
|
|
} |
2982
|
|
|
|
2983
|
|
|
public static function matches(string $string): StringMatchesFormatDescription |
2984
|
|
|
{ |
2985
|
|
|
return new StringMatchesFormatDescription($string); |
2986
|
|
|
} |
2987
|
|
|
|
2988
|
|
|
public static function stringStartsWith($prefix): StringStartsWith |
2989
|
|
|
{ |
2990
|
|
|
return new StringStartsWith($prefix); |
2991
|
|
|
} |
2992
|
|
|
|
2993
|
|
|
public static function stringContains(string $string, bool $case = true): StringContains |
2994
|
|
|
{ |
2995
|
|
|
return new StringContains($string, $case); |
2996
|
|
|
} |
2997
|
|
|
|
2998
|
|
|
public static function stringEndsWith(string $suffix): StringEndsWith |
2999
|
|
|
{ |
3000
|
|
|
return new StringEndsWith($suffix); |
3001
|
|
|
} |
3002
|
|
|
|
3003
|
|
|
public static function countOf(int $count): Count |
3004
|
|
|
{ |
3005
|
|
|
return new Count($count); |
3006
|
|
|
} |
3007
|
|
|
|
3008
|
|
|
/** |
3009
|
|
|
* Fails a test with the given message. |
3010
|
|
|
* |
3011
|
|
|
* @throws AssertionFailedError |
3012
|
|
|
*/ |
3013
|
|
|
public static function fail(string $message = ''): void |
3014
|
|
|
{ |
3015
|
|
|
self::$count++; |
3016
|
|
|
|
3017
|
|
|
throw new AssertionFailedError($message); |
3018
|
|
|
} |
3019
|
|
|
|
3020
|
|
|
/** |
3021
|
|
|
* Returns the value of an attribute of a class or an object. |
3022
|
|
|
* This also works for attributes that are declared protected or private. |
3023
|
|
|
* |
3024
|
|
|
* @param object|string $classOrObject |
3025
|
|
|
* |
3026
|
|
|
* @throws Exception |
3027
|
|
|
* @throws ReflectionException |
3028
|
|
|
* |
3029
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
3030
|
|
|
* @codeCoverageIgnore |
3031
|
|
|
*/ |
3032
|
|
|
public static function readAttribute($classOrObject, string $attributeName) |
3033
|
|
|
{ |
3034
|
|
|
self::createWarning('readAttribute() is deprecated and will be removed in PHPUnit 9.'); |
3035
|
|
|
|
3036
|
|
|
if (!self::isValidClassAttributeName($attributeName)) { |
3037
|
|
|
throw InvalidArgumentHelper::factory(2, 'valid attribute name'); |
3038
|
|
|
} |
3039
|
|
|
|
3040
|
|
|
if (\is_string($classOrObject)) { |
3041
|
|
|
if (!\class_exists($classOrObject)) { |
3042
|
|
|
throw InvalidArgumentHelper::factory( |
3043
|
|
|
1, |
3044
|
|
|
'class name' |
3045
|
|
|
); |
3046
|
|
|
} |
3047
|
|
|
|
3048
|
|
|
return static::getStaticAttribute( |
3049
|
|
|
$classOrObject, |
3050
|
|
|
$attributeName |
3051
|
|
|
); |
3052
|
|
|
} |
3053
|
|
|
|
3054
|
|
|
if (\is_object($classOrObject)) { |
3055
|
|
|
return static::getObjectAttribute( |
3056
|
|
|
$classOrObject, |
3057
|
|
|
$attributeName |
3058
|
|
|
); |
3059
|
|
|
} |
3060
|
|
|
|
3061
|
|
|
throw InvalidArgumentHelper::factory( |
3062
|
|
|
1, |
3063
|
|
|
'class name or object' |
3064
|
|
|
); |
3065
|
|
|
} |
3066
|
|
|
|
3067
|
|
|
/** |
3068
|
|
|
* Returns the value of a static attribute. |
3069
|
|
|
* This also works for attributes that are declared protected or private. |
3070
|
|
|
* |
3071
|
|
|
* @throws Exception |
3072
|
|
|
* @throws ReflectionException |
3073
|
|
|
* |
3074
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
3075
|
|
|
* @codeCoverageIgnore |
3076
|
|
|
*/ |
3077
|
|
|
public static function getStaticAttribute(string $className, string $attributeName) |
3078
|
|
|
{ |
3079
|
|
|
self::createWarning('getStaticAttribute() is deprecated and will be removed in PHPUnit 9.'); |
3080
|
|
|
|
3081
|
|
|
if (!\class_exists($className)) { |
3082
|
|
|
throw InvalidArgumentHelper::factory(1, 'class name'); |
3083
|
|
|
} |
3084
|
|
|
|
3085
|
|
|
if (!self::isValidClassAttributeName($attributeName)) { |
3086
|
|
|
throw InvalidArgumentHelper::factory(2, 'valid attribute name'); |
3087
|
|
|
} |
3088
|
|
|
|
3089
|
|
|
$class = new ReflectionClass($className); |
3090
|
|
|
|
3091
|
|
|
while ($class) { |
3092
|
|
|
$attributes = $class->getStaticProperties(); |
3093
|
|
|
|
3094
|
|
|
if (\array_key_exists($attributeName, $attributes)) { |
3095
|
|
|
return $attributes[$attributeName]; |
3096
|
|
|
} |
3097
|
|
|
|
3098
|
|
|
$class = $class->getParentClass(); |
3099
|
|
|
} |
3100
|
|
|
|
3101
|
|
|
throw new Exception( |
3102
|
|
|
\sprintf( |
3103
|
|
|
'Attribute "%s" not found in class.', |
3104
|
|
|
$attributeName |
3105
|
|
|
) |
3106
|
|
|
); |
3107
|
|
|
} |
3108
|
|
|
|
3109
|
|
|
/** |
3110
|
|
|
* Returns the value of an object's attribute. |
3111
|
|
|
* This also works for attributes that are declared protected or private. |
3112
|
|
|
* |
3113
|
|
|
* @param object $object |
3114
|
|
|
* |
3115
|
|
|
* @throws Exception |
3116
|
|
|
* |
3117
|
|
|
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 |
3118
|
|
|
* @codeCoverageIgnore |
3119
|
|
|
*/ |
3120
|
|
|
public static function getObjectAttribute($object, string $attributeName) |
3121
|
|
|
{ |
3122
|
|
|
self::createWarning('getObjectAttribute() is deprecated and will be removed in PHPUnit 9.'); |
3123
|
|
|
|
3124
|
|
|
if (!\is_object($object)) { |
3125
|
|
|
throw InvalidArgumentHelper::factory(1, 'object'); |
3126
|
|
|
} |
3127
|
|
|
|
3128
|
|
|
if (!self::isValidClassAttributeName($attributeName)) { |
3129
|
|
|
throw InvalidArgumentHelper::factory(2, 'valid attribute name'); |
3130
|
|
|
} |
3131
|
|
|
|
3132
|
|
|
try { |
3133
|
|
|
$reflector = new ReflectionObject($object); |
3134
|
|
|
|
3135
|
|
|
do { |
3136
|
|
|
try { |
3137
|
|
|
$attribute = $reflector->getProperty($attributeName); |
3138
|
|
|
|
3139
|
|
|
if (!$attribute || $attribute->isPublic()) { |
3140
|
|
|
return $object->$attributeName; |
3141
|
|
|
} |
3142
|
|
|
|
3143
|
|
|
$attribute->setAccessible(true); |
3144
|
|
|
$value = $attribute->getValue($object); |
3145
|
|
|
$attribute->setAccessible(false); |
3146
|
|
|
|
3147
|
|
|
return $value; |
3148
|
|
|
} catch (ReflectionException $e) { |
3149
|
|
|
} |
3150
|
|
|
} while ($reflector = $reflector->getParentClass()); |
3151
|
|
|
} catch (ReflectionException $e) { |
3152
|
|
|
} |
3153
|
|
|
|
3154
|
|
|
throw new Exception( |
3155
|
|
|
\sprintf( |
3156
|
|
|
'Attribute "%s" not found in object.', |
3157
|
|
|
$attributeName |
3158
|
|
|
) |
3159
|
|
|
); |
3160
|
|
|
} |
3161
|
|
|
|
3162
|
|
|
/** |
3163
|
|
|
* Mark the test as incomplete. |
3164
|
|
|
* |
3165
|
|
|
* @throws IncompleteTestError |
3166
|
|
|
*/ |
3167
|
|
|
public static function markTestIncomplete(string $message = ''): void |
3168
|
|
|
{ |
3169
|
|
|
throw new IncompleteTestError($message); |
3170
|
|
|
} |
3171
|
|
|
|
3172
|
|
|
/** |
3173
|
|
|
* Mark the test as skipped. |
3174
|
|
|
* |
3175
|
|
|
* @throws SkippedTestError |
3176
|
|
|
* @throws SyntheticSkippedError |
3177
|
|
|
*/ |
3178
|
|
|
public static function markTestSkipped(string $message = ''): void |
3179
|
|
|
{ |
3180
|
|
|
if ($hint = self::detectLocationHint($message)) { |
3181
|
|
|
$trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS); |
3182
|
|
|
\array_unshift($trace, $hint); |
3183
|
|
|
|
3184
|
|
|
throw new SyntheticSkippedError($hint['message'], 0, $hint['file'], (int) $hint['line'], $trace); |
3185
|
|
|
} |
3186
|
|
|
|
3187
|
|
|
throw new SkippedTestError($message); |
3188
|
|
|
} |
3189
|
|
|
|
3190
|
|
|
/** |
3191
|
|
|
* Return the current assertion count. |
3192
|
|
|
*/ |
3193
|
|
|
public static function getCount(): int |
3194
|
|
|
{ |
3195
|
|
|
return self::$count; |
3196
|
|
|
} |
3197
|
|
|
|
3198
|
|
|
/** |
3199
|
|
|
* Reset the assertion counter. |
3200
|
|
|
*/ |
3201
|
|
|
public static function resetCount(): void |
3202
|
|
|
{ |
3203
|
|
|
self::$count = 0; |
3204
|
|
|
} |
3205
|
|
|
|
3206
|
|
|
private static function detectLocationHint(string $message): ?array |
3207
|
|
|
{ |
3208
|
|
|
$hint = null; |
3209
|
|
|
$lines = \preg_split('/\r\n|\r|\n/', $message); |
3210
|
|
|
|
3211
|
|
|
while (\strpos($lines[0], '__OFFSET') !== false) { |
3212
|
|
|
$offset = \explode('=', \array_shift($lines)); |
3213
|
|
|
|
3214
|
|
|
if ($offset[0] === '__OFFSET_FILE') { |
3215
|
|
|
$hint['file'] = $offset[1]; |
3216
|
|
|
} |
3217
|
|
|
|
3218
|
|
|
if ($offset[0] === '__OFFSET_LINE') { |
3219
|
|
|
$hint['line'] = $offset[1]; |
3220
|
|
|
} |
3221
|
|
|
} |
3222
|
|
|
|
3223
|
|
|
if ($hint) { |
3224
|
|
|
$hint['message'] = \implode(\PHP_EOL, $lines); |
3225
|
|
|
} |
3226
|
|
|
|
3227
|
|
|
return $hint; |
3228
|
|
|
} |
3229
|
|
|
|
3230
|
|
|
private static function isValidObjectAttributeName(string $attributeName): bool |
3231
|
|
|
{ |
3232
|
|
|
return (bool) \preg_match('/[^\x00-\x1f\x7f-\x9f]+/', $attributeName); |
3233
|
|
|
} |
3234
|
|
|
|
3235
|
|
|
private static function isValidClassAttributeName(string $attributeName): bool |
3236
|
|
|
{ |
3237
|
|
|
return (bool) \preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $attributeName); |
3238
|
|
|
} |
3239
|
|
|
|
3240
|
|
|
/** |
3241
|
|
|
* @codeCoverageIgnore |
3242
|
|
|
*/ |
3243
|
|
|
private static function createWarning(string $warning): void |
3244
|
|
|
{ |
3245
|
|
|
foreach (\debug_backtrace() as $step) { |
3246
|
|
|
if (isset($step['object']) && $step['object'] instanceof TestCase) { |
3247
|
|
|
\assert($step['object'] instanceof TestCase); |
3248
|
|
|
|
3249
|
|
|
$step['object']->addWarning($warning); |
3250
|
|
|
|
3251
|
|
|
break; |
3252
|
|
|
} |
3253
|
|
|
} |
3254
|
|
|
} |
3255
|
|
|
} |
3256
|
|
|
|