1
|
|
|
<?php |
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
|
|
|
namespace PHPUnit\Framework; |
11
|
|
|
|
12
|
|
|
use PHPUnit\Util\Xml; |
13
|
|
|
|
14
|
|
|
class AssertTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public static function validInvalidJsonDataprovider(): array |
17
|
|
|
{ |
18
|
|
|
return [ |
19
|
|
|
'error syntax in expected JSON' => ['{"Mascott"::}', '{"Mascott" : "Tux"}'], |
20
|
|
|
'error UTF-8 in actual JSON' => ['{"Mascott" : "Tux"}', '{"Mascott" : :}'], |
21
|
|
|
]; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testFail(): void |
25
|
|
|
{ |
26
|
|
|
try { |
27
|
|
|
$this->fail(); |
28
|
|
|
} catch (AssertionFailedError $e) { |
29
|
|
|
return; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
throw new AssertionFailedError('Fail did not throw fail exception'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testAssertSplObjectStorageContainsObject(): void |
36
|
|
|
{ |
37
|
|
|
$a = new \stdClass; |
38
|
|
|
$b = new \stdClass; |
39
|
|
|
$c = new \SplObjectStorage; |
40
|
|
|
$c->attach($a); |
41
|
|
|
|
42
|
|
|
$this->assertContains($a, $c); |
43
|
|
|
|
44
|
|
|
$this->expectException(AssertionFailedError::class); |
45
|
|
|
|
46
|
|
|
$this->assertContains($b, $c); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testAssertArrayContainsObject(): void |
50
|
|
|
{ |
51
|
|
|
$a = new \stdClass; |
52
|
|
|
$b = new \stdClass; |
53
|
|
|
|
54
|
|
|
$this->assertContains($a, [$a]); |
55
|
|
|
|
56
|
|
|
$this->expectException(AssertionFailedError::class); |
57
|
|
|
|
58
|
|
|
$this->assertContains($a, [$b]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testAssertArrayContainsString(): void |
62
|
|
|
{ |
63
|
|
|
$this->assertContains('foo', ['foo']); |
64
|
|
|
|
65
|
|
|
$this->expectException(AssertionFailedError::class); |
66
|
|
|
|
67
|
|
|
$this->assertContains('foo', ['bar']); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testAssertArrayContainsNonObject(): void |
71
|
|
|
{ |
72
|
|
|
$this->assertContains('foo', [true]); |
73
|
|
|
|
74
|
|
|
$this->expectException(AssertionFailedError::class); |
75
|
|
|
|
76
|
|
|
$this->assertContains('foo', [true], '', false, true, true); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testAssertContainsOnlyInstancesOf(): void |
80
|
|
|
{ |
81
|
|
|
$test = [new \Book, new \Book]; |
82
|
|
|
|
83
|
|
|
$this->assertContainsOnlyInstancesOf(\Book::class, $test); |
84
|
|
|
$this->assertContainsOnlyInstancesOf(\stdClass::class, [new \stdClass]); |
85
|
|
|
|
86
|
|
|
$test2 = [new \Author('Test')]; |
87
|
|
|
|
88
|
|
|
$this->expectException(AssertionFailedError::class); |
89
|
|
|
|
90
|
|
|
$this->assertContainsOnlyInstancesOf(\Book::class, $test2); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testAssertContainsPartialStringInString(): void |
94
|
|
|
{ |
95
|
|
|
$this->assertContains('bar', 'foo bar'); |
96
|
|
|
|
97
|
|
|
$this->expectException(AssertionFailedError::class); |
98
|
|
|
|
99
|
|
|
$this->assertContains('cake', 'foo bar'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testAssertContainsNonCaseSensitiveStringInString(): void |
103
|
|
|
{ |
104
|
|
|
$this->assertContains('Foo', 'foo', '', true); |
105
|
|
|
|
106
|
|
|
$this->expectException(AssertionFailedError::class); |
107
|
|
|
|
108
|
|
|
$this->assertContains('Foo', 'foo', '', false); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function testAssertContainsEmptyStringInString(): void |
112
|
|
|
{ |
113
|
|
|
$this->assertContains('', 'test'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testAssertStringContainsNonString(): void |
117
|
|
|
{ |
118
|
|
|
$this->expectException(Exception::class); |
119
|
|
|
|
120
|
|
|
$this->assertContains(null, ''); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testAssertStringNotContainsNonString(): void |
124
|
|
|
{ |
125
|
|
|
$this->expectException(Exception::class); |
126
|
|
|
|
127
|
|
|
$this->assertNotContains(null, ''); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function testAssertArrayHasKeyThrowsExceptionForInvalidFirstArgument(): void |
131
|
|
|
{ |
132
|
|
|
$this->expectException(Exception::class); |
133
|
|
|
|
134
|
|
|
$this->assertArrayHasKey(null, []); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function testAssertArrayHasKeyThrowsExceptionForInvalidSecondArgument(): void |
138
|
|
|
{ |
139
|
|
|
$this->expectException(Exception::class); |
140
|
|
|
|
141
|
|
|
$this->assertArrayHasKey(0, null); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testAssertArrayHasIntegerKey(): void |
145
|
|
|
{ |
146
|
|
|
$this->assertArrayHasKey(0, ['foo']); |
147
|
|
|
|
148
|
|
|
$this->expectException(AssertionFailedError::class); |
149
|
|
|
|
150
|
|
|
$this->assertArrayHasKey(1, ['foo']); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function testAssertArraySubset(): void |
154
|
|
|
{ |
155
|
|
|
$array = [ |
156
|
|
|
'a' => 'item a', |
157
|
|
|
'b' => 'item b', |
158
|
|
|
'c' => ['a2' => 'item a2', 'b2' => 'item b2'], |
159
|
|
|
'd' => ['a2' => ['a3' => 'item a3', 'b3' => 'item b3']], |
160
|
|
|
]; |
161
|
|
|
|
162
|
|
|
$this->assertArraySubset(['a' => 'item a', 'c' => ['a2' => 'item a2']], $array); |
|
|
|
|
163
|
|
|
$this->assertArraySubset(['a' => 'item a', 'd' => ['a2' => ['b3' => 'item b3']]], $array); |
|
|
|
|
164
|
|
|
|
165
|
|
|
$arrayAccessData = new \ArrayObject($array); |
166
|
|
|
|
167
|
|
|
$this->assertArraySubset(['a' => 'item a', 'c' => ['a2' => 'item a2']], $arrayAccessData); |
|
|
|
|
168
|
|
|
$this->assertArraySubset(['a' => 'item a', 'd' => ['a2' => ['b3' => 'item b3']]], $arrayAccessData); |
|
|
|
|
169
|
|
|
|
170
|
|
|
try { |
171
|
|
|
$this->assertArraySubset(['a' => 'bad value'], $array); |
|
|
|
|
172
|
|
|
} catch (AssertionFailedError $e) { |
|
|
|
|
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
try { |
176
|
|
|
$this->assertArraySubset(['d' => ['a2' => ['bad index' => 'item b3']]], $array); |
|
|
|
|
177
|
|
|
} catch (AssertionFailedError $e) { |
178
|
|
|
return; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
$this->fail(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function testAssertArraySubsetWithDeepNestedArrays(): void |
185
|
|
|
{ |
186
|
|
|
$array = [ |
187
|
|
|
'path' => [ |
188
|
|
|
'to' => [ |
189
|
|
|
'the' => [ |
190
|
|
|
'cake' => 'is a lie', |
191
|
|
|
], |
192
|
|
|
], |
193
|
|
|
], |
194
|
|
|
]; |
195
|
|
|
|
196
|
|
|
$this->assertArraySubset(['path' => []], $array); |
|
|
|
|
197
|
|
|
$this->assertArraySubset(['path' => ['to' => []]], $array); |
|
|
|
|
198
|
|
|
$this->assertArraySubset(['path' => ['to' => ['the' => []]]], $array); |
|
|
|
|
199
|
|
|
$this->assertArraySubset(['path' => ['to' => ['the' => ['cake' => 'is a lie']]]], $array); |
|
|
|
|
200
|
|
|
|
201
|
|
|
$this->expectException(AssertionFailedError::class); |
202
|
|
|
|
203
|
|
|
$this->assertArraySubset(['path' => ['to' => ['the' => ['cake' => 'is not a lie']]]], $array); |
|
|
|
|
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function testAssertArraySubsetWithNoStrictCheckAndObjects(): void |
207
|
|
|
{ |
208
|
|
|
$obj = new \stdClass; |
209
|
|
|
$reference = &$obj; |
210
|
|
|
$array = ['a' => $obj]; |
211
|
|
|
|
212
|
|
|
$this->assertArraySubset(['a' => $reference], $array); |
|
|
|
|
213
|
|
|
$this->assertArraySubset(['a' => new \stdClass], $array); |
|
|
|
|
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function testAssertArraySubsetWithStrictCheckAndObjects(): void |
217
|
|
|
{ |
218
|
|
|
$obj = new \stdClass; |
219
|
|
|
$reference = &$obj; |
220
|
|
|
$array = ['a' => $obj]; |
221
|
|
|
|
222
|
|
|
$this->assertArraySubset(['a' => $reference], $array, true); |
|
|
|
|
223
|
|
|
|
224
|
|
|
$this->expectException(AssertionFailedError::class); |
225
|
|
|
|
226
|
|
|
$this->assertArraySubset(['a' => new \stdClass], $array, true); |
|
|
|
|
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @dataProvider assertArraySubsetInvalidArgumentProvider |
231
|
|
|
* |
232
|
|
|
* @throws Exception |
233
|
|
|
* @throws ExpectationFailedException |
234
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
235
|
|
|
*/ |
236
|
|
|
public function testAssertArraySubsetRaisesExceptionForInvalidArguments($partial, $subject): void |
237
|
|
|
{ |
238
|
|
|
$this->expectException(Exception::class); |
239
|
|
|
|
240
|
|
|
$this->assertArraySubset($partial, $subject); |
|
|
|
|
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
public function assertArraySubsetInvalidArgumentProvider(): array |
244
|
|
|
{ |
245
|
|
|
return [ |
246
|
|
|
[false, []], |
247
|
|
|
[[], false], |
248
|
|
|
]; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
public function testAssertArrayNotHasKeyThrowsExceptionForInvalidFirstArgument(): void |
252
|
|
|
{ |
253
|
|
|
$this->expectException(Exception::class); |
254
|
|
|
|
255
|
|
|
$this->assertArrayNotHasKey(null, []); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function testAssertArrayNotHasKeyThrowsExceptionForInvalidSecondArgument(): void |
259
|
|
|
{ |
260
|
|
|
$this->expectException(Exception::class); |
261
|
|
|
|
262
|
|
|
$this->assertArrayNotHasKey(0, null); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
public function testAssertArrayNotHasIntegerKey(): void |
266
|
|
|
{ |
267
|
|
|
$this->assertArrayNotHasKey(1, ['foo']); |
268
|
|
|
|
269
|
|
|
$this->expectException(AssertionFailedError::class); |
270
|
|
|
|
271
|
|
|
$this->assertArrayNotHasKey(0, ['foo']); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
public function testAssertArrayHasStringKey(): void |
275
|
|
|
{ |
276
|
|
|
$this->assertArrayHasKey('foo', ['foo' => 'bar']); |
277
|
|
|
|
278
|
|
|
$this->expectException(AssertionFailedError::class); |
279
|
|
|
|
280
|
|
|
$this->assertArrayHasKey('bar', ['foo' => 'bar']); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
public function testAssertArrayNotHasStringKey(): void |
284
|
|
|
{ |
285
|
|
|
$this->assertArrayNotHasKey('bar', ['foo' => 'bar']); |
286
|
|
|
|
287
|
|
|
$this->expectException(AssertionFailedError::class); |
288
|
|
|
|
289
|
|
|
$this->assertArrayNotHasKey('foo', ['foo' => 'bar']); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
public function testAssertArrayHasKeyAcceptsArrayObjectValue(): void |
293
|
|
|
{ |
294
|
|
|
$array = new \ArrayObject; |
295
|
|
|
$array['foo'] = 'bar'; |
296
|
|
|
|
297
|
|
|
$this->assertArrayHasKey('foo', $array); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
public function testAssertArrayHasKeyProperlyFailsWithArrayObjectValue(): void |
301
|
|
|
{ |
302
|
|
|
$array = new \ArrayObject; |
303
|
|
|
$array['bar'] = 'bar'; |
304
|
|
|
|
305
|
|
|
$this->expectException(AssertionFailedError::class); |
306
|
|
|
|
307
|
|
|
$this->assertArrayHasKey('foo', $array); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
public function testAssertArrayHasKeyAcceptsArrayAccessValue(): void |
311
|
|
|
{ |
312
|
|
|
$array = new \SampleArrayAccess; |
313
|
|
|
$array['foo'] = 'bar'; |
314
|
|
|
|
315
|
|
|
$this->assertArrayHasKey('foo', $array); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
public function testAssertArrayHasKeyProperlyFailsWithArrayAccessValue(): void |
319
|
|
|
{ |
320
|
|
|
$array = new \SampleArrayAccess; |
321
|
|
|
$array['bar'] = 'bar'; |
322
|
|
|
|
323
|
|
|
$this->expectException(AssertionFailedError::class); |
324
|
|
|
|
325
|
|
|
$this->assertArrayHasKey('foo', $array); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
public function testAssertArrayNotHasKeyAcceptsArrayAccessValue(): void |
329
|
|
|
{ |
330
|
|
|
$array = new \ArrayObject; |
331
|
|
|
$array['foo'] = 'bar'; |
332
|
|
|
|
333
|
|
|
$this->assertArrayNotHasKey('bar', $array); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
public function testAssertArrayNotHasKeyPropertlyFailsWithArrayAccessValue(): void |
337
|
|
|
{ |
338
|
|
|
$array = new \ArrayObject; |
339
|
|
|
$array['bar'] = 'bar'; |
340
|
|
|
|
341
|
|
|
$this->expectException(AssertionFailedError::class); |
342
|
|
|
|
343
|
|
|
$this->assertArrayNotHasKey('bar', $array); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
public function testAssertContainsThrowsException(): void |
347
|
|
|
{ |
348
|
|
|
$this->expectException(Exception::class); |
349
|
|
|
|
350
|
|
|
$this->assertContains(null, null); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
public function testAssertIteratorContainsObject(): void |
354
|
|
|
{ |
355
|
|
|
$foo = new \stdClass; |
356
|
|
|
|
357
|
|
|
$this->assertContains($foo, new \TestIterator([$foo])); |
358
|
|
|
|
359
|
|
|
$this->expectException(AssertionFailedError::class); |
360
|
|
|
|
361
|
|
|
$this->assertContains($foo, new \TestIterator([new \stdClass])); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
public function testAssertIteratorContainsString(): void |
365
|
|
|
{ |
366
|
|
|
$this->assertContains('foo', new \TestIterator(['foo'])); |
367
|
|
|
|
368
|
|
|
$this->expectException(AssertionFailedError::class); |
369
|
|
|
|
370
|
|
|
$this->assertContains('foo', new \TestIterator(['bar'])); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
public function testAssertStringContainsString(): void |
374
|
|
|
{ |
375
|
|
|
$this->assertContains('foo', 'foobar'); |
376
|
|
|
|
377
|
|
|
$this->expectException(AssertionFailedError::class); |
378
|
|
|
|
379
|
|
|
$this->assertContains('foo', 'bar'); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
public function testAssertStringContainsStringForUtf8(): void |
383
|
|
|
{ |
384
|
|
|
$this->assertContains('oryginał', 'oryginał'); |
385
|
|
|
|
386
|
|
|
$this->expectException(AssertionFailedError::class); |
387
|
|
|
|
388
|
|
|
$this->assertContains('ORYGINAŁ', 'oryginał'); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
public function testAssertStringContainsStringForUtf8WhenIgnoreCase(): void |
392
|
|
|
{ |
393
|
|
|
$this->assertContains('oryginał', 'oryginał', '', true); |
394
|
|
|
$this->assertContains('ORYGINAŁ', 'oryginał', '', true); |
395
|
|
|
|
396
|
|
|
$this->expectException(AssertionFailedError::class); |
397
|
|
|
|
398
|
|
|
$this->assertContains('foo', 'oryginał', '', true); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
public function testAssertNotContainsThrowsException(): void |
402
|
|
|
{ |
403
|
|
|
$this->expectException(Exception::class); |
404
|
|
|
|
405
|
|
|
$this->assertNotContains(null, null); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
public function testAssertSplObjectStorageNotContainsObject(): void |
409
|
|
|
{ |
410
|
|
|
$a = new \stdClass; |
411
|
|
|
$b = new \stdClass; |
412
|
|
|
$c = new \SplObjectStorage; |
413
|
|
|
$c->attach($a); |
414
|
|
|
|
415
|
|
|
$this->assertNotContains($b, $c); |
416
|
|
|
|
417
|
|
|
$this->expectException(AssertionFailedError::class); |
418
|
|
|
|
419
|
|
|
$this->assertNotContains($a, $c); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
public function testAssertArrayNotContainsObject(): void |
423
|
|
|
{ |
424
|
|
|
$a = new \stdClass; |
425
|
|
|
$b = new \stdClass; |
426
|
|
|
|
427
|
|
|
$this->assertNotContains($a, [$b]); |
428
|
|
|
|
429
|
|
|
$this->expectException(AssertionFailedError::class); |
430
|
|
|
|
431
|
|
|
$this->assertNotContains($a, [$a]); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
public function testAssertArrayNotContainsString(): void |
435
|
|
|
{ |
436
|
|
|
$this->assertNotContains('foo', ['bar']); |
437
|
|
|
|
438
|
|
|
$this->expectException(AssertionFailedError::class); |
439
|
|
|
|
440
|
|
|
$this->assertNotContains('foo', ['foo']); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
public function testAssertArrayNotContainsNonObject(): void |
444
|
|
|
{ |
445
|
|
|
$this->assertNotContains('foo', [true], '', false, true, true); |
446
|
|
|
|
447
|
|
|
$this->expectException(AssertionFailedError::class); |
448
|
|
|
|
449
|
|
|
$this->assertNotContains('foo', [true]); |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
public function testAssertStringNotContainsString(): void |
453
|
|
|
{ |
454
|
|
|
$this->assertNotContains('foo', 'bar'); |
455
|
|
|
|
456
|
|
|
$this->expectException(AssertionFailedError::class); |
457
|
|
|
|
458
|
|
|
$this->assertNotContains('foo', 'foo'); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
public function testAssertStringNotContainsStringForUtf8(): void |
462
|
|
|
{ |
463
|
|
|
$this->assertNotContains('ORYGINAŁ', 'oryginał'); |
464
|
|
|
|
465
|
|
|
$this->expectException(AssertionFailedError::class); |
466
|
|
|
|
467
|
|
|
$this->assertNotContains('oryginał', 'oryginał'); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
public function testAssertStringNotContainsStringForUtf8WhenIgnoreCase(): void |
471
|
|
|
{ |
472
|
|
|
$this->expectException(AssertionFailedError::class); |
473
|
|
|
|
474
|
|
|
$this->assertNotContains('ORYGINAŁ', 'oryginał', '', true); |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
public function testAssertArrayContainsOnlyIntegers(): void |
478
|
|
|
{ |
479
|
|
|
$this->assertContainsOnly('integer', [1, 2, 3]); |
480
|
|
|
|
481
|
|
|
$this->expectException(AssertionFailedError::class); |
482
|
|
|
|
483
|
|
|
$this->assertContainsOnly('integer', ['1', 2, 3]); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
public function testAssertArrayNotContainsOnlyIntegers(): void |
487
|
|
|
{ |
488
|
|
|
$this->assertNotContainsOnly('integer', ['1', 2, 3]); |
489
|
|
|
|
490
|
|
|
$this->expectException(AssertionFailedError::class); |
491
|
|
|
|
492
|
|
|
$this->assertNotContainsOnly('integer', [1, 2, 3]); |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
public function testAssertArrayContainsOnlyStdClass(): void |
496
|
|
|
{ |
497
|
|
|
$this->assertContainsOnly('StdClass', [new \stdClass]); |
498
|
|
|
|
499
|
|
|
$this->expectException(AssertionFailedError::class); |
500
|
|
|
|
501
|
|
|
$this->assertContainsOnly('StdClass', ['StdClass']); |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
public function testAssertArrayNotContainsOnlyStdClass(): void |
505
|
|
|
{ |
506
|
|
|
$this->assertNotContainsOnly('StdClass', ['StdClass']); |
507
|
|
|
|
508
|
|
|
$this->expectException(AssertionFailedError::class); |
509
|
|
|
|
510
|
|
|
$this->assertNotContainsOnly('StdClass', [new \stdClass]); |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
public function equalProvider(): array |
514
|
|
|
{ |
515
|
|
|
// same |= equal |
516
|
|
|
return \array_merge($this->equalValues(), $this->sameValues()); |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
public function notEqualProvider() |
520
|
|
|
{ |
521
|
|
|
return $this->notEqualValues(); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
public function sameProvider(): array |
525
|
|
|
{ |
526
|
|
|
return $this->sameValues(); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
public function notSameProvider(): array |
530
|
|
|
{ |
531
|
|
|
// not equal |= not same |
532
|
|
|
// equal, ¬same |= not same |
533
|
|
|
return \array_merge($this->notEqualValues(), $this->equalValues()); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
/** |
537
|
|
|
* @dataProvider equalProvider |
538
|
|
|
* |
539
|
|
|
* @throws ExpectationFailedException |
540
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
541
|
|
|
*/ |
542
|
|
|
public function testAssertEqualsSucceeds($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void |
543
|
|
|
{ |
544
|
|
|
$this->assertEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase); |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* @dataProvider notEqualProvider |
549
|
|
|
* |
550
|
|
|
* @throws ExpectationFailedException |
551
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
552
|
|
|
*/ |
553
|
|
|
public function testAssertEqualsFails($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void |
554
|
|
|
{ |
555
|
|
|
$this->expectException(AssertionFailedError::class); |
556
|
|
|
|
557
|
|
|
$this->assertEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* @dataProvider notEqualProvider |
562
|
|
|
* |
563
|
|
|
* @throws ExpectationFailedException |
564
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
565
|
|
|
*/ |
566
|
|
|
public function testAssertNotEqualsSucceeds($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void |
567
|
|
|
{ |
568
|
|
|
$this->assertNotEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase); |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* @dataProvider equalProvider |
573
|
|
|
* |
574
|
|
|
* @throws ExpectationFailedException |
575
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
576
|
|
|
*/ |
577
|
|
|
public function testAssertNotEqualsFails($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void |
578
|
|
|
{ |
579
|
|
|
$this->expectException(AssertionFailedError::class); |
580
|
|
|
|
581
|
|
|
$this->assertNotEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase); |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
/** |
585
|
|
|
* @dataProvider sameProvider |
586
|
|
|
* |
587
|
|
|
* @throws ExpectationFailedException |
588
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
589
|
|
|
*/ |
590
|
|
|
public function testAssertSameSucceeds($a, $b): void |
591
|
|
|
{ |
592
|
|
|
$this->assertSame($a, $b); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
/** |
596
|
|
|
* @dataProvider notSameProvider |
597
|
|
|
* |
598
|
|
|
* @throws ExpectationFailedException |
599
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
600
|
|
|
*/ |
601
|
|
|
public function testAssertSameFails($a, $b): void |
602
|
|
|
{ |
603
|
|
|
$this->expectException(AssertionFailedError::class); |
604
|
|
|
|
605
|
|
|
$this->assertSame($a, $b); |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
/** |
609
|
|
|
* @dataProvider notSameProvider |
610
|
|
|
* |
611
|
|
|
* @throws ExpectationFailedException |
612
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
613
|
|
|
*/ |
614
|
|
|
public function testAssertNotSameSucceeds($a, $b): void |
615
|
|
|
{ |
616
|
|
|
$this->assertNotSame($a, $b); |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
/** |
620
|
|
|
* @dataProvider sameProvider |
621
|
|
|
* |
622
|
|
|
* @throws ExpectationFailedException |
623
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
624
|
|
|
*/ |
625
|
|
|
public function testAssertNotSameFails($a, $b): void |
626
|
|
|
{ |
627
|
|
|
$this->expectException(AssertionFailedError::class); |
628
|
|
|
|
629
|
|
|
$this->assertNotSame($a, $b); |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
public function testAssertXmlFileEqualsXmlFile(): void |
633
|
|
|
{ |
634
|
|
|
$this->assertXmlFileEqualsXmlFile( |
635
|
|
|
TEST_FILES_PATH . 'foo.xml', |
636
|
|
|
TEST_FILES_PATH . 'foo.xml' |
637
|
|
|
); |
638
|
|
|
|
639
|
|
|
$this->expectException(AssertionFailedError::class); |
640
|
|
|
|
641
|
|
|
$this->assertXmlFileEqualsXmlFile( |
642
|
|
|
TEST_FILES_PATH . 'foo.xml', |
643
|
|
|
TEST_FILES_PATH . 'bar.xml' |
644
|
|
|
); |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
public function testAssertXmlFileNotEqualsXmlFile(): void |
648
|
|
|
{ |
649
|
|
|
$this->assertXmlFileNotEqualsXmlFile( |
650
|
|
|
TEST_FILES_PATH . 'foo.xml', |
651
|
|
|
TEST_FILES_PATH . 'bar.xml' |
652
|
|
|
); |
653
|
|
|
|
654
|
|
|
$this->expectException(AssertionFailedError::class); |
655
|
|
|
|
656
|
|
|
$this->assertXmlFileNotEqualsXmlFile( |
657
|
|
|
TEST_FILES_PATH . 'foo.xml', |
658
|
|
|
TEST_FILES_PATH . 'foo.xml' |
659
|
|
|
); |
660
|
|
|
} |
661
|
|
|
|
662
|
|
|
public function testAssertXmlStringEqualsXmlFile(): void |
663
|
|
|
{ |
664
|
|
|
$this->assertXmlStringEqualsXmlFile( |
665
|
|
|
TEST_FILES_PATH . 'foo.xml', |
666
|
|
|
\file_get_contents(TEST_FILES_PATH . 'foo.xml') |
667
|
|
|
); |
668
|
|
|
|
669
|
|
|
$this->expectException(AssertionFailedError::class); |
670
|
|
|
|
671
|
|
|
$this->assertXmlStringEqualsXmlFile( |
672
|
|
|
TEST_FILES_PATH . 'foo.xml', |
673
|
|
|
\file_get_contents(TEST_FILES_PATH . 'bar.xml') |
674
|
|
|
); |
675
|
|
|
} |
676
|
|
|
|
677
|
|
|
public function testXmlStringNotEqualsXmlFile(): void |
678
|
|
|
{ |
679
|
|
|
$this->assertXmlStringNotEqualsXmlFile( |
680
|
|
|
TEST_FILES_PATH . 'foo.xml', |
681
|
|
|
\file_get_contents(TEST_FILES_PATH . 'bar.xml') |
682
|
|
|
); |
683
|
|
|
|
684
|
|
|
$this->expectException(AssertionFailedError::class); |
685
|
|
|
|
686
|
|
|
$this->assertXmlStringNotEqualsXmlFile( |
687
|
|
|
TEST_FILES_PATH . 'foo.xml', |
688
|
|
|
\file_get_contents(TEST_FILES_PATH . 'foo.xml') |
689
|
|
|
); |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
public function testAssertXmlStringEqualsXmlString(): void |
693
|
|
|
{ |
694
|
|
|
$this->assertXmlStringEqualsXmlString('<root/>', '<root/>'); |
695
|
|
|
|
696
|
|
|
$this->expectException(AssertionFailedError::class); |
697
|
|
|
|
698
|
|
|
$this->assertXmlStringEqualsXmlString('<foo/>', '<bar/>'); |
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
/** |
702
|
|
|
* @ticket 1860 |
703
|
|
|
*/ |
704
|
|
|
public function testAssertXmlStringEqualsXmlString2(): void |
705
|
|
|
{ |
706
|
|
|
$this->expectException(Exception::class); |
707
|
|
|
|
708
|
|
|
$this->assertXmlStringEqualsXmlString('<a></b>', '<c></d>'); |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
/** |
712
|
|
|
* @ticket 1860 |
713
|
|
|
*/ |
714
|
|
|
public function testAssertXmlStringEqualsXmlString3(): void |
715
|
|
|
{ |
716
|
|
|
$expected = <<<XML |
717
|
|
|
<?xml version="1.0"?> |
718
|
|
|
<root> |
719
|
|
|
<node /> |
720
|
|
|
</root> |
721
|
|
|
XML; |
722
|
|
|
|
723
|
|
|
$actual = <<<XML |
724
|
|
|
<?xml version="1.0"?> |
725
|
|
|
<root> |
726
|
|
|
<node /> |
727
|
|
|
</root> |
728
|
|
|
XML; |
729
|
|
|
|
730
|
|
|
$this->assertXmlStringEqualsXmlString($expected, $actual); |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
public function testAssertXmlStringNotEqualsXmlString(): void |
734
|
|
|
{ |
735
|
|
|
$this->assertXmlStringNotEqualsXmlString('<foo/>', '<bar/>'); |
736
|
|
|
|
737
|
|
|
$this->expectException(AssertionFailedError::class); |
738
|
|
|
|
739
|
|
|
$this->assertXmlStringNotEqualsXmlString('<root/>', '<root/>'); |
740
|
|
|
} |
741
|
|
|
|
742
|
|
|
public function testXMLStructureIsSame(): void |
743
|
|
|
{ |
744
|
|
|
$expected = new \DOMDocument; |
745
|
|
|
$expected->load(TEST_FILES_PATH . 'structureExpected.xml'); |
746
|
|
|
|
747
|
|
|
$actual = new \DOMDocument; |
748
|
|
|
$actual->load(TEST_FILES_PATH . 'structureExpected.xml'); |
749
|
|
|
|
750
|
|
|
$this->assertEqualXMLStructure( |
751
|
|
|
$expected->firstChild, |
|
|
|
|
752
|
|
|
$actual->firstChild, |
|
|
|
|
753
|
|
|
true |
754
|
|
|
); |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
public function testXMLStructureWrongNumberOfAttributes(): void |
758
|
|
|
{ |
759
|
|
|
$expected = new \DOMDocument; |
760
|
|
|
$expected->load(TEST_FILES_PATH . 'structureExpected.xml'); |
761
|
|
|
|
762
|
|
|
$actual = new \DOMDocument; |
763
|
|
|
$actual->load(TEST_FILES_PATH . 'structureWrongNumberOfAttributes.xml'); |
764
|
|
|
|
765
|
|
|
$this->expectException(ExpectationFailedException::class); |
766
|
|
|
|
767
|
|
|
$this->assertEqualXMLStructure( |
768
|
|
|
$expected->firstChild, |
|
|
|
|
769
|
|
|
$actual->firstChild, |
|
|
|
|
770
|
|
|
true |
771
|
|
|
); |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
public function testXMLStructureWrongNumberOfNodes(): void |
775
|
|
|
{ |
776
|
|
|
$expected = new \DOMDocument; |
777
|
|
|
$expected->load(TEST_FILES_PATH . 'structureExpected.xml'); |
778
|
|
|
|
779
|
|
|
$actual = new \DOMDocument; |
780
|
|
|
$actual->load(TEST_FILES_PATH . 'structureWrongNumberOfNodes.xml'); |
781
|
|
|
|
782
|
|
|
$this->expectException(ExpectationFailedException::class); |
783
|
|
|
|
784
|
|
|
$this->assertEqualXMLStructure( |
785
|
|
|
$expected->firstChild, |
|
|
|
|
786
|
|
|
$actual->firstChild, |
|
|
|
|
787
|
|
|
true |
788
|
|
|
); |
789
|
|
|
} |
790
|
|
|
|
791
|
|
|
public function testXMLStructureIsSameButDataIsNot(): void |
792
|
|
|
{ |
793
|
|
|
$expected = new \DOMDocument; |
794
|
|
|
$expected->load(TEST_FILES_PATH . 'structureExpected.xml'); |
795
|
|
|
|
796
|
|
|
$actual = new \DOMDocument; |
797
|
|
|
$actual->load(TEST_FILES_PATH . 'structureIsSameButDataIsNot.xml'); |
798
|
|
|
|
799
|
|
|
$this->assertEqualXMLStructure( |
800
|
|
|
$expected->firstChild, |
|
|
|
|
801
|
|
|
$actual->firstChild, |
|
|
|
|
802
|
|
|
true |
803
|
|
|
); |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
public function testXMLStructureAttributesAreSameButValuesAreNot(): void |
807
|
|
|
{ |
808
|
|
|
$expected = new \DOMDocument; |
809
|
|
|
$expected->load(TEST_FILES_PATH . 'structureExpected.xml'); |
810
|
|
|
|
811
|
|
|
$actual = new \DOMDocument; |
812
|
|
|
$actual->load(TEST_FILES_PATH . 'structureAttributesAreSameButValuesAreNot.xml'); |
813
|
|
|
|
814
|
|
|
$this->assertEqualXMLStructure( |
815
|
|
|
$expected->firstChild, |
|
|
|
|
816
|
|
|
$actual->firstChild, |
|
|
|
|
817
|
|
|
true |
818
|
|
|
); |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
public function testXMLStructureIgnoreTextNodes(): void |
822
|
|
|
{ |
823
|
|
|
$expected = new \DOMDocument; |
824
|
|
|
$expected->load(TEST_FILES_PATH . 'structureExpected.xml'); |
825
|
|
|
|
826
|
|
|
$actual = new \DOMDocument; |
827
|
|
|
$actual->load(TEST_FILES_PATH . 'structureIgnoreTextNodes.xml'); |
828
|
|
|
|
829
|
|
|
$this->assertEqualXMLStructure( |
830
|
|
|
$expected->firstChild, |
|
|
|
|
831
|
|
|
$actual->firstChild, |
|
|
|
|
832
|
|
|
true |
833
|
|
|
); |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
public function testAssertStringEqualsNumeric(): void |
837
|
|
|
{ |
838
|
|
|
$this->assertEquals('0', 0); |
839
|
|
|
|
840
|
|
|
$this->expectException(AssertionFailedError::class); |
841
|
|
|
|
842
|
|
|
$this->assertEquals('0', 1); |
843
|
|
|
} |
844
|
|
|
|
845
|
|
|
public function testAssertStringEqualsNumeric2(): void |
846
|
|
|
{ |
847
|
|
|
$this->assertNotEquals('A', 0); |
848
|
|
|
} |
849
|
|
|
|
850
|
|
|
public function testAssertIsReadable(): void |
851
|
|
|
{ |
852
|
|
|
$this->assertIsReadable(__FILE__); |
853
|
|
|
|
854
|
|
|
$this->expectException(AssertionFailedError::class); |
855
|
|
|
|
856
|
|
|
$this->assertIsReadable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
857
|
|
|
} |
858
|
|
|
|
859
|
|
|
public function testAssertNotIsReadable(): void |
860
|
|
|
{ |
861
|
|
|
$this->assertNotIsReadable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
862
|
|
|
|
863
|
|
|
$this->expectException(AssertionFailedError::class); |
864
|
|
|
|
865
|
|
|
$this->assertNotIsReadable(__FILE__); |
866
|
|
|
} |
867
|
|
|
|
868
|
|
|
public function testAssertIsWritable(): void |
869
|
|
|
{ |
870
|
|
|
$this->assertIsWritable(__FILE__); |
871
|
|
|
|
872
|
|
|
$this->expectException(AssertionFailedError::class); |
873
|
|
|
|
874
|
|
|
$this->assertIsWritable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
875
|
|
|
} |
876
|
|
|
|
877
|
|
|
public function testAssertNotIsWritable(): void |
878
|
|
|
{ |
879
|
|
|
$this->assertNotIsWritable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
880
|
|
|
|
881
|
|
|
$this->expectException(AssertionFailedError::class); |
882
|
|
|
|
883
|
|
|
$this->assertNotIsWritable(__FILE__); |
884
|
|
|
} |
885
|
|
|
|
886
|
|
|
public function testAssertDirectoryExists(): void |
887
|
|
|
{ |
888
|
|
|
$this->assertDirectoryExists(__DIR__); |
889
|
|
|
|
890
|
|
|
$this->expectException(AssertionFailedError::class); |
891
|
|
|
|
892
|
|
|
$this->assertDirectoryExists(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
893
|
|
|
} |
894
|
|
|
|
895
|
|
|
public function testAssertDirectoryNotExists(): void |
896
|
|
|
{ |
897
|
|
|
$this->assertDirectoryNotExists(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
898
|
|
|
|
899
|
|
|
$this->expectException(AssertionFailedError::class); |
900
|
|
|
|
901
|
|
|
$this->assertDirectoryNotExists(__DIR__); |
902
|
|
|
} |
903
|
|
|
|
904
|
|
|
public function testAssertDirectoryIsReadable(): void |
905
|
|
|
{ |
906
|
|
|
$this->assertDirectoryIsReadable(__DIR__); |
907
|
|
|
|
908
|
|
|
$this->expectException(AssertionFailedError::class); |
909
|
|
|
|
910
|
|
|
$this->assertDirectoryIsReadable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
911
|
|
|
} |
912
|
|
|
|
913
|
|
|
public function testAssertDirectoryIsWritable(): void |
914
|
|
|
{ |
915
|
|
|
$this->assertDirectoryIsWritable(__DIR__); |
916
|
|
|
|
917
|
|
|
$this->expectException(AssertionFailedError::class); |
918
|
|
|
|
919
|
|
|
$this->assertDirectoryIsWritable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
920
|
|
|
} |
921
|
|
|
|
922
|
|
|
public function testAssertFileExists(): void |
923
|
|
|
{ |
924
|
|
|
$this->assertFileExists(__FILE__); |
925
|
|
|
|
926
|
|
|
$this->expectException(AssertionFailedError::class); |
927
|
|
|
|
928
|
|
|
$this->assertFileExists(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
929
|
|
|
} |
930
|
|
|
|
931
|
|
|
public function testAssertFileNotExists(): void |
932
|
|
|
{ |
933
|
|
|
$this->assertFileNotExists(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
934
|
|
|
|
935
|
|
|
$this->expectException(AssertionFailedError::class); |
936
|
|
|
|
937
|
|
|
$this->assertFileNotExists(__FILE__); |
938
|
|
|
} |
939
|
|
|
|
940
|
|
|
public function testAssertFileIsReadable(): void |
941
|
|
|
{ |
942
|
|
|
$this->assertFileIsReadable(__FILE__); |
943
|
|
|
|
944
|
|
|
$this->expectException(AssertionFailedError::class); |
945
|
|
|
|
946
|
|
|
$this->assertFileIsReadable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
947
|
|
|
} |
948
|
|
|
|
949
|
|
|
public function testAssertFileIsWritable(): void |
950
|
|
|
{ |
951
|
|
|
$this->assertFileIsWritable(__FILE__); |
952
|
|
|
|
953
|
|
|
$this->expectException(AssertionFailedError::class); |
954
|
|
|
|
955
|
|
|
$this->assertFileIsWritable(__DIR__ . \DIRECTORY_SEPARATOR . 'NotExisting'); |
956
|
|
|
} |
957
|
|
|
|
958
|
|
|
public function testAssertObjectHasAttribute(): void |
959
|
|
|
{ |
960
|
|
|
$o = new \Author('Terry Pratchett'); |
961
|
|
|
|
962
|
|
|
$this->assertObjectHasAttribute('name', $o); |
963
|
|
|
|
964
|
|
|
$this->expectException(AssertionFailedError::class); |
965
|
|
|
|
966
|
|
|
$this->assertObjectHasAttribute('foo', $o); |
967
|
|
|
} |
968
|
|
|
|
969
|
|
|
public function testAssertObjectHasAttributeNumericAttribute(): void |
970
|
|
|
{ |
971
|
|
|
$object = new \stdClass; |
972
|
|
|
$object->{'2020'} = 'Tokyo'; |
973
|
|
|
|
974
|
|
|
$this->assertObjectHasAttribute('2020', $object); |
975
|
|
|
|
976
|
|
|
$this->expectException(AssertionFailedError::class); |
977
|
|
|
|
978
|
|
|
$this->assertObjectHasAttribute('2018', $object); |
979
|
|
|
} |
980
|
|
|
|
981
|
|
|
public function testAssertObjectHasAttributeMultiByteAttribute(): void |
982
|
|
|
{ |
983
|
|
|
$object = new \stdClass; |
984
|
|
|
$object->{'東京'} = 2020; |
985
|
|
|
|
986
|
|
|
$this->assertObjectHasAttribute('東京', $object); |
987
|
|
|
|
988
|
|
|
$this->expectException(AssertionFailedError::class); |
989
|
|
|
|
990
|
|
|
$this->assertObjectHasAttribute('長野', $object); |
991
|
|
|
} |
992
|
|
|
|
993
|
|
|
public function testAssertObjectNotHasAttribute(): void |
994
|
|
|
{ |
995
|
|
|
$o = new \Author('Terry Pratchett'); |
996
|
|
|
|
997
|
|
|
$this->assertObjectNotHasAttribute('foo', $o); |
998
|
|
|
|
999
|
|
|
$this->expectException(AssertionFailedError::class); |
1000
|
|
|
|
1001
|
|
|
$this->assertObjectNotHasAttribute('name', $o); |
1002
|
|
|
} |
1003
|
|
|
|
1004
|
|
|
public function testAssertObjectNotHasAttributeNumericAttribute(): void |
1005
|
|
|
{ |
1006
|
|
|
$object = new \stdClass; |
1007
|
|
|
$object->{'2020'} = 'Tokyo'; |
1008
|
|
|
|
1009
|
|
|
$this->assertObjectNotHasAttribute('2018', $object); |
1010
|
|
|
|
1011
|
|
|
$this->expectException(AssertionFailedError::class); |
1012
|
|
|
|
1013
|
|
|
$this->assertObjectNotHasAttribute('2020', $object); |
1014
|
|
|
} |
1015
|
|
|
|
1016
|
|
|
public function testAssertObjectNotHasAttributeMultiByteAttribute(): void |
1017
|
|
|
{ |
1018
|
|
|
$object = new \stdClass; |
1019
|
|
|
$object->{'東京'} = 2020; |
1020
|
|
|
|
1021
|
|
|
$this->assertObjectNotHasAttribute('長野', $object); |
1022
|
|
|
|
1023
|
|
|
$this->expectException(AssertionFailedError::class); |
1024
|
|
|
|
1025
|
|
|
$this->assertObjectNotHasAttribute('東京', $object); |
1026
|
|
|
} |
1027
|
|
|
|
1028
|
|
|
public function testAssertFinite(): void |
1029
|
|
|
{ |
1030
|
|
|
$this->assertFinite(1); |
1031
|
|
|
|
1032
|
|
|
$this->expectException(AssertionFailedError::class); |
1033
|
|
|
|
1034
|
|
|
$this->assertFinite(\INF); |
1035
|
|
|
} |
1036
|
|
|
|
1037
|
|
|
public function testAssertInfinite(): void |
1038
|
|
|
{ |
1039
|
|
|
$this->assertInfinite(\INF); |
1040
|
|
|
|
1041
|
|
|
$this->expectException(AssertionFailedError::class); |
1042
|
|
|
|
1043
|
|
|
$this->assertInfinite(1); |
1044
|
|
|
} |
1045
|
|
|
|
1046
|
|
|
public function testAssertNan(): void |
1047
|
|
|
{ |
1048
|
|
|
$this->assertNan(\NAN); |
1049
|
|
|
|
1050
|
|
|
$this->expectException(AssertionFailedError::class); |
1051
|
|
|
|
1052
|
|
|
$this->assertNan(1); |
1053
|
|
|
} |
1054
|
|
|
|
1055
|
|
|
public function testAssertNull(): void |
1056
|
|
|
{ |
1057
|
|
|
$this->assertNull(null); |
1058
|
|
|
|
1059
|
|
|
$this->expectException(AssertionFailedError::class); |
1060
|
|
|
|
1061
|
|
|
$this->assertNull(new \stdClass); |
1062
|
|
|
} |
1063
|
|
|
|
1064
|
|
|
public function testAssertNotNull(): void |
1065
|
|
|
{ |
1066
|
|
|
$this->assertNotNull(new \stdClass); |
1067
|
|
|
|
1068
|
|
|
$this->expectException(AssertionFailedError::class); |
1069
|
|
|
|
1070
|
|
|
$this->assertNotNull(null); |
1071
|
|
|
} |
1072
|
|
|
|
1073
|
|
|
public function testAssertTrue(): void |
1074
|
|
|
{ |
1075
|
|
|
$this->assertTrue(true); |
1076
|
|
|
|
1077
|
|
|
$this->expectException(AssertionFailedError::class); |
1078
|
|
|
|
1079
|
|
|
$this->assertTrue(false); |
1080
|
|
|
} |
1081
|
|
|
|
1082
|
|
|
public function testAssertNotTrue(): void |
1083
|
|
|
{ |
1084
|
|
|
$this->assertNotTrue(false); |
1085
|
|
|
$this->assertNotTrue(1); |
1086
|
|
|
$this->assertNotTrue('true'); |
1087
|
|
|
|
1088
|
|
|
$this->expectException(AssertionFailedError::class); |
1089
|
|
|
|
1090
|
|
|
$this->assertNotTrue(true); |
1091
|
|
|
} |
1092
|
|
|
|
1093
|
|
|
public function testAssertFalse(): void |
1094
|
|
|
{ |
1095
|
|
|
$this->assertFalse(false); |
1096
|
|
|
|
1097
|
|
|
$this->expectException(AssertionFailedError::class); |
1098
|
|
|
|
1099
|
|
|
$this->assertFalse(true); |
1100
|
|
|
} |
1101
|
|
|
|
1102
|
|
|
public function testAssertNotFalse(): void |
1103
|
|
|
{ |
1104
|
|
|
$this->assertNotFalse(true); |
1105
|
|
|
$this->assertNotFalse(0); |
1106
|
|
|
$this->assertNotFalse(''); |
1107
|
|
|
|
1108
|
|
|
$this->expectException(AssertionFailedError::class); |
1109
|
|
|
|
1110
|
|
|
$this->assertNotFalse(false); |
1111
|
|
|
} |
1112
|
|
|
|
1113
|
|
|
public function testAssertRegExp(): void |
1114
|
|
|
{ |
1115
|
|
|
$this->assertRegExp('/foo/', 'foobar'); |
1116
|
|
|
|
1117
|
|
|
$this->expectException(AssertionFailedError::class); |
1118
|
|
|
|
1119
|
|
|
$this->assertRegExp('/foo/', 'bar'); |
1120
|
|
|
} |
1121
|
|
|
|
1122
|
|
|
public function testAssertNotRegExp(): void |
1123
|
|
|
{ |
1124
|
|
|
$this->assertNotRegExp('/foo/', 'bar'); |
1125
|
|
|
|
1126
|
|
|
$this->expectException(AssertionFailedError::class); |
1127
|
|
|
|
1128
|
|
|
$this->assertNotRegExp('/foo/', 'foobar'); |
1129
|
|
|
} |
1130
|
|
|
|
1131
|
|
|
public function testAssertSame(): void |
1132
|
|
|
{ |
1133
|
|
|
$o = new \stdClass; |
1134
|
|
|
|
1135
|
|
|
$this->assertSame($o, $o); |
1136
|
|
|
|
1137
|
|
|
$this->expectException(AssertionFailedError::class); |
1138
|
|
|
|
1139
|
|
|
$this->assertSame(new \stdClass, new \stdClass); |
1140
|
|
|
} |
1141
|
|
|
|
1142
|
|
|
public function testAssertSame2(): void |
1143
|
|
|
{ |
1144
|
|
|
$this->assertSame(true, true); |
1145
|
|
|
$this->assertSame(false, false); |
1146
|
|
|
|
1147
|
|
|
$this->expectException(AssertionFailedError::class); |
1148
|
|
|
|
1149
|
|
|
$this->assertSame(true, false); |
1150
|
|
|
} |
1151
|
|
|
|
1152
|
|
|
public function testAssertNotSame(): void |
1153
|
|
|
{ |
1154
|
|
|
$this->assertNotSame( |
1155
|
|
|
new \stdClass, |
1156
|
|
|
null |
1157
|
|
|
); |
1158
|
|
|
|
1159
|
|
|
$this->assertNotSame( |
1160
|
|
|
null, |
1161
|
|
|
new \stdClass |
1162
|
|
|
); |
1163
|
|
|
|
1164
|
|
|
$this->assertNotSame( |
1165
|
|
|
new \stdClass, |
1166
|
|
|
new \stdClass |
1167
|
|
|
); |
1168
|
|
|
|
1169
|
|
|
$o = new \stdClass; |
1170
|
|
|
|
1171
|
|
|
$this->expectException(AssertionFailedError::class); |
1172
|
|
|
|
1173
|
|
|
$this->assertNotSame($o, $o); |
1174
|
|
|
} |
1175
|
|
|
|
1176
|
|
|
public function testAssertNotSame2(): void |
1177
|
|
|
{ |
1178
|
|
|
$this->assertNotSame(true, false); |
1179
|
|
|
$this->assertNotSame(false, true); |
1180
|
|
|
|
1181
|
|
|
$this->expectException(AssertionFailedError::class); |
1182
|
|
|
|
1183
|
|
|
$this->assertNotSame(true, true); |
1184
|
|
|
} |
1185
|
|
|
|
1186
|
|
|
public function testAssertNotSameFailsNull(): void |
1187
|
|
|
{ |
1188
|
|
|
$this->expectException(AssertionFailedError::class); |
1189
|
|
|
|
1190
|
|
|
$this->assertNotSame(null, null); |
1191
|
|
|
} |
1192
|
|
|
|
1193
|
|
|
public function testGreaterThan(): void |
1194
|
|
|
{ |
1195
|
|
|
$this->assertGreaterThan(1, 2); |
1196
|
|
|
|
1197
|
|
|
$this->expectException(AssertionFailedError::class); |
1198
|
|
|
|
1199
|
|
|
$this->assertGreaterThan(2, 1); |
1200
|
|
|
} |
1201
|
|
|
|
1202
|
|
|
public function testAttributeGreaterThan(): void |
1203
|
|
|
{ |
1204
|
|
|
$this->assertAttributeGreaterThan( |
|
|
|
|
1205
|
|
|
1, |
1206
|
|
|
'bar', |
1207
|
|
|
new \ClassWithNonPublicAttributes |
1208
|
|
|
); |
1209
|
|
|
|
1210
|
|
|
$this->expectException(AssertionFailedError::class); |
1211
|
|
|
|
1212
|
|
|
$this->assertAttributeGreaterThan( |
|
|
|
|
1213
|
|
|
1, |
1214
|
|
|
'foo', |
1215
|
|
|
new \ClassWithNonPublicAttributes |
1216
|
|
|
); |
1217
|
|
|
} |
1218
|
|
|
|
1219
|
|
|
public function testGreaterThanOrEqual(): void |
1220
|
|
|
{ |
1221
|
|
|
$this->assertGreaterThanOrEqual(1, 2); |
1222
|
|
|
|
1223
|
|
|
$this->expectException(AssertionFailedError::class); |
1224
|
|
|
|
1225
|
|
|
$this->assertGreaterThanOrEqual(2, 1); |
1226
|
|
|
} |
1227
|
|
|
|
1228
|
|
|
public function testAttributeGreaterThanOrEqual(): void |
1229
|
|
|
{ |
1230
|
|
|
$this->assertAttributeGreaterThanOrEqual( |
|
|
|
|
1231
|
|
|
1, |
1232
|
|
|
'bar', |
1233
|
|
|
new \ClassWithNonPublicAttributes |
1234
|
|
|
); |
1235
|
|
|
|
1236
|
|
|
$this->expectException(AssertionFailedError::class); |
1237
|
|
|
|
1238
|
|
|
$this->assertAttributeGreaterThanOrEqual( |
|
|
|
|
1239
|
|
|
2, |
1240
|
|
|
'foo', |
1241
|
|
|
new \ClassWithNonPublicAttributes |
1242
|
|
|
); |
1243
|
|
|
} |
1244
|
|
|
|
1245
|
|
|
public function testLessThan(): void |
1246
|
|
|
{ |
1247
|
|
|
$this->assertLessThan(2, 1); |
1248
|
|
|
|
1249
|
|
|
try { |
1250
|
|
|
$this->assertLessThan(1, 2); |
1251
|
|
|
} catch (AssertionFailedError $e) { |
1252
|
|
|
return; |
1253
|
|
|
} |
1254
|
|
|
|
1255
|
|
|
$this->fail(); |
1256
|
|
|
} |
1257
|
|
|
|
1258
|
|
|
public function testAttributeLessThan(): void |
1259
|
|
|
{ |
1260
|
|
|
$this->assertAttributeLessThan( |
|
|
|
|
1261
|
|
|
2, |
1262
|
|
|
'foo', |
1263
|
|
|
new \ClassWithNonPublicAttributes |
1264
|
|
|
); |
1265
|
|
|
|
1266
|
|
|
$this->expectException(AssertionFailedError::class); |
1267
|
|
|
|
1268
|
|
|
$this->assertAttributeLessThan( |
|
|
|
|
1269
|
|
|
1, |
1270
|
|
|
'bar', |
1271
|
|
|
new \ClassWithNonPublicAttributes |
1272
|
|
|
); |
1273
|
|
|
} |
1274
|
|
|
|
1275
|
|
|
public function testLessThanOrEqual(): void |
1276
|
|
|
{ |
1277
|
|
|
$this->assertLessThanOrEqual(2, 1); |
1278
|
|
|
|
1279
|
|
|
$this->expectException(AssertionFailedError::class); |
1280
|
|
|
|
1281
|
|
|
$this->assertLessThanOrEqual(1, 2); |
1282
|
|
|
} |
1283
|
|
|
|
1284
|
|
|
public function testAttributeLessThanOrEqual(): void |
1285
|
|
|
{ |
1286
|
|
|
$this->assertAttributeLessThanOrEqual( |
|
|
|
|
1287
|
|
|
2, |
1288
|
|
|
'foo', |
1289
|
|
|
new \ClassWithNonPublicAttributes |
1290
|
|
|
); |
1291
|
|
|
|
1292
|
|
|
$this->expectException(AssertionFailedError::class); |
1293
|
|
|
|
1294
|
|
|
$this->assertAttributeLessThanOrEqual( |
|
|
|
|
1295
|
|
|
1, |
1296
|
|
|
'bar', |
1297
|
|
|
new \ClassWithNonPublicAttributes |
1298
|
|
|
); |
1299
|
|
|
} |
1300
|
|
|
|
1301
|
|
|
public function testReadAttribute(): void |
1302
|
|
|
{ |
1303
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1304
|
|
|
|
1305
|
|
|
$this->assertEquals('foo', $this->readAttribute($obj, 'publicAttribute')); |
|
|
|
|
1306
|
|
|
$this->assertEquals('bar', $this->readAttribute($obj, 'protectedAttribute')); |
|
|
|
|
1307
|
|
|
$this->assertEquals('baz', $this->readAttribute($obj, 'privateAttribute')); |
|
|
|
|
1308
|
|
|
$this->assertEquals('bar', $this->readAttribute($obj, 'protectedParentAttribute')); |
|
|
|
|
1309
|
|
|
//$this->assertEquals('bar', $this->readAttribute($obj, 'privateParentAttribute')); |
1310
|
|
|
} |
1311
|
|
|
|
1312
|
|
|
public function testReadAttribute2(): void |
1313
|
|
|
{ |
1314
|
|
|
$this->assertEquals('foo', $this->readAttribute(\ClassWithNonPublicAttributes::class, 'publicStaticAttribute')); |
|
|
|
|
1315
|
|
|
$this->assertEquals('bar', $this->readAttribute(\ClassWithNonPublicAttributes::class, 'protectedStaticAttribute')); |
|
|
|
|
1316
|
|
|
$this->assertEquals('baz', $this->readAttribute(\ClassWithNonPublicAttributes::class, 'privateStaticAttribute')); |
|
|
|
|
1317
|
|
|
$this->assertEquals('foo', $this->readAttribute(\ClassWithNonPublicAttributes::class, 'protectedStaticParentAttribute')); |
|
|
|
|
1318
|
|
|
$this->assertEquals('foo', $this->readAttribute(\ClassWithNonPublicAttributes::class, 'privateStaticParentAttribute')); |
|
|
|
|
1319
|
|
|
} |
1320
|
|
|
|
1321
|
|
|
public function testReadAttribute4(): void |
1322
|
|
|
{ |
1323
|
|
|
$this->expectException(Exception::class); |
1324
|
|
|
|
1325
|
|
|
$this->readAttribute('NotExistingClass', 'foo'); |
|
|
|
|
1326
|
|
|
} |
1327
|
|
|
|
1328
|
|
|
public function testReadAttribute5(): void |
1329
|
|
|
{ |
1330
|
|
|
$this->expectException(Exception::class); |
1331
|
|
|
|
1332
|
|
|
$this->readAttribute(null, 'foo'); |
|
|
|
|
1333
|
|
|
} |
1334
|
|
|
|
1335
|
|
|
public function testReadAttributeIfAttributeNameIsNotValid(): void |
1336
|
|
|
{ |
1337
|
|
|
$this->expectException(Exception::class); |
1338
|
|
|
|
1339
|
|
|
$this->readAttribute(\stdClass::class, '2'); |
|
|
|
|
1340
|
|
|
} |
1341
|
|
|
|
1342
|
|
|
public function testGetStaticAttributeRaisesExceptionForInvalidFirstArgument2(): void |
1343
|
|
|
{ |
1344
|
|
|
$this->expectException(Exception::class); |
1345
|
|
|
|
1346
|
|
|
$this->getStaticAttribute('NotExistingClass', 'foo'); |
|
|
|
|
1347
|
|
|
} |
1348
|
|
|
|
1349
|
|
|
public function testGetStaticAttributeRaisesExceptionForInvalidSecondArgument2(): void |
1350
|
|
|
{ |
1351
|
|
|
$this->expectException(Exception::class); |
1352
|
|
|
|
1353
|
|
|
$this->getStaticAttribute(\stdClass::class, '0'); |
|
|
|
|
1354
|
|
|
} |
1355
|
|
|
|
1356
|
|
|
public function testGetStaticAttributeRaisesExceptionForInvalidSecondArgument3(): void |
1357
|
|
|
{ |
1358
|
|
|
$this->expectException(Exception::class); |
1359
|
|
|
|
1360
|
|
|
$this->getStaticAttribute(\stdClass::class, 'foo'); |
|
|
|
|
1361
|
|
|
} |
1362
|
|
|
|
1363
|
|
|
public function testGetObjectAttributeRaisesExceptionForInvalidFirstArgument(): void |
1364
|
|
|
{ |
1365
|
|
|
$this->expectException(Exception::class); |
1366
|
|
|
|
1367
|
|
|
$this->getObjectAttribute(null, 'foo'); |
|
|
|
|
1368
|
|
|
} |
1369
|
|
|
|
1370
|
|
|
public function testGetObjectAttributeRaisesExceptionForInvalidSecondArgument2(): void |
1371
|
|
|
{ |
1372
|
|
|
$this->expectException(Exception::class); |
1373
|
|
|
|
1374
|
|
|
$this->getObjectAttribute(new \stdClass, '0'); |
|
|
|
|
1375
|
|
|
} |
1376
|
|
|
|
1377
|
|
|
public function testGetObjectAttributeRaisesExceptionForInvalidSecondArgument3(): void |
1378
|
|
|
{ |
1379
|
|
|
$this->expectException(Exception::class); |
1380
|
|
|
|
1381
|
|
|
$this->getObjectAttribute(new \stdClass, 'foo'); |
|
|
|
|
1382
|
|
|
} |
1383
|
|
|
|
1384
|
|
|
public function testGetObjectAttributeWorksForInheritedAttributes(): void |
1385
|
|
|
{ |
1386
|
|
|
$this->assertEquals( |
1387
|
|
|
'bar', |
1388
|
|
|
$this->getObjectAttribute(new \ClassWithNonPublicAttributes, 'privateParentAttribute') |
|
|
|
|
1389
|
|
|
); |
1390
|
|
|
} |
1391
|
|
|
|
1392
|
|
|
public function testAssertPublicAttributeContains(): void |
1393
|
|
|
{ |
1394
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1395
|
|
|
|
1396
|
|
|
$this->assertAttributeContains('foo', 'publicArray', $obj); |
|
|
|
|
1397
|
|
|
|
1398
|
|
|
$this->expectException(AssertionFailedError::class); |
1399
|
|
|
|
1400
|
|
|
$this->assertAttributeContains('bar', 'publicArray', $obj); |
|
|
|
|
1401
|
|
|
} |
1402
|
|
|
|
1403
|
|
|
public function testAssertPublicAttributeContainsOnly(): void |
1404
|
|
|
{ |
1405
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1406
|
|
|
|
1407
|
|
|
$this->assertAttributeContainsOnly('string', 'publicArray', $obj); |
|
|
|
|
1408
|
|
|
|
1409
|
|
|
$this->expectException(AssertionFailedError::class); |
1410
|
|
|
|
1411
|
|
|
$this->assertAttributeContainsOnly('integer', 'publicArray', $obj); |
|
|
|
|
1412
|
|
|
} |
1413
|
|
|
|
1414
|
|
|
public function testAssertPublicAttributeNotContains(): void |
1415
|
|
|
{ |
1416
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1417
|
|
|
|
1418
|
|
|
$this->assertAttributeNotContains('bar', 'publicArray', $obj); |
|
|
|
|
1419
|
|
|
|
1420
|
|
|
$this->expectException(AssertionFailedError::class); |
1421
|
|
|
|
1422
|
|
|
$this->assertAttributeNotContains('foo', 'publicArray', $obj); |
|
|
|
|
1423
|
|
|
} |
1424
|
|
|
|
1425
|
|
|
public function testAssertPublicAttributeNotContainsOnly(): void |
1426
|
|
|
{ |
1427
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1428
|
|
|
|
1429
|
|
|
$this->assertAttributeNotContainsOnly('integer', 'publicArray', $obj); |
|
|
|
|
1430
|
|
|
|
1431
|
|
|
$this->expectException(AssertionFailedError::class); |
1432
|
|
|
|
1433
|
|
|
$this->assertAttributeNotContainsOnly('string', 'publicArray', $obj); |
|
|
|
|
1434
|
|
|
} |
1435
|
|
|
|
1436
|
|
|
public function testAssertProtectedAttributeContains(): void |
1437
|
|
|
{ |
1438
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1439
|
|
|
|
1440
|
|
|
$this->assertAttributeContains('bar', 'protectedArray', $obj); |
|
|
|
|
1441
|
|
|
|
1442
|
|
|
$this->expectException(AssertionFailedError::class); |
1443
|
|
|
|
1444
|
|
|
$this->assertAttributeContains('foo', 'protectedArray', $obj); |
|
|
|
|
1445
|
|
|
} |
1446
|
|
|
|
1447
|
|
|
public function testAssertProtectedAttributeNotContains(): void |
1448
|
|
|
{ |
1449
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1450
|
|
|
|
1451
|
|
|
$this->assertAttributeNotContains('foo', 'protectedArray', $obj); |
|
|
|
|
1452
|
|
|
|
1453
|
|
|
$this->expectException(AssertionFailedError::class); |
1454
|
|
|
|
1455
|
|
|
$this->assertAttributeNotContains('bar', 'protectedArray', $obj); |
|
|
|
|
1456
|
|
|
} |
1457
|
|
|
|
1458
|
|
|
public function testAssertPrivateAttributeContains(): void |
1459
|
|
|
{ |
1460
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1461
|
|
|
|
1462
|
|
|
$this->assertAttributeContains('baz', 'privateArray', $obj); |
|
|
|
|
1463
|
|
|
|
1464
|
|
|
$this->expectException(AssertionFailedError::class); |
1465
|
|
|
|
1466
|
|
|
$this->assertAttributeContains('foo', 'privateArray', $obj); |
|
|
|
|
1467
|
|
|
} |
1468
|
|
|
|
1469
|
|
|
public function testAssertPrivateAttributeNotContains(): void |
1470
|
|
|
{ |
1471
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1472
|
|
|
|
1473
|
|
|
$this->assertAttributeNotContains('foo', 'privateArray', $obj); |
|
|
|
|
1474
|
|
|
|
1475
|
|
|
$this->expectException(AssertionFailedError::class); |
1476
|
|
|
|
1477
|
|
|
$this->assertAttributeNotContains('baz', 'privateArray', $obj); |
|
|
|
|
1478
|
|
|
} |
1479
|
|
|
|
1480
|
|
|
public function testAssertAttributeContainsNonObject(): void |
1481
|
|
|
{ |
1482
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1483
|
|
|
|
1484
|
|
|
$this->assertAttributeContains(true, 'privateArray', $obj); |
|
|
|
|
1485
|
|
|
|
1486
|
|
|
$this->expectException(AssertionFailedError::class); |
1487
|
|
|
|
1488
|
|
|
$this->assertAttributeContains(true, 'privateArray', $obj, '', false, true, true); |
|
|
|
|
1489
|
|
|
} |
1490
|
|
|
|
1491
|
|
|
public function testAssertAttributeNotContainsNonObject(): void |
1492
|
|
|
{ |
1493
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1494
|
|
|
|
1495
|
|
|
$this->assertAttributeNotContains(true, 'privateArray', $obj, '', false, true, true); |
|
|
|
|
1496
|
|
|
|
1497
|
|
|
$this->expectException(AssertionFailedError::class); |
1498
|
|
|
|
1499
|
|
|
$this->assertAttributeNotContains(true, 'privateArray', $obj); |
|
|
|
|
1500
|
|
|
} |
1501
|
|
|
|
1502
|
|
|
public function testAssertPublicAttributeEquals(): void |
1503
|
|
|
{ |
1504
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1505
|
|
|
|
1506
|
|
|
$this->assertAttributeEquals('foo', 'publicAttribute', $obj); |
|
|
|
|
1507
|
|
|
|
1508
|
|
|
$this->expectException(AssertionFailedError::class); |
1509
|
|
|
|
1510
|
|
|
$this->assertAttributeEquals('bar', 'publicAttribute', $obj); |
|
|
|
|
1511
|
|
|
} |
1512
|
|
|
|
1513
|
|
|
public function testAssertPublicAttributeNotEquals(): void |
1514
|
|
|
{ |
1515
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1516
|
|
|
|
1517
|
|
|
$this->assertAttributeNotEquals('bar', 'publicAttribute', $obj); |
|
|
|
|
1518
|
|
|
|
1519
|
|
|
$this->expectException(AssertionFailedError::class); |
1520
|
|
|
|
1521
|
|
|
$this->assertAttributeNotEquals('foo', 'publicAttribute', $obj); |
|
|
|
|
1522
|
|
|
} |
1523
|
|
|
|
1524
|
|
|
public function testAssertPublicAttributeSame(): void |
1525
|
|
|
{ |
1526
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1527
|
|
|
|
1528
|
|
|
$this->assertAttributeSame('foo', 'publicAttribute', $obj); |
|
|
|
|
1529
|
|
|
|
1530
|
|
|
$this->expectException(AssertionFailedError::class); |
1531
|
|
|
|
1532
|
|
|
$this->assertAttributeSame('bar', 'publicAttribute', $obj); |
|
|
|
|
1533
|
|
|
} |
1534
|
|
|
|
1535
|
|
|
public function testAssertPublicAttributeNotSame(): void |
1536
|
|
|
{ |
1537
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1538
|
|
|
|
1539
|
|
|
$this->assertAttributeNotSame('bar', 'publicAttribute', $obj); |
|
|
|
|
1540
|
|
|
|
1541
|
|
|
$this->expectException(AssertionFailedError::class); |
1542
|
|
|
|
1543
|
|
|
$this->assertAttributeNotSame('foo', 'publicAttribute', $obj); |
|
|
|
|
1544
|
|
|
} |
1545
|
|
|
|
1546
|
|
|
public function testAssertProtectedAttributeEquals(): void |
1547
|
|
|
{ |
1548
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1549
|
|
|
|
1550
|
|
|
$this->assertAttributeEquals('bar', 'protectedAttribute', $obj); |
|
|
|
|
1551
|
|
|
|
1552
|
|
|
$this->expectException(AssertionFailedError::class); |
1553
|
|
|
|
1554
|
|
|
$this->assertAttributeEquals('foo', 'protectedAttribute', $obj); |
|
|
|
|
1555
|
|
|
} |
1556
|
|
|
|
1557
|
|
|
public function testAssertProtectedAttributeNotEquals(): void |
1558
|
|
|
{ |
1559
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1560
|
|
|
|
1561
|
|
|
$this->assertAttributeNotEquals('foo', 'protectedAttribute', $obj); |
|
|
|
|
1562
|
|
|
|
1563
|
|
|
$this->expectException(AssertionFailedError::class); |
1564
|
|
|
|
1565
|
|
|
$this->assertAttributeNotEquals('bar', 'protectedAttribute', $obj); |
|
|
|
|
1566
|
|
|
} |
1567
|
|
|
|
1568
|
|
|
public function testAssertPrivateAttributeEquals(): void |
1569
|
|
|
{ |
1570
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1571
|
|
|
|
1572
|
|
|
$this->assertAttributeEquals('baz', 'privateAttribute', $obj); |
|
|
|
|
1573
|
|
|
|
1574
|
|
|
$this->expectException(AssertionFailedError::class); |
1575
|
|
|
|
1576
|
|
|
$this->assertAttributeEquals('foo', 'privateAttribute', $obj); |
|
|
|
|
1577
|
|
|
} |
1578
|
|
|
|
1579
|
|
|
public function testAssertPrivateAttributeNotEquals(): void |
1580
|
|
|
{ |
1581
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1582
|
|
|
|
1583
|
|
|
$this->assertAttributeNotEquals('foo', 'privateAttribute', $obj); |
|
|
|
|
1584
|
|
|
|
1585
|
|
|
$this->expectException(AssertionFailedError::class); |
1586
|
|
|
|
1587
|
|
|
$this->assertAttributeNotEquals('baz', 'privateAttribute', $obj); |
|
|
|
|
1588
|
|
|
} |
1589
|
|
|
|
1590
|
|
|
public function testAssertPublicStaticAttributeEquals(): void |
1591
|
|
|
{ |
1592
|
|
|
$this->assertAttributeEquals('foo', 'publicStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1593
|
|
|
|
1594
|
|
|
$this->expectException(AssertionFailedError::class); |
1595
|
|
|
|
1596
|
|
|
$this->assertAttributeEquals('bar', 'publicStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1597
|
|
|
} |
1598
|
|
|
|
1599
|
|
|
public function testAssertPublicStaticAttributeNotEquals(): void |
1600
|
|
|
{ |
1601
|
|
|
$this->assertAttributeNotEquals('bar', 'publicStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1602
|
|
|
|
1603
|
|
|
$this->expectException(AssertionFailedError::class); |
1604
|
|
|
|
1605
|
|
|
$this->assertAttributeNotEquals('foo', 'publicStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1606
|
|
|
} |
1607
|
|
|
|
1608
|
|
|
public function testAssertProtectedStaticAttributeEquals(): void |
1609
|
|
|
{ |
1610
|
|
|
$this->assertAttributeEquals('bar', 'protectedStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1611
|
|
|
|
1612
|
|
|
$this->expectException(AssertionFailedError::class); |
1613
|
|
|
|
1614
|
|
|
$this->assertAttributeEquals('foo', 'protectedStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1615
|
|
|
} |
1616
|
|
|
|
1617
|
|
|
public function testAssertProtectedStaticAttributeNotEquals(): void |
1618
|
|
|
{ |
1619
|
|
|
$this->assertAttributeNotEquals('foo', 'protectedStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1620
|
|
|
|
1621
|
|
|
$this->expectException(AssertionFailedError::class); |
1622
|
|
|
|
1623
|
|
|
$this->assertAttributeNotEquals('bar', 'protectedStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1624
|
|
|
} |
1625
|
|
|
|
1626
|
|
|
public function testAssertPrivateStaticAttributeEquals(): void |
1627
|
|
|
{ |
1628
|
|
|
$this->assertAttributeEquals('baz', 'privateStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1629
|
|
|
|
1630
|
|
|
$this->expectException(AssertionFailedError::class); |
1631
|
|
|
|
1632
|
|
|
$this->assertAttributeEquals('foo', 'privateStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1633
|
|
|
} |
1634
|
|
|
|
1635
|
|
|
public function testAssertPrivateStaticAttributeNotEquals(): void |
1636
|
|
|
{ |
1637
|
|
|
$this->assertAttributeNotEquals('foo', 'privateStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1638
|
|
|
|
1639
|
|
|
$this->expectException(AssertionFailedError::class); |
1640
|
|
|
|
1641
|
|
|
$this->assertAttributeNotEquals('baz', 'privateStaticAttribute', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1642
|
|
|
} |
1643
|
|
|
|
1644
|
|
|
public function testAssertClassHasAttributeThrowsExceptionIfAttributeNameIsNotValid(): void |
1645
|
|
|
{ |
1646
|
|
|
$this->expectException(Exception::class); |
1647
|
|
|
|
1648
|
|
|
$this->assertClassHasAttribute('1', \ClassWithNonPublicAttributes::class); |
1649
|
|
|
} |
1650
|
|
|
|
1651
|
|
|
public function testAssertClassHasAttributeThrowsExceptionIfClassDoesNotExist(): void |
1652
|
|
|
{ |
1653
|
|
|
$this->expectException(Exception::class); |
1654
|
|
|
|
1655
|
|
|
$this->assertClassHasAttribute('attribute', 'ClassThatDoesNotExist'); |
1656
|
|
|
} |
1657
|
|
|
|
1658
|
|
|
public function testAssertClassNotHasAttributeThrowsExceptionIfAttributeNameIsNotValid(): void |
1659
|
|
|
{ |
1660
|
|
|
$this->expectException(Exception::class); |
1661
|
|
|
|
1662
|
|
|
$this->assertClassNotHasAttribute('1', \ClassWithNonPublicAttributes::class); |
1663
|
|
|
} |
1664
|
|
|
|
1665
|
|
|
public function testAssertClassNotHasAttributeThrowsExceptionIfClassDoesNotExist(): void |
1666
|
|
|
{ |
1667
|
|
|
$this->expectException(Exception::class); |
1668
|
|
|
|
1669
|
|
|
$this->assertClassNotHasAttribute('attribute', 'ClassThatDoesNotExist'); |
1670
|
|
|
} |
1671
|
|
|
|
1672
|
|
|
public function testAssertClassHasStaticAttributeThrowsExceptionIfAttributeNameIsNotValid(): void |
1673
|
|
|
{ |
1674
|
|
|
$this->expectException(Exception::class); |
1675
|
|
|
|
1676
|
|
|
$this->assertClassHasStaticAttribute('1', \ClassWithNonPublicAttributes::class); |
1677
|
|
|
} |
1678
|
|
|
|
1679
|
|
|
public function testAssertClassHasStaticAttributeThrowsExceptionIfClassDoesNotExist(): void |
1680
|
|
|
{ |
1681
|
|
|
$this->expectException(Exception::class); |
1682
|
|
|
|
1683
|
|
|
$this->assertClassHasStaticAttribute('attribute', 'ClassThatDoesNotExist'); |
1684
|
|
|
} |
1685
|
|
|
|
1686
|
|
|
public function testAssertClassNotHasStaticAttributeThrowsExceptionIfAttributeNameIsNotValid(): void |
1687
|
|
|
{ |
1688
|
|
|
$this->expectException(Exception::class); |
1689
|
|
|
|
1690
|
|
|
$this->assertClassNotHasStaticAttribute('1', \ClassWithNonPublicAttributes::class); |
1691
|
|
|
} |
1692
|
|
|
|
1693
|
|
|
public function testAssertClassNotHasStaticAttributeThrowsExceptionIfClassDoesNotExist(): void |
1694
|
|
|
{ |
1695
|
|
|
$this->expectException(Exception::class); |
1696
|
|
|
|
1697
|
|
|
$this->assertClassNotHasStaticAttribute('attribute', 'ClassThatDoesNotExist'); |
1698
|
|
|
} |
1699
|
|
|
|
1700
|
|
|
public function testAssertObjectHasAttributeThrowsException2(): void |
1701
|
|
|
{ |
1702
|
|
|
$this->expectException(Exception::class); |
1703
|
|
|
|
1704
|
|
|
$this->assertObjectHasAttribute('foo', null); |
1705
|
|
|
} |
1706
|
|
|
|
1707
|
|
|
public function testAssertObjectHasAttributeThrowsExceptionIfAttributeNameIsNotValid(): void |
1708
|
|
|
{ |
1709
|
|
|
$this->expectException(Exception::class); |
1710
|
|
|
|
1711
|
|
|
$this->assertObjectHasAttribute('1', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1712
|
|
|
} |
1713
|
|
|
|
1714
|
|
|
public function testAssertObjectNotHasAttributeThrowsException2(): void |
1715
|
|
|
{ |
1716
|
|
|
$this->expectException(Exception::class); |
1717
|
|
|
|
1718
|
|
|
$this->assertObjectNotHasAttribute('foo', null); |
1719
|
|
|
} |
1720
|
|
|
|
1721
|
|
|
public function testAssertObjectNotHasAttributeThrowsExceptionIfAttributeNameIsNotValid(): void |
1722
|
|
|
{ |
1723
|
|
|
$this->expectException(Exception::class); |
1724
|
|
|
|
1725
|
|
|
$this->assertObjectNotHasAttribute('1', \ClassWithNonPublicAttributes::class); |
|
|
|
|
1726
|
|
|
} |
1727
|
|
|
|
1728
|
|
|
public function testClassHasPublicAttribute(): void |
1729
|
|
|
{ |
1730
|
|
|
$this->assertClassHasAttribute('publicAttribute', \ClassWithNonPublicAttributes::class); |
1731
|
|
|
|
1732
|
|
|
$this->expectException(AssertionFailedError::class); |
1733
|
|
|
|
1734
|
|
|
$this->assertClassHasAttribute('attribute', \ClassWithNonPublicAttributes::class); |
1735
|
|
|
} |
1736
|
|
|
|
1737
|
|
|
public function testClassNotHasPublicAttribute(): void |
1738
|
|
|
{ |
1739
|
|
|
$this->assertClassNotHasAttribute('attribute', \ClassWithNonPublicAttributes::class); |
1740
|
|
|
|
1741
|
|
|
$this->expectException(AssertionFailedError::class); |
1742
|
|
|
|
1743
|
|
|
$this->assertClassNotHasAttribute('publicAttribute', \ClassWithNonPublicAttributes::class); |
1744
|
|
|
} |
1745
|
|
|
|
1746
|
|
|
public function testClassHasPublicStaticAttribute(): void |
1747
|
|
|
{ |
1748
|
|
|
$this->assertClassHasStaticAttribute('publicStaticAttribute', \ClassWithNonPublicAttributes::class); |
1749
|
|
|
|
1750
|
|
|
$this->expectException(AssertionFailedError::class); |
1751
|
|
|
|
1752
|
|
|
$this->assertClassHasStaticAttribute('attribute', \ClassWithNonPublicAttributes::class); |
1753
|
|
|
} |
1754
|
|
|
|
1755
|
|
|
public function testClassNotHasPublicStaticAttribute(): void |
1756
|
|
|
{ |
1757
|
|
|
$this->assertClassNotHasStaticAttribute('attribute', \ClassWithNonPublicAttributes::class); |
1758
|
|
|
|
1759
|
|
|
$this->expectException(AssertionFailedError::class); |
1760
|
|
|
|
1761
|
|
|
$this->assertClassNotHasStaticAttribute('publicStaticAttribute', \ClassWithNonPublicAttributes::class); |
1762
|
|
|
} |
1763
|
|
|
|
1764
|
|
|
public function testObjectHasPublicAttribute(): void |
1765
|
|
|
{ |
1766
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1767
|
|
|
|
1768
|
|
|
$this->assertObjectHasAttribute('publicAttribute', $obj); |
1769
|
|
|
|
1770
|
|
|
$this->expectException(AssertionFailedError::class); |
1771
|
|
|
|
1772
|
|
|
$this->assertObjectHasAttribute('attribute', $obj); |
1773
|
|
|
} |
1774
|
|
|
|
1775
|
|
|
public function testObjectNotHasPublicAttribute(): void |
1776
|
|
|
{ |
1777
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1778
|
|
|
|
1779
|
|
|
$this->assertObjectNotHasAttribute('attribute', $obj); |
1780
|
|
|
|
1781
|
|
|
$this->expectException(AssertionFailedError::class); |
1782
|
|
|
|
1783
|
|
|
$this->assertObjectNotHasAttribute('publicAttribute', $obj); |
1784
|
|
|
} |
1785
|
|
|
|
1786
|
|
|
public function testObjectHasOnTheFlyAttribute(): void |
1787
|
|
|
{ |
1788
|
|
|
$obj = new \stdClass; |
1789
|
|
|
$obj->foo = 'bar'; |
1790
|
|
|
|
1791
|
|
|
$this->assertObjectHasAttribute('foo', $obj); |
1792
|
|
|
|
1793
|
|
|
$this->expectException(AssertionFailedError::class); |
1794
|
|
|
|
1795
|
|
|
$this->assertObjectHasAttribute('bar', $obj); |
1796
|
|
|
} |
1797
|
|
|
|
1798
|
|
|
public function testObjectNotHasOnTheFlyAttribute(): void |
1799
|
|
|
{ |
1800
|
|
|
$obj = new \stdClass; |
1801
|
|
|
$obj->foo = 'bar'; |
1802
|
|
|
|
1803
|
|
|
$this->assertObjectNotHasAttribute('bar', $obj); |
1804
|
|
|
|
1805
|
|
|
$this->expectException(AssertionFailedError::class); |
1806
|
|
|
|
1807
|
|
|
$this->assertObjectNotHasAttribute('foo', $obj); |
1808
|
|
|
} |
1809
|
|
|
|
1810
|
|
|
public function testObjectHasProtectedAttribute(): void |
1811
|
|
|
{ |
1812
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1813
|
|
|
|
1814
|
|
|
$this->assertObjectHasAttribute('protectedAttribute', $obj); |
1815
|
|
|
|
1816
|
|
|
$this->expectException(AssertionFailedError::class); |
1817
|
|
|
|
1818
|
|
|
$this->assertObjectHasAttribute('attribute', $obj); |
1819
|
|
|
} |
1820
|
|
|
|
1821
|
|
|
public function testObjectNotHasProtectedAttribute(): void |
1822
|
|
|
{ |
1823
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1824
|
|
|
|
1825
|
|
|
$this->assertObjectNotHasAttribute('attribute', $obj); |
1826
|
|
|
|
1827
|
|
|
$this->expectException(AssertionFailedError::class); |
1828
|
|
|
|
1829
|
|
|
$this->assertObjectNotHasAttribute('protectedAttribute', $obj); |
1830
|
|
|
} |
1831
|
|
|
|
1832
|
|
|
public function testObjectHasPrivateAttribute(): void |
1833
|
|
|
{ |
1834
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1835
|
|
|
|
1836
|
|
|
$this->assertObjectHasAttribute('privateAttribute', $obj); |
1837
|
|
|
|
1838
|
|
|
$this->expectException(AssertionFailedError::class); |
1839
|
|
|
|
1840
|
|
|
$this->assertObjectHasAttribute('attribute', $obj); |
1841
|
|
|
} |
1842
|
|
|
|
1843
|
|
|
public function testObjectNotHasPrivateAttribute(): void |
1844
|
|
|
{ |
1845
|
|
|
$obj = new \ClassWithNonPublicAttributes; |
1846
|
|
|
|
1847
|
|
|
$this->assertObjectNotHasAttribute('attribute', $obj); |
1848
|
|
|
|
1849
|
|
|
$this->expectException(AssertionFailedError::class); |
1850
|
|
|
|
1851
|
|
|
$this->assertObjectNotHasAttribute('privateAttribute', $obj); |
1852
|
|
|
} |
1853
|
|
|
|
1854
|
|
|
public function testAssertThatAttributeEquals(): void |
1855
|
|
|
{ |
1856
|
|
|
$this->assertThat( |
1857
|
|
|
new \ClassWithNonPublicAttributes, |
1858
|
|
|
$this->attribute( |
|
|
|
|
1859
|
|
|
$this->equalTo('foo'), |
1860
|
|
|
'publicAttribute' |
1861
|
|
|
) |
1862
|
|
|
); |
1863
|
|
|
} |
1864
|
|
|
|
1865
|
|
|
public function testAssertThatAttributeEquals2(): void |
1866
|
|
|
{ |
1867
|
|
|
$this->expectException(AssertionFailedError::class); |
1868
|
|
|
|
1869
|
|
|
$this->assertThat( |
1870
|
|
|
new \ClassWithNonPublicAttributes, |
1871
|
|
|
$this->attribute( |
|
|
|
|
1872
|
|
|
$this->equalTo('bar'), |
1873
|
|
|
'publicAttribute' |
1874
|
|
|
) |
1875
|
|
|
); |
1876
|
|
|
} |
1877
|
|
|
|
1878
|
|
|
public function testAssertThatAttributeEqualTo(): void |
1879
|
|
|
{ |
1880
|
|
|
$this->assertThat( |
1881
|
|
|
new \ClassWithNonPublicAttributes, |
1882
|
|
|
$this->attributeEqualTo('publicAttribute', 'foo') |
|
|
|
|
1883
|
|
|
); |
1884
|
|
|
} |
1885
|
|
|
|
1886
|
|
|
/** |
1887
|
|
|
* @doesNotPerformAssertions |
1888
|
|
|
*/ |
1889
|
|
|
public function testAssertThatAnything(): void |
1890
|
|
|
{ |
1891
|
|
|
$this->assertThat('anything', $this->anything()); |
1892
|
|
|
} |
1893
|
|
|
|
1894
|
|
|
public function testAssertThatIsTrue(): void |
1895
|
|
|
{ |
1896
|
|
|
$this->assertThat(true, $this->isTrue()); |
1897
|
|
|
} |
1898
|
|
|
|
1899
|
|
|
public function testAssertThatIsFalse(): void |
1900
|
|
|
{ |
1901
|
|
|
$this->assertThat(false, $this->isFalse()); |
1902
|
|
|
} |
1903
|
|
|
|
1904
|
|
|
public function testAssertThatIsJson(): void |
1905
|
|
|
{ |
1906
|
|
|
$this->assertThat('{}', $this->isJson()); |
1907
|
|
|
} |
1908
|
|
|
|
1909
|
|
|
/** |
1910
|
|
|
* @doesNotPerformAssertions |
1911
|
|
|
*/ |
1912
|
|
|
public function testAssertThatAnythingAndAnything(): void |
1913
|
|
|
{ |
1914
|
|
|
$this->assertThat( |
1915
|
|
|
'anything', |
1916
|
|
|
$this->logicalAnd( |
1917
|
|
|
$this->anything(), |
1918
|
|
|
$this->anything() |
1919
|
|
|
) |
1920
|
|
|
); |
1921
|
|
|
} |
1922
|
|
|
|
1923
|
|
|
/** |
1924
|
|
|
* @doesNotPerformAssertions |
1925
|
|
|
*/ |
1926
|
|
|
public function testAssertThatAnythingOrAnything(): void |
1927
|
|
|
{ |
1928
|
|
|
$this->assertThat( |
1929
|
|
|
'anything', |
1930
|
|
|
$this->logicalOr( |
1931
|
|
|
$this->anything(), |
1932
|
|
|
$this->anything() |
1933
|
|
|
) |
1934
|
|
|
); |
1935
|
|
|
} |
1936
|
|
|
|
1937
|
|
|
/** |
1938
|
|
|
* @doesNotPerformAssertions |
1939
|
|
|
*/ |
1940
|
|
|
public function testAssertThatAnythingXorNotAnything(): void |
1941
|
|
|
{ |
1942
|
|
|
$this->assertThat( |
1943
|
|
|
'anything', |
1944
|
|
|
$this->logicalXor( |
1945
|
|
|
$this->anything(), |
1946
|
|
|
$this->logicalNot($this->anything()) |
1947
|
|
|
) |
1948
|
|
|
); |
1949
|
|
|
} |
1950
|
|
|
|
1951
|
|
|
public function testAssertThatContains(): void |
1952
|
|
|
{ |
1953
|
|
|
$this->assertThat(['foo'], $this->contains('foo')); |
1954
|
|
|
} |
1955
|
|
|
|
1956
|
|
|
public function testAssertThatStringContains(): void |
1957
|
|
|
{ |
1958
|
|
|
$this->assertThat('barfoobar', $this->stringContains('foo')); |
1959
|
|
|
} |
1960
|
|
|
|
1961
|
|
|
public function testAssertThatContainsOnly(): void |
1962
|
|
|
{ |
1963
|
|
|
$this->assertThat(['foo'], $this->containsOnly('string')); |
1964
|
|
|
} |
1965
|
|
|
|
1966
|
|
|
public function testAssertThatContainsOnlyInstancesOf(): void |
1967
|
|
|
{ |
1968
|
|
|
$this->assertThat([new \Book], $this->containsOnlyInstancesOf(\Book::class)); |
1969
|
|
|
} |
1970
|
|
|
|
1971
|
|
|
public function testAssertThatArrayHasKey(): void |
1972
|
|
|
{ |
1973
|
|
|
$this->assertThat(['foo' => 'bar'], $this->arrayHasKey('foo')); |
1974
|
|
|
} |
1975
|
|
|
|
1976
|
|
|
public function testAssertThatClassHasAttribute(): void |
1977
|
|
|
{ |
1978
|
|
|
$this->assertThat( |
1979
|
|
|
new \ClassWithNonPublicAttributes, |
1980
|
|
|
$this->classHasAttribute('publicAttribute') |
1981
|
|
|
); |
1982
|
|
|
} |
1983
|
|
|
|
1984
|
|
|
public function testAssertThatClassHasStaticAttribute(): void |
1985
|
|
|
{ |
1986
|
|
|
$this->assertThat( |
1987
|
|
|
new \ClassWithNonPublicAttributes, |
1988
|
|
|
$this->classHasStaticAttribute('publicStaticAttribute') |
1989
|
|
|
); |
1990
|
|
|
} |
1991
|
|
|
|
1992
|
|
|
public function testAssertThatObjectHasAttribute(): void |
1993
|
|
|
{ |
1994
|
|
|
$this->assertThat( |
1995
|
|
|
new \ClassWithNonPublicAttributes, |
1996
|
|
|
$this->objectHasAttribute('publicAttribute') |
1997
|
|
|
); |
1998
|
|
|
} |
1999
|
|
|
|
2000
|
|
|
public function testAssertThatEqualTo(): void |
2001
|
|
|
{ |
2002
|
|
|
$this->assertThat('foo', $this->equalTo('foo')); |
2003
|
|
|
} |
2004
|
|
|
|
2005
|
|
|
public function testAssertThatIdenticalTo(): void |
2006
|
|
|
{ |
2007
|
|
|
$value = new \stdClass; |
2008
|
|
|
$constraint = $this->identicalTo($value); |
2009
|
|
|
|
2010
|
|
|
$this->assertThat($value, $constraint); |
2011
|
|
|
} |
2012
|
|
|
|
2013
|
|
|
public function testAssertThatIsInstanceOf(): void |
2014
|
|
|
{ |
2015
|
|
|
$this->assertThat(new \stdClass, $this->isInstanceOf('StdClass')); |
2016
|
|
|
} |
2017
|
|
|
|
2018
|
|
|
public function testAssertThatIsType(): void |
2019
|
|
|
{ |
2020
|
|
|
$this->assertThat('string', $this->isType('string')); |
2021
|
|
|
} |
2022
|
|
|
|
2023
|
|
|
public function testAssertThatIsEmpty(): void |
2024
|
|
|
{ |
2025
|
|
|
$this->assertThat([], $this->isEmpty()); |
2026
|
|
|
} |
2027
|
|
|
|
2028
|
|
|
public function testAssertThatFileExists(): void |
2029
|
|
|
{ |
2030
|
|
|
$this->assertThat(__FILE__, $this->fileExists()); |
2031
|
|
|
} |
2032
|
|
|
|
2033
|
|
|
public function testAssertThatGreaterThan(): void |
2034
|
|
|
{ |
2035
|
|
|
$this->assertThat(2, $this->greaterThan(1)); |
2036
|
|
|
} |
2037
|
|
|
|
2038
|
|
|
public function testAssertThatGreaterThanOrEqual(): void |
2039
|
|
|
{ |
2040
|
|
|
$this->assertThat(2, $this->greaterThanOrEqual(1)); |
2041
|
|
|
} |
2042
|
|
|
|
2043
|
|
|
public function testAssertThatLessThan(): void |
2044
|
|
|
{ |
2045
|
|
|
$this->assertThat(1, $this->lessThan(2)); |
2046
|
|
|
} |
2047
|
|
|
|
2048
|
|
|
public function testAssertThatLessThanOrEqual(): void |
2049
|
|
|
{ |
2050
|
|
|
$this->assertThat(1, $this->lessThanOrEqual(2)); |
2051
|
|
|
} |
2052
|
|
|
|
2053
|
|
|
public function testAssertThatMatchesRegularExpression(): void |
2054
|
|
|
{ |
2055
|
|
|
$this->assertThat('foobar', $this->matchesRegularExpression('/foo/')); |
2056
|
|
|
} |
2057
|
|
|
|
2058
|
|
|
public function testAssertThatCallback(): void |
2059
|
|
|
{ |
2060
|
|
|
$this->assertThat( |
2061
|
|
|
null, |
2062
|
|
|
$this->callback(function ($other) { |
|
|
|
|
2063
|
|
|
return true; |
2064
|
|
|
}) |
2065
|
|
|
); |
2066
|
|
|
} |
2067
|
|
|
|
2068
|
|
|
public function testAssertThatCountOf(): void |
2069
|
|
|
{ |
2070
|
|
|
$this->assertThat([1], $this->countOf(1)); |
2071
|
|
|
} |
2072
|
|
|
|
2073
|
|
|
public function testAssertFileEquals(): void |
2074
|
|
|
{ |
2075
|
|
|
$this->assertFileEquals( |
2076
|
|
|
TEST_FILES_PATH . 'foo.xml', |
2077
|
|
|
TEST_FILES_PATH . 'foo.xml' |
2078
|
|
|
); |
2079
|
|
|
|
2080
|
|
|
$this->expectException(AssertionFailedError::class); |
2081
|
|
|
|
2082
|
|
|
$this->assertFileEquals( |
2083
|
|
|
TEST_FILES_PATH . 'foo.xml', |
2084
|
|
|
TEST_FILES_PATH . 'bar.xml' |
2085
|
|
|
); |
2086
|
|
|
} |
2087
|
|
|
|
2088
|
|
|
public function testAssertFileNotEquals(): void |
2089
|
|
|
{ |
2090
|
|
|
$this->assertFileNotEquals( |
2091
|
|
|
TEST_FILES_PATH . 'foo.xml', |
2092
|
|
|
TEST_FILES_PATH . 'bar.xml' |
2093
|
|
|
); |
2094
|
|
|
|
2095
|
|
|
$this->expectException(AssertionFailedError::class); |
2096
|
|
|
|
2097
|
|
|
$this->assertFileNotEquals( |
2098
|
|
|
TEST_FILES_PATH . 'foo.xml', |
2099
|
|
|
TEST_FILES_PATH . 'foo.xml' |
2100
|
|
|
); |
2101
|
|
|
} |
2102
|
|
|
|
2103
|
|
|
public function testAssertStringEqualsFile(): void |
2104
|
|
|
{ |
2105
|
|
|
$this->assertStringEqualsFile( |
2106
|
|
|
TEST_FILES_PATH . 'foo.xml', |
2107
|
|
|
\file_get_contents(TEST_FILES_PATH . 'foo.xml') |
2108
|
|
|
); |
2109
|
|
|
|
2110
|
|
|
$this->expectException(AssertionFailedError::class); |
2111
|
|
|
|
2112
|
|
|
$this->assertStringEqualsFile( |
2113
|
|
|
TEST_FILES_PATH . 'foo.xml', |
2114
|
|
|
\file_get_contents(TEST_FILES_PATH . 'bar.xml') |
2115
|
|
|
); |
2116
|
|
|
} |
2117
|
|
|
|
2118
|
|
|
public function testAssertStringNotEqualsFile(): void |
2119
|
|
|
{ |
2120
|
|
|
$this->assertStringNotEqualsFile( |
2121
|
|
|
TEST_FILES_PATH . 'foo.xml', |
2122
|
|
|
\file_get_contents(TEST_FILES_PATH . 'bar.xml') |
2123
|
|
|
); |
2124
|
|
|
|
2125
|
|
|
$this->expectException(AssertionFailedError::class); |
2126
|
|
|
|
2127
|
|
|
$this->assertStringNotEqualsFile( |
2128
|
|
|
TEST_FILES_PATH . 'foo.xml', |
2129
|
|
|
\file_get_contents(TEST_FILES_PATH . 'foo.xml') |
2130
|
|
|
); |
2131
|
|
|
} |
2132
|
|
|
|
2133
|
|
|
public function testAssertStringStartsNotWithThrowsException2(): void |
2134
|
|
|
{ |
2135
|
|
|
$this->expectException(Exception::class); |
2136
|
|
|
|
2137
|
|
|
$this->assertStringStartsNotWith('', null); |
2138
|
|
|
} |
2139
|
|
|
|
2140
|
|
|
public function testAssertStringStartsWith(): void |
2141
|
|
|
{ |
2142
|
|
|
$this->assertStringStartsWith('prefix', 'prefixfoo'); |
2143
|
|
|
|
2144
|
|
|
$this->expectException(AssertionFailedError::class); |
2145
|
|
|
|
2146
|
|
|
$this->assertStringStartsWith('prefix', 'foo'); |
2147
|
|
|
} |
2148
|
|
|
|
2149
|
|
|
public function testAssertStringStartsNotWith(): void |
2150
|
|
|
{ |
2151
|
|
|
$this->assertStringStartsNotWith('prefix', 'foo'); |
2152
|
|
|
|
2153
|
|
|
$this->expectException(AssertionFailedError::class); |
2154
|
|
|
|
2155
|
|
|
$this->assertStringStartsNotWith('prefix', 'prefixfoo'); |
2156
|
|
|
} |
2157
|
|
|
|
2158
|
|
|
public function testAssertStringEndsWith(): void |
2159
|
|
|
{ |
2160
|
|
|
$this->assertStringEndsWith('suffix', 'foosuffix'); |
2161
|
|
|
|
2162
|
|
|
$this->expectException(AssertionFailedError::class); |
2163
|
|
|
|
2164
|
|
|
$this->assertStringEndsWith('suffix', 'foo'); |
2165
|
|
|
} |
2166
|
|
|
|
2167
|
|
|
public function testAssertStringEndsNotWith(): void |
2168
|
|
|
{ |
2169
|
|
|
$this->assertStringEndsNotWith('suffix', 'foo'); |
2170
|
|
|
|
2171
|
|
|
$this->expectException(AssertionFailedError::class); |
2172
|
|
|
|
2173
|
|
|
$this->assertStringEndsNotWith('suffix', 'foosuffix'); |
2174
|
|
|
} |
2175
|
|
|
|
2176
|
|
|
public function testAssertStringMatchesFormat(): void |
2177
|
|
|
{ |
2178
|
|
|
$this->assertStringMatchesFormat('*%s*', '***'); |
2179
|
|
|
} |
2180
|
|
|
|
2181
|
|
|
public function testAssertStringMatchesFormatFailure(): void |
2182
|
|
|
{ |
2183
|
|
|
$this->expectException(AssertionFailedError::class); |
2184
|
|
|
|
2185
|
|
|
$this->assertStringMatchesFormat('*%s*', '**'); |
2186
|
|
|
} |
2187
|
|
|
|
2188
|
|
|
public function testAssertStringNotMatchesFormat(): void |
2189
|
|
|
{ |
2190
|
|
|
$this->assertStringNotMatchesFormat('*%s*', '**'); |
2191
|
|
|
|
2192
|
|
|
$this->expectException(AssertionFailedError::class); |
2193
|
|
|
|
2194
|
|
|
$this->assertStringMatchesFormat('*%s*', '**'); |
2195
|
|
|
} |
2196
|
|
|
|
2197
|
|
|
public function testAssertEmpty(): void |
2198
|
|
|
{ |
2199
|
|
|
$this->assertEmpty([]); |
2200
|
|
|
|
2201
|
|
|
$this->expectException(AssertionFailedError::class); |
2202
|
|
|
|
2203
|
|
|
$this->assertEmpty(['foo']); |
2204
|
|
|
} |
2205
|
|
|
|
2206
|
|
|
public function testAssertNotEmpty(): void |
2207
|
|
|
{ |
2208
|
|
|
$this->assertNotEmpty(['foo']); |
2209
|
|
|
|
2210
|
|
|
$this->expectException(AssertionFailedError::class); |
2211
|
|
|
|
2212
|
|
|
$this->assertNotEmpty([]); |
2213
|
|
|
} |
2214
|
|
|
|
2215
|
|
|
public function testAssertAttributeEmpty(): void |
2216
|
|
|
{ |
2217
|
|
|
$o = new \stdClass; |
2218
|
|
|
$o->a = []; |
2219
|
|
|
|
2220
|
|
|
$this->assertAttributeEmpty('a', $o); |
|
|
|
|
2221
|
|
|
|
2222
|
|
|
$o->a = ['b']; |
2223
|
|
|
|
2224
|
|
|
$this->expectException(AssertionFailedError::class); |
2225
|
|
|
|
2226
|
|
|
$this->assertAttributeEmpty('a', $o); |
|
|
|
|
2227
|
|
|
} |
2228
|
|
|
|
2229
|
|
|
public function testAssertAttributeNotEmpty(): void |
2230
|
|
|
{ |
2231
|
|
|
$o = new \stdClass; |
2232
|
|
|
$o->a = ['b']; |
2233
|
|
|
|
2234
|
|
|
$this->assertAttributeNotEmpty('a', $o); |
|
|
|
|
2235
|
|
|
|
2236
|
|
|
$o->a = []; |
2237
|
|
|
|
2238
|
|
|
$this->expectException(AssertionFailedError::class); |
2239
|
|
|
|
2240
|
|
|
$this->assertAttributeNotEmpty('a', $o); |
|
|
|
|
2241
|
|
|
} |
2242
|
|
|
|
2243
|
|
|
public function testMarkTestIncomplete(): void |
2244
|
|
|
{ |
2245
|
|
|
try { |
2246
|
|
|
$this->markTestIncomplete('incomplete'); |
2247
|
|
|
} catch (IncompleteTestError $e) { |
2248
|
|
|
$this->assertEquals('incomplete', $e->getMessage()); |
2249
|
|
|
|
2250
|
|
|
return; |
2251
|
|
|
} |
2252
|
|
|
|
2253
|
|
|
$this->fail(); |
2254
|
|
|
} |
2255
|
|
|
|
2256
|
|
|
public function testMarkTestSkipped(): void |
2257
|
|
|
{ |
2258
|
|
|
try { |
2259
|
|
|
$this->markTestSkipped('skipped'); |
2260
|
|
|
} catch (SkippedTestError $e) { |
2261
|
|
|
$this->assertEquals('skipped', $e->getMessage()); |
2262
|
|
|
|
2263
|
|
|
return; |
2264
|
|
|
} |
2265
|
|
|
|
2266
|
|
|
$this->fail(); |
2267
|
|
|
} |
2268
|
|
|
|
2269
|
|
|
public function testAssertCount(): void |
2270
|
|
|
{ |
2271
|
|
|
$this->assertCount(2, [1, 2]); |
2272
|
|
|
|
2273
|
|
|
$this->expectException(AssertionFailedError::class); |
2274
|
|
|
|
2275
|
|
|
$this->assertCount(2, [1, 2, 3]); |
2276
|
|
|
} |
2277
|
|
|
|
2278
|
|
|
public function testAssertCountTraversable(): void |
2279
|
|
|
{ |
2280
|
|
|
$this->assertCount(2, new \ArrayIterator([1, 2])); |
2281
|
|
|
|
2282
|
|
|
$this->expectException(AssertionFailedError::class); |
2283
|
|
|
|
2284
|
|
|
$this->assertCount(2, new \ArrayIterator([1, 2, 3])); |
2285
|
|
|
} |
2286
|
|
|
|
2287
|
|
|
public function testAssertCountThrowsExceptionIfElementIsNotCountable(): void |
2288
|
|
|
{ |
2289
|
|
|
try { |
2290
|
|
|
$this->assertCount(2, ''); |
|
|
|
|
2291
|
|
|
} catch (Exception $e) { |
2292
|
|
|
$this->assertEquals('Argument #2 (No Value) of PHPUnit\Framework\Assert::assertCount() must be a countable or iterable', $e->getMessage()); |
2293
|
|
|
|
2294
|
|
|
return; |
2295
|
|
|
} |
2296
|
|
|
|
2297
|
|
|
$this->fail(); |
2298
|
|
|
} |
2299
|
|
|
|
2300
|
|
|
public function testAssertAttributeCount(): void |
2301
|
|
|
{ |
2302
|
|
|
$o = new \stdClass; |
2303
|
|
|
$o->a = []; |
2304
|
|
|
|
2305
|
|
|
$this->assertAttributeCount(0, 'a', $o); |
|
|
|
|
2306
|
|
|
} |
2307
|
|
|
|
2308
|
|
|
public function testAssertNotCount(): void |
2309
|
|
|
{ |
2310
|
|
|
$this->assertNotCount(2, [1, 2, 3]); |
2311
|
|
|
|
2312
|
|
|
$this->expectException(AssertionFailedError::class); |
2313
|
|
|
|
2314
|
|
|
$this->assertNotCount(2, [1, 2]); |
2315
|
|
|
} |
2316
|
|
|
|
2317
|
|
|
public function testAssertNotCountThrowsExceptionIfElementIsNotCountable(): void |
2318
|
|
|
{ |
2319
|
|
|
$this->expectException(Exception::class); |
2320
|
|
|
|
2321
|
|
|
$this->assertNotCount(2, ''); |
|
|
|
|
2322
|
|
|
} |
2323
|
|
|
|
2324
|
|
|
public function testAssertAttributeNotCount(): void |
2325
|
|
|
{ |
2326
|
|
|
$o = new \stdClass; |
2327
|
|
|
$o->a = []; |
2328
|
|
|
|
2329
|
|
|
$this->assertAttributeNotCount(1, 'a', $o); |
|
|
|
|
2330
|
|
|
} |
2331
|
|
|
|
2332
|
|
|
public function testAssertSameSize(): void |
2333
|
|
|
{ |
2334
|
|
|
$this->assertSameSize([1, 2], [3, 4]); |
2335
|
|
|
|
2336
|
|
|
$this->expectException(AssertionFailedError::class); |
2337
|
|
|
|
2338
|
|
|
$this->assertSameSize([1, 2], [1, 2, 3]); |
2339
|
|
|
} |
2340
|
|
|
|
2341
|
|
|
public function testAssertSameSizeThrowsExceptionIfExpectedIsNotCountable(): void |
2342
|
|
|
{ |
2343
|
|
|
try { |
2344
|
|
|
$this->assertSameSize('a', []); |
|
|
|
|
2345
|
|
|
} catch (Exception $e) { |
2346
|
|
|
$this->assertEquals('Argument #1 (No Value) of PHPUnit\Framework\Assert::assertSameSize() must be a countable or iterable', $e->getMessage()); |
2347
|
|
|
|
2348
|
|
|
return; |
2349
|
|
|
} |
2350
|
|
|
|
2351
|
|
|
$this->fail(); |
2352
|
|
|
} |
2353
|
|
|
|
2354
|
|
|
public function testAssertSameSizeThrowsExceptionIfActualIsNotCountable(): void |
2355
|
|
|
{ |
2356
|
|
|
try { |
2357
|
|
|
$this->assertSameSize([], ''); |
|
|
|
|
2358
|
|
|
} catch (Exception $e) { |
2359
|
|
|
$this->assertEquals('Argument #2 (No Value) of PHPUnit\Framework\Assert::assertSameSize() must be a countable or iterable', $e->getMessage()); |
2360
|
|
|
|
2361
|
|
|
return; |
2362
|
|
|
} |
2363
|
|
|
|
2364
|
|
|
$this->fail(); |
2365
|
|
|
} |
2366
|
|
|
|
2367
|
|
|
public function testAssertNotSameSize(): void |
2368
|
|
|
{ |
2369
|
|
|
$this->assertNotSameSize([1, 2], [1, 2, 3]); |
2370
|
|
|
|
2371
|
|
|
$this->expectException(AssertionFailedError::class); |
2372
|
|
|
|
2373
|
|
|
$this->assertNotSameSize([1, 2], [3, 4]); |
2374
|
|
|
} |
2375
|
|
|
|
2376
|
|
|
public function testAssertNotSameSizeThrowsExceptionIfExpectedIsNotCountable(): void |
2377
|
|
|
{ |
2378
|
|
|
$this->expectException(Exception::class); |
2379
|
|
|
|
2380
|
|
|
$this->assertNotSameSize('a', []); |
|
|
|
|
2381
|
|
|
} |
2382
|
|
|
|
2383
|
|
|
public function testAssertNotSameSizeThrowsExceptionIfActualIsNotCountable(): void |
2384
|
|
|
{ |
2385
|
|
|
$this->expectException(Exception::class); |
2386
|
|
|
|
2387
|
|
|
$this->assertNotSameSize([], ''); |
|
|
|
|
2388
|
|
|
} |
2389
|
|
|
|
2390
|
|
|
public function testAssertJson(): void |
2391
|
|
|
{ |
2392
|
|
|
$this->assertJson('{}'); |
2393
|
|
|
} |
2394
|
|
|
|
2395
|
|
|
public function testAssertJsonStringEqualsJsonString(): void |
2396
|
|
|
{ |
2397
|
|
|
$expected = '{"Mascott" : "Tux"}'; |
2398
|
|
|
$actual = '{"Mascott" : "Tux"}'; |
2399
|
|
|
$message = 'Given Json strings do not match'; |
2400
|
|
|
|
2401
|
|
|
$this->assertJsonStringEqualsJsonString($expected, $actual, $message); |
2402
|
|
|
} |
2403
|
|
|
|
2404
|
|
|
/** |
2405
|
|
|
* @dataProvider validInvalidJsonDataprovider |
2406
|
|
|
* |
2407
|
|
|
* @throws ExpectationFailedException |
2408
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2409
|
|
|
*/ |
2410
|
|
|
public function testAssertJsonStringEqualsJsonStringErrorRaised($expected, $actual): void |
2411
|
|
|
{ |
2412
|
|
|
$this->expectException(AssertionFailedError::class); |
2413
|
|
|
|
2414
|
|
|
$this->assertJsonStringEqualsJsonString($expected, $actual); |
2415
|
|
|
} |
2416
|
|
|
|
2417
|
|
|
public function testAssertJsonStringNotEqualsJsonString(): void |
2418
|
|
|
{ |
2419
|
|
|
$expected = '{"Mascott" : "Beastie"}'; |
2420
|
|
|
$actual = '{"Mascott" : "Tux"}'; |
2421
|
|
|
$message = 'Given Json strings do match'; |
2422
|
|
|
|
2423
|
|
|
$this->assertJsonStringNotEqualsJsonString($expected, $actual, $message); |
2424
|
|
|
} |
2425
|
|
|
|
2426
|
|
|
/** |
2427
|
|
|
* @dataProvider validInvalidJsonDataprovider |
2428
|
|
|
* |
2429
|
|
|
* @throws ExpectationFailedException |
2430
|
|
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException |
2431
|
|
|
*/ |
2432
|
|
|
public function testAssertJsonStringNotEqualsJsonStringErrorRaised($expected, $actual): void |
2433
|
|
|
{ |
2434
|
|
|
$this->expectException(AssertionFailedError::class); |
2435
|
|
|
|
2436
|
|
|
$this->assertJsonStringNotEqualsJsonString($expected, $actual); |
2437
|
|
|
} |
2438
|
|
|
|
2439
|
|
|
public function testAssertJsonStringEqualsJsonFile(): void |
2440
|
|
|
{ |
2441
|
|
|
$file = TEST_FILES_PATH . 'JsonData/simpleObject.json'; |
2442
|
|
|
$actual = \json_encode(['Mascott' => 'Tux']); |
2443
|
|
|
$message = ''; |
2444
|
|
|
|
2445
|
|
|
$this->assertJsonStringEqualsJsonFile($file, $actual, $message); |
2446
|
|
|
} |
2447
|
|
|
|
2448
|
|
|
public function testAssertJsonStringEqualsJsonFileExpectingExpectationFailedException(): void |
2449
|
|
|
{ |
2450
|
|
|
$file = TEST_FILES_PATH . 'JsonData/simpleObject.json'; |
2451
|
|
|
$actual = \json_encode(['Mascott' => 'Beastie']); |
2452
|
|
|
$message = ''; |
2453
|
|
|
|
2454
|
|
|
try { |
2455
|
|
|
$this->assertJsonStringEqualsJsonFile($file, $actual, $message); |
2456
|
|
|
} catch (ExpectationFailedException $e) { |
2457
|
|
|
$this->assertEquals( |
2458
|
|
|
'Failed asserting that \'{"Mascott":"Beastie"}\' matches JSON string "{"Mascott":"Tux"}".', |
2459
|
|
|
$e->getMessage() |
2460
|
|
|
); |
2461
|
|
|
|
2462
|
|
|
return; |
2463
|
|
|
} |
2464
|
|
|
|
2465
|
|
|
$this->fail('Expected Exception not thrown.'); |
2466
|
|
|
} |
2467
|
|
|
|
2468
|
|
|
public function testAssertJsonStringNotEqualsJsonFile(): void |
2469
|
|
|
{ |
2470
|
|
|
$file = TEST_FILES_PATH . 'JsonData/simpleObject.json'; |
2471
|
|
|
$actual = \json_encode(['Mascott' => 'Beastie']); |
2472
|
|
|
$message = ''; |
2473
|
|
|
|
2474
|
|
|
$this->assertJsonStringNotEqualsJsonFile($file, $actual, $message); |
2475
|
|
|
} |
2476
|
|
|
|
2477
|
|
|
public function testAssertJsonFileNotEqualsJsonFile(): void |
2478
|
|
|
{ |
2479
|
|
|
$fileExpected = TEST_FILES_PATH . 'JsonData/simpleObject.json'; |
2480
|
|
|
$fileActual = TEST_FILES_PATH . 'JsonData/arrayObject.json'; |
2481
|
|
|
$message = ''; |
2482
|
|
|
|
2483
|
|
|
$this->assertJsonFileNotEqualsJsonFile($fileExpected, $fileActual, $message); |
2484
|
|
|
} |
2485
|
|
|
|
2486
|
|
|
public function testAssertJsonFileEqualsJsonFile(): void |
2487
|
|
|
{ |
2488
|
|
|
$file = TEST_FILES_PATH . 'JsonData/simpleObject.json'; |
2489
|
|
|
$message = ''; |
2490
|
|
|
|
2491
|
|
|
$this->assertJsonFileEqualsJsonFile($file, $file, $message); |
2492
|
|
|
} |
2493
|
|
|
|
2494
|
|
|
public function testAssertInstanceOfThrowsExceptionIfTypeDoesNotExist(): void |
2495
|
|
|
{ |
2496
|
|
|
$this->expectException(Exception::class); |
2497
|
|
|
|
2498
|
|
|
$this->assertInstanceOf('ClassThatDoesNotExist', new \stdClass); |
2499
|
|
|
} |
2500
|
|
|
|
2501
|
|
|
public function testAssertInstanceOf(): void |
2502
|
|
|
{ |
2503
|
|
|
$this->assertInstanceOf(\stdClass::class, new \stdClass); |
2504
|
|
|
|
2505
|
|
|
$this->expectException(AssertionFailedError::class); |
2506
|
|
|
|
2507
|
|
|
$this->assertInstanceOf(\Exception::class, new \stdClass); |
2508
|
|
|
} |
2509
|
|
|
|
2510
|
|
|
public function testAssertAttributeInstanceOf(): void |
2511
|
|
|
{ |
2512
|
|
|
$o = new \stdClass; |
2513
|
|
|
$o->a = new \stdClass; |
2514
|
|
|
|
2515
|
|
|
$this->assertAttributeInstanceOf(\stdClass::class, 'a', $o); |
|
|
|
|
2516
|
|
|
} |
2517
|
|
|
|
2518
|
|
|
public function testAssertNotInstanceOfThrowsExceptionIfTypeDoesNotExist(): void |
2519
|
|
|
{ |
2520
|
|
|
$this->expectException(Exception::class); |
2521
|
|
|
|
2522
|
|
|
$this->assertNotInstanceOf('ClassThatDoesNotExist', new \stdClass); |
2523
|
|
|
} |
2524
|
|
|
|
2525
|
|
|
public function testAssertNotInstanceOf(): void |
2526
|
|
|
{ |
2527
|
|
|
$this->assertNotInstanceOf(\Exception::class, new \stdClass); |
2528
|
|
|
|
2529
|
|
|
$this->expectException(AssertionFailedError::class); |
2530
|
|
|
|
2531
|
|
|
$this->assertNotInstanceOf(\stdClass::class, new \stdClass); |
2532
|
|
|
} |
2533
|
|
|
|
2534
|
|
|
public function testAssertAttributeNotInstanceOf(): void |
2535
|
|
|
{ |
2536
|
|
|
$o = new \stdClass; |
2537
|
|
|
$o->a = new \stdClass; |
2538
|
|
|
|
2539
|
|
|
$this->assertAttributeNotInstanceOf(\Exception::class, 'a', $o); |
|
|
|
|
2540
|
|
|
} |
2541
|
|
|
|
2542
|
|
|
public function testAssertInternalType(): void |
2543
|
|
|
{ |
2544
|
|
|
$this->assertInternalType('integer', 1); |
|
|
|
|
2545
|
|
|
|
2546
|
|
|
$this->expectException(AssertionFailedError::class); |
2547
|
|
|
|
2548
|
|
|
$this->assertInternalType('string', 1); |
|
|
|
|
2549
|
|
|
} |
2550
|
|
|
|
2551
|
|
|
public function testAssertInternalTypeDouble(): void |
2552
|
|
|
{ |
2553
|
|
|
$this->assertInternalType('double', 1.0); |
|
|
|
|
2554
|
|
|
|
2555
|
|
|
$this->expectException(AssertionFailedError::class); |
2556
|
|
|
|
2557
|
|
|
$this->assertInternalType('double', 1); |
|
|
|
|
2558
|
|
|
} |
2559
|
|
|
|
2560
|
|
|
public function testAssertAttributeInternalType(): void |
2561
|
|
|
{ |
2562
|
|
|
$o = new \stdClass; |
2563
|
|
|
$o->a = 1; |
2564
|
|
|
|
2565
|
|
|
$this->assertAttributeInternalType('integer', 'a', $o); |
|
|
|
|
2566
|
|
|
} |
2567
|
|
|
|
2568
|
|
|
public function testAssertNotInternalType(): void |
2569
|
|
|
{ |
2570
|
|
|
$this->assertNotInternalType('string', 1); |
|
|
|
|
2571
|
|
|
|
2572
|
|
|
$this->expectException(AssertionFailedError::class); |
2573
|
|
|
|
2574
|
|
|
$this->assertNotInternalType('integer', 1); |
|
|
|
|
2575
|
|
|
} |
2576
|
|
|
|
2577
|
|
|
public function testAssertAttributeNotInternalType(): void |
2578
|
|
|
{ |
2579
|
|
|
$o = new \stdClass; |
2580
|
|
|
$o->a = 1; |
2581
|
|
|
|
2582
|
|
|
$this->assertAttributeNotInternalType('string', 'a', $o); |
|
|
|
|
2583
|
|
|
} |
2584
|
|
|
|
2585
|
|
|
public function testAssertStringMatchesFormatFileThrowsExceptionForInvalidArgument(): void |
2586
|
|
|
{ |
2587
|
|
|
$this->expectException(Exception::class); |
2588
|
|
|
|
2589
|
|
|
$this->assertStringMatchesFormatFile('not_existing_file', ''); |
2590
|
|
|
} |
2591
|
|
|
|
2592
|
|
|
public function testAssertStringMatchesFormatFile(): void |
2593
|
|
|
{ |
2594
|
|
|
$this->assertStringMatchesFormatFile(TEST_FILES_PATH . 'expectedFileFormat.txt', "FOO\n"); |
2595
|
|
|
|
2596
|
|
|
$this->expectException(AssertionFailedError::class); |
2597
|
|
|
|
2598
|
|
|
$this->assertStringMatchesFormatFile(TEST_FILES_PATH . 'expectedFileFormat.txt', "BAR\n"); |
2599
|
|
|
} |
2600
|
|
|
|
2601
|
|
|
public function testAssertStringNotMatchesFormatFileThrowsExceptionForInvalidArgument(): void |
2602
|
|
|
{ |
2603
|
|
|
$this->expectException(Exception::class); |
2604
|
|
|
|
2605
|
|
|
$this->assertStringNotMatchesFormatFile('not_existing_file', ''); |
2606
|
|
|
} |
2607
|
|
|
|
2608
|
|
|
public function testAssertStringNotMatchesFormatFile(): void |
2609
|
|
|
{ |
2610
|
|
|
$this->assertStringNotMatchesFormatFile(TEST_FILES_PATH . 'expectedFileFormat.txt', "BAR\n"); |
2611
|
|
|
|
2612
|
|
|
$this->expectException(AssertionFailedError::class); |
2613
|
|
|
|
2614
|
|
|
$this->assertStringNotMatchesFormatFile(TEST_FILES_PATH . 'expectedFileFormat.txt', "FOO\n"); |
2615
|
|
|
} |
2616
|
|
|
|
2617
|
|
|
public function testStringsCanBeComparedForEqualityIgnoringCase(): void |
2618
|
|
|
{ |
2619
|
|
|
$this->assertEqualsIgnoringCase('a', 'A'); |
2620
|
|
|
|
2621
|
|
|
$this->assertNotEqualsIgnoringCase('a', 'B'); |
2622
|
|
|
} |
2623
|
|
|
|
2624
|
|
|
public function testArraysOfStringsCanBeComparedForEqualityIgnoringCase(): void |
2625
|
|
|
{ |
2626
|
|
|
$this->assertEqualsIgnoringCase(['a'], ['A']); |
2627
|
|
|
|
2628
|
|
|
$this->assertNotEqualsIgnoringCase(['a'], ['B']); |
2629
|
|
|
} |
2630
|
|
|
|
2631
|
|
|
public function testStringsCanBeComparedForEqualityWithDelta(): void |
2632
|
|
|
{ |
2633
|
|
|
$this->assertEqualsWithDelta(2.3, 2.5, 0.5); |
2634
|
|
|
|
2635
|
|
|
$this->assertNotEqualsWithDelta(2.3, 3.5, 0.5); |
2636
|
|
|
} |
2637
|
|
|
|
2638
|
|
|
public function testArraysOfStringsCanBeComparedForEqualityWithDelta(): void |
2639
|
|
|
{ |
2640
|
|
|
$this->assertEqualsWithDelta([2.3], [2.5], 0.5); |
2641
|
|
|
|
2642
|
|
|
$this->assertNotEqualsWithDelta([2.3], [3.5], 0.5); |
2643
|
|
|
} |
2644
|
|
|
|
2645
|
|
|
public function testArraysCanBeComparedForEqualityWithCanonicalization(): void |
2646
|
|
|
{ |
2647
|
|
|
$this->assertEqualsCanonicalizing([3, 2, 1], [2, 3, 1]); |
2648
|
|
|
|
2649
|
|
|
$this->assertNotEqualsCanonicalizing([3, 2, 1], [2, 3, 4]); |
2650
|
|
|
} |
2651
|
|
|
|
2652
|
|
|
public function testArrayTypeCanBeAsserted(): void |
2653
|
|
|
{ |
2654
|
|
|
$this->assertIsArray([]); |
2655
|
|
|
|
2656
|
|
|
try { |
2657
|
|
|
$this->assertIsArray(null); |
2658
|
|
|
} catch (AssertionFailedError $e) { |
2659
|
|
|
return; |
2660
|
|
|
} |
2661
|
|
|
|
2662
|
|
|
$this->fail(); |
2663
|
|
|
} |
2664
|
|
|
|
2665
|
|
|
public function testBoolTypeCanBeAsserted(): void |
2666
|
|
|
{ |
2667
|
|
|
$this->assertIsBool(true); |
2668
|
|
|
|
2669
|
|
|
try { |
2670
|
|
|
$this->assertIsBool(null); |
2671
|
|
|
} catch (AssertionFailedError $e) { |
2672
|
|
|
return; |
2673
|
|
|
} |
2674
|
|
|
|
2675
|
|
|
$this->fail(); |
2676
|
|
|
} |
2677
|
|
|
|
2678
|
|
|
public function testFloatTypeCanBeAsserted(): void |
2679
|
|
|
{ |
2680
|
|
|
$this->assertIsFloat(0.0); |
2681
|
|
|
|
2682
|
|
|
try { |
2683
|
|
|
$this->assertIsFloat(null); |
2684
|
|
|
} catch (AssertionFailedError $e) { |
2685
|
|
|
return; |
2686
|
|
|
} |
2687
|
|
|
|
2688
|
|
|
$this->fail(); |
2689
|
|
|
} |
2690
|
|
|
|
2691
|
|
|
public function testIntTypeCanBeAsserted(): void |
2692
|
|
|
{ |
2693
|
|
|
$this->assertIsInt(1); |
2694
|
|
|
|
2695
|
|
|
try { |
2696
|
|
|
$this->assertIsInt(null); |
2697
|
|
|
} catch (AssertionFailedError $e) { |
2698
|
|
|
return; |
2699
|
|
|
} |
2700
|
|
|
|
2701
|
|
|
$this->fail(); |
2702
|
|
|
} |
2703
|
|
|
|
2704
|
|
|
public function testNumericTypeCanBeAsserted(): void |
2705
|
|
|
{ |
2706
|
|
|
$this->assertIsNumeric('1.0'); |
2707
|
|
|
|
2708
|
|
|
try { |
2709
|
|
|
$this->assertIsNumeric('abc'); |
2710
|
|
|
} catch (AssertionFailedError $e) { |
2711
|
|
|
return; |
2712
|
|
|
} |
2713
|
|
|
|
2714
|
|
|
$this->fail(); |
2715
|
|
|
} |
2716
|
|
|
|
2717
|
|
|
public function testObjectTypeCanBeAsserted(): void |
2718
|
|
|
{ |
2719
|
|
|
$this->assertIsObject(new \stdClass); |
2720
|
|
|
|
2721
|
|
|
try { |
2722
|
|
|
$this->assertIsObject(null); |
2723
|
|
|
} catch (AssertionFailedError $e) { |
2724
|
|
|
return; |
2725
|
|
|
} |
2726
|
|
|
|
2727
|
|
|
$this->fail(); |
2728
|
|
|
} |
2729
|
|
|
|
2730
|
|
|
public function testResourceTypeCanBeAsserted(): void |
2731
|
|
|
{ |
2732
|
|
|
$this->assertIsResource(\fopen(__FILE__, 'r')); |
2733
|
|
|
|
2734
|
|
|
try { |
2735
|
|
|
$this->assertIsResource(null); |
2736
|
|
|
} catch (AssertionFailedError $e) { |
2737
|
|
|
return; |
2738
|
|
|
} |
2739
|
|
|
|
2740
|
|
|
$this->fail(); |
2741
|
|
|
} |
2742
|
|
|
|
2743
|
|
|
public function testStringTypeCanBeAsserted(): void |
2744
|
|
|
{ |
2745
|
|
|
$this->assertIsString(''); |
2746
|
|
|
|
2747
|
|
|
try { |
2748
|
|
|
$this->assertIsString(null); |
2749
|
|
|
} catch (AssertionFailedError $e) { |
2750
|
|
|
return; |
2751
|
|
|
} |
2752
|
|
|
|
2753
|
|
|
$this->fail(); |
2754
|
|
|
} |
2755
|
|
|
|
2756
|
|
|
public function testScalarTypeCanBeAsserted(): void |
2757
|
|
|
{ |
2758
|
|
|
$this->assertIsScalar(true); |
2759
|
|
|
|
2760
|
|
|
try { |
2761
|
|
|
$this->assertIsScalar(new \stdClass); |
2762
|
|
|
} catch (AssertionFailedError $e) { |
2763
|
|
|
return; |
2764
|
|
|
} |
2765
|
|
|
|
2766
|
|
|
$this->fail(); |
2767
|
|
|
} |
2768
|
|
|
|
2769
|
|
|
public function testCallableTypeCanBeAsserted(): void |
2770
|
|
|
{ |
2771
|
|
|
$this->assertIsCallable(function () { |
2772
|
|
|
}); |
2773
|
|
|
|
2774
|
|
|
try { |
2775
|
|
|
$this->assertIsCallable(null); |
2776
|
|
|
} catch (AssertionFailedError $e) { |
2777
|
|
|
return; |
2778
|
|
|
} |
2779
|
|
|
|
2780
|
|
|
$this->fail(); |
2781
|
|
|
} |
2782
|
|
|
|
2783
|
|
|
public function testIterableTypeCanBeAsserted(): void |
2784
|
|
|
{ |
2785
|
|
|
$this->assertIsIterable([]); |
2786
|
|
|
|
2787
|
|
|
try { |
2788
|
|
|
$this->assertIsIterable(null); |
2789
|
|
|
} catch (AssertionFailedError $e) { |
2790
|
|
|
return; |
2791
|
|
|
} |
2792
|
|
|
|
2793
|
|
|
$this->fail(); |
2794
|
|
|
} |
2795
|
|
|
|
2796
|
|
|
public function testNotArrayTypeCanBeAsserted(): void |
2797
|
|
|
{ |
2798
|
|
|
$this->assertIsNotArray(null); |
2799
|
|
|
|
2800
|
|
|
try { |
2801
|
|
|
$this->assertIsNotArray([]); |
2802
|
|
|
} catch (AssertionFailedError $e) { |
2803
|
|
|
return; |
2804
|
|
|
} |
2805
|
|
|
|
2806
|
|
|
$this->fail(); |
2807
|
|
|
} |
2808
|
|
|
|
2809
|
|
|
public function testNotBoolTypeCanBeAsserted(): void |
2810
|
|
|
{ |
2811
|
|
|
$this->assertIsNotBool(null); |
2812
|
|
|
|
2813
|
|
|
try { |
2814
|
|
|
$this->assertIsNotBool(true); |
2815
|
|
|
} catch (AssertionFailedError $e) { |
2816
|
|
|
return; |
2817
|
|
|
} |
2818
|
|
|
|
2819
|
|
|
$this->fail(); |
2820
|
|
|
} |
2821
|
|
|
|
2822
|
|
|
public function testNotFloatTypeCanBeAsserted(): void |
2823
|
|
|
{ |
2824
|
|
|
$this->assertIsNotFloat(null); |
2825
|
|
|
|
2826
|
|
|
try { |
2827
|
|
|
$this->assertIsNotFloat(0.0); |
2828
|
|
|
} catch (AssertionFailedError $e) { |
2829
|
|
|
return; |
2830
|
|
|
} |
2831
|
|
|
|
2832
|
|
|
$this->fail(); |
2833
|
|
|
} |
2834
|
|
|
|
2835
|
|
|
public function testNotIntTypeCanBeAsserted(): void |
2836
|
|
|
{ |
2837
|
|
|
$this->assertIsNotInt(null); |
2838
|
|
|
|
2839
|
|
|
try { |
2840
|
|
|
$this->assertIsNotInt(1); |
2841
|
|
|
} catch (AssertionFailedError $e) { |
2842
|
|
|
return; |
2843
|
|
|
} |
2844
|
|
|
|
2845
|
|
|
$this->fail(); |
2846
|
|
|
} |
2847
|
|
|
|
2848
|
|
|
public function testNotNumericTypeCanBeAsserted(): void |
2849
|
|
|
{ |
2850
|
|
|
$this->assertIsNotNumeric('abc'); |
2851
|
|
|
|
2852
|
|
|
try { |
2853
|
|
|
$this->assertIsNotNumeric('1.0'); |
2854
|
|
|
} catch (AssertionFailedError $e) { |
2855
|
|
|
return; |
2856
|
|
|
} |
2857
|
|
|
|
2858
|
|
|
$this->fail(); |
2859
|
|
|
} |
2860
|
|
|
|
2861
|
|
|
public function testNotObjectTypeCanBeAsserted(): void |
2862
|
|
|
{ |
2863
|
|
|
$this->assertIsNotObject(null); |
2864
|
|
|
|
2865
|
|
|
try { |
2866
|
|
|
$this->assertIsNotObject(new \stdClass); |
2867
|
|
|
} catch (AssertionFailedError $e) { |
2868
|
|
|
return; |
2869
|
|
|
} |
2870
|
|
|
|
2871
|
|
|
$this->fail(); |
2872
|
|
|
} |
2873
|
|
|
|
2874
|
|
|
public function testNotResourceTypeCanBeAsserted(): void |
2875
|
|
|
{ |
2876
|
|
|
$this->assertIsNotResource(null); |
2877
|
|
|
|
2878
|
|
|
try { |
2879
|
|
|
$this->assertIsNotResource(\fopen(__FILE__, 'r')); |
2880
|
|
|
} catch (AssertionFailedError $e) { |
2881
|
|
|
return; |
2882
|
|
|
} |
2883
|
|
|
|
2884
|
|
|
$this->fail(); |
2885
|
|
|
} |
2886
|
|
|
|
2887
|
|
|
public function testNotScalarTypeCanBeAsserted(): void |
2888
|
|
|
{ |
2889
|
|
|
$this->assertIsNotScalar(new \stdClass); |
2890
|
|
|
|
2891
|
|
|
try { |
2892
|
|
|
$this->assertIsNotScalar(true); |
2893
|
|
|
} catch (AssertionFailedError $e) { |
2894
|
|
|
return; |
2895
|
|
|
} |
2896
|
|
|
|
2897
|
|
|
$this->fail(); |
2898
|
|
|
} |
2899
|
|
|
|
2900
|
|
|
public function testNotStringTypeCanBeAsserted(): void |
2901
|
|
|
{ |
2902
|
|
|
$this->assertIsNotString(null); |
2903
|
|
|
|
2904
|
|
|
try { |
2905
|
|
|
$this->assertIsNotString(''); |
2906
|
|
|
} catch (AssertionFailedError $e) { |
2907
|
|
|
return; |
2908
|
|
|
} |
2909
|
|
|
|
2910
|
|
|
$this->fail(); |
2911
|
|
|
} |
2912
|
|
|
|
2913
|
|
|
public function testNotCallableTypeCanBeAsserted(): void |
2914
|
|
|
{ |
2915
|
|
|
$this->assertIsNotCallable(null); |
2916
|
|
|
|
2917
|
|
|
try { |
2918
|
|
|
$this->assertIsNotCallable(function () { |
2919
|
|
|
}); |
2920
|
|
|
} catch (AssertionFailedError $e) { |
2921
|
|
|
return; |
2922
|
|
|
} |
2923
|
|
|
|
2924
|
|
|
$this->fail(); |
2925
|
|
|
} |
2926
|
|
|
|
2927
|
|
|
public function testNotIterableTypeCanBeAsserted(): void |
2928
|
|
|
{ |
2929
|
|
|
$this->assertIsNotIterable(null); |
2930
|
|
|
|
2931
|
|
|
try { |
2932
|
|
|
$this->assertIsNotIterable([]); |
2933
|
|
|
} catch (AssertionFailedError $e) { |
2934
|
|
|
return; |
2935
|
|
|
} |
2936
|
|
|
|
2937
|
|
|
$this->fail(); |
2938
|
|
|
} |
2939
|
|
|
|
2940
|
|
|
public function testLogicalAnd(): void |
2941
|
|
|
{ |
2942
|
|
|
$this->assertThat( |
2943
|
|
|
true, |
2944
|
|
|
$this->logicalAnd( |
2945
|
|
|
$this->isTrue(), |
2946
|
|
|
$this->isTrue() |
2947
|
|
|
) |
2948
|
|
|
); |
2949
|
|
|
|
2950
|
|
|
$this->expectException(AssertionFailedError::class); |
2951
|
|
|
|
2952
|
|
|
$this->assertThat( |
2953
|
|
|
true, |
2954
|
|
|
$this->logicalAnd( |
2955
|
|
|
$this->isTrue(), |
2956
|
|
|
$this->isFalse() |
2957
|
|
|
) |
2958
|
|
|
); |
2959
|
|
|
} |
2960
|
|
|
|
2961
|
|
|
public function testLogicalOr(): void |
2962
|
|
|
{ |
2963
|
|
|
$this->assertThat( |
2964
|
|
|
true, |
2965
|
|
|
$this->logicalOr( |
2966
|
|
|
$this->isTrue(), |
2967
|
|
|
$this->isFalse() |
2968
|
|
|
) |
2969
|
|
|
); |
2970
|
|
|
|
2971
|
|
|
$this->expectException(AssertionFailedError::class); |
2972
|
|
|
|
2973
|
|
|
$this->assertThat( |
2974
|
|
|
true, |
2975
|
|
|
$this->logicalOr( |
2976
|
|
|
$this->isFalse(), |
2977
|
|
|
$this->isFalse() |
2978
|
|
|
) |
2979
|
|
|
); |
2980
|
|
|
} |
2981
|
|
|
|
2982
|
|
|
public function testLogicalXor(): void |
2983
|
|
|
{ |
2984
|
|
|
$this->assertThat( |
2985
|
|
|
true, |
2986
|
|
|
$this->logicalXor( |
2987
|
|
|
$this->isTrue(), |
2988
|
|
|
$this->isFalse() |
2989
|
|
|
) |
2990
|
|
|
); |
2991
|
|
|
|
2992
|
|
|
$this->expectException(AssertionFailedError::class); |
2993
|
|
|
|
2994
|
|
|
$this->assertThat( |
2995
|
|
|
true, |
2996
|
|
|
$this->logicalXor( |
2997
|
|
|
$this->isTrue(), |
2998
|
|
|
$this->isTrue() |
2999
|
|
|
) |
3000
|
|
|
); |
3001
|
|
|
} |
3002
|
|
|
|
3003
|
|
|
public function testStringContainsStringCanBeAsserted(): void |
3004
|
|
|
{ |
3005
|
|
|
$this->assertStringContainsString('bar', 'foobarbaz'); |
3006
|
|
|
|
3007
|
|
|
try { |
3008
|
|
|
$this->assertStringContainsString('barbara', 'foobarbaz'); |
3009
|
|
|
} catch (AssertionFailedError $e) { |
3010
|
|
|
return; |
3011
|
|
|
} |
3012
|
|
|
|
3013
|
|
|
$this->fail(); |
3014
|
|
|
} |
3015
|
|
|
|
3016
|
|
|
public function testStringNotContainsStringCanBeAsserted(): void |
3017
|
|
|
{ |
3018
|
|
|
$this->assertStringNotContainsString('barbara', 'foobarbaz'); |
3019
|
|
|
|
3020
|
|
|
try { |
3021
|
|
|
$this->assertStringNotContainsString('bar', 'foobarbaz'); |
3022
|
|
|
} catch (AssertionFailedError $e) { |
3023
|
|
|
return; |
3024
|
|
|
} |
3025
|
|
|
|
3026
|
|
|
$this->fail(); |
3027
|
|
|
} |
3028
|
|
|
|
3029
|
|
|
public function testStringContainsStringCanBeAssertedIgnoringCase(): void |
3030
|
|
|
{ |
3031
|
|
|
$this->assertStringContainsStringIgnoringCase('BAR', 'foobarbaz'); |
3032
|
|
|
|
3033
|
|
|
try { |
3034
|
|
|
$this->assertStringContainsStringIgnoringCase('BARBARA', 'foobarbaz'); |
3035
|
|
|
} catch (AssertionFailedError $e) { |
3036
|
|
|
return; |
3037
|
|
|
} |
3038
|
|
|
|
3039
|
|
|
$this->fail(); |
3040
|
|
|
} |
3041
|
|
|
|
3042
|
|
|
public function testStringNotContainsStringCanBeAssertedIgnoringCase(): void |
3043
|
|
|
{ |
3044
|
|
|
$this->assertStringNotContainsStringIgnoringCase('BARBARA', 'foobarbaz'); |
3045
|
|
|
|
3046
|
|
|
try { |
3047
|
|
|
$this->assertStringNotContainsStringIgnoringCase('BAR', 'foobarbaz'); |
3048
|
|
|
} catch (AssertionFailedError $e) { |
3049
|
|
|
return; |
3050
|
|
|
} |
3051
|
|
|
|
3052
|
|
|
$this->fail(); |
3053
|
|
|
} |
3054
|
|
|
|
3055
|
|
|
public function testIterableContainsSameObjectCanBeAsserted(): void |
3056
|
|
|
{ |
3057
|
|
|
$object = new \stdClass; |
3058
|
|
|
$iterable = [$object]; |
3059
|
|
|
|
3060
|
|
|
$this->assertContains($object, $iterable); |
3061
|
|
|
|
3062
|
|
|
try { |
3063
|
|
|
$this->assertContains(new \stdClass, $iterable); |
3064
|
|
|
} catch (AssertionFailedError $e) { |
3065
|
|
|
return; |
3066
|
|
|
} |
3067
|
|
|
|
3068
|
|
|
$this->fail(); |
3069
|
|
|
} |
3070
|
|
|
|
3071
|
|
|
public function testIterableNotContainsSameObjectCanBeAsserted(): void |
3072
|
|
|
{ |
3073
|
|
|
$object = new \stdClass; |
3074
|
|
|
$iterable = [$object]; |
3075
|
|
|
|
3076
|
|
|
$this->assertNotContains(new \stdClass, $iterable); |
3077
|
|
|
|
3078
|
|
|
try { |
3079
|
|
|
$this->assertNotContains($object, $iterable); |
3080
|
|
|
} catch (AssertionFailedError $e) { |
3081
|
|
|
return; |
3082
|
|
|
} |
3083
|
|
|
|
3084
|
|
|
$this->fail(); |
3085
|
|
|
} |
3086
|
|
|
|
3087
|
|
|
protected function sameValues(): array |
3088
|
|
|
{ |
3089
|
|
|
$object = new \SampleClass(4, 8, 15); |
3090
|
|
|
$file = TEST_FILES_PATH . 'foo.xml'; |
3091
|
|
|
$resource = \fopen($file, 'r'); |
3092
|
|
|
|
3093
|
|
|
return [ |
3094
|
|
|
// null |
3095
|
|
|
[null, null], |
3096
|
|
|
// strings |
3097
|
|
|
['a', 'a'], |
3098
|
|
|
// integers |
3099
|
|
|
[0, 0], |
3100
|
|
|
// floats |
3101
|
|
|
[2.3, 2.3], |
3102
|
|
|
[1 / 3, 1 - 2 / 3], |
3103
|
|
|
[\log(0), \log(0)], |
3104
|
|
|
// arrays |
3105
|
|
|
[[], []], |
3106
|
|
|
[[0 => 1], [0 => 1]], |
3107
|
|
|
[[0 => null], [0 => null]], |
3108
|
|
|
[['a', 'b' => [1, 2]], ['a', 'b' => [1, 2]]], |
3109
|
|
|
// objects |
3110
|
|
|
[$object, $object], |
3111
|
|
|
// resources |
3112
|
|
|
[$resource, $resource], |
3113
|
|
|
]; |
3114
|
|
|
} |
3115
|
|
|
|
3116
|
|
|
protected function notEqualValues(): array |
3117
|
|
|
{ |
3118
|
|
|
// cyclic dependencies |
3119
|
|
|
$book1 = new \Book; |
3120
|
|
|
$book1->author = new \Author('Terry Pratchett'); |
3121
|
|
|
$book1->author->books[] = $book1; |
3122
|
|
|
$book2 = new \Book; |
3123
|
|
|
$book2->author = new \Author('Terry Pratch'); |
3124
|
|
|
$book2->author->books[] = $book2; |
3125
|
|
|
|
3126
|
|
|
$book3 = new \Book; |
3127
|
|
|
$book3->author = 'Terry Pratchett'; |
3128
|
|
|
$book4 = new \stdClass; |
3129
|
|
|
$book4->author = 'Terry Pratchett'; |
3130
|
|
|
|
3131
|
|
|
$object1 = new \SampleClass(4, 8, 15); |
3132
|
|
|
$object2 = new \SampleClass(16, 23, 42); |
3133
|
|
|
$object3 = new \SampleClass(4, 8, 15); |
3134
|
|
|
$storage1 = new \SplObjectStorage; |
3135
|
|
|
$storage1->attach($object1); |
3136
|
|
|
$storage2 = new \SplObjectStorage; |
3137
|
|
|
$storage2->attach($object3); // same content, different object |
3138
|
|
|
|
3139
|
|
|
$file = TEST_FILES_PATH . 'foo.xml'; |
3140
|
|
|
|
3141
|
|
|
return [ |
3142
|
|
|
// strings |
3143
|
|
|
['a', 'b'], |
3144
|
|
|
['a', 'A'], |
3145
|
|
|
// https://github.com/sebastianbergmann/phpunit/issues/1023 |
3146
|
|
|
['9E6666666', '9E7777777'], |
3147
|
|
|
// integers |
3148
|
|
|
[1, 2], |
3149
|
|
|
[2, 1], |
3150
|
|
|
// floats |
3151
|
|
|
[2.3, 4.2], |
3152
|
|
|
[2.3, 4.2, 0.5], |
3153
|
|
|
[[2.3], [4.2], 0.5], |
3154
|
|
|
[[[2.3]], [[4.2]], 0.5], |
3155
|
|
|
[new \Struct(2.3), new \Struct(4.2), 0.5], |
3156
|
|
|
[[new \Struct(2.3)], [new \Struct(4.2)], 0.5], |
3157
|
|
|
// NAN |
3158
|
|
|
[\NAN, \NAN], |
3159
|
|
|
// arrays |
3160
|
|
|
[[], [0 => 1]], |
3161
|
|
|
[[0 => 1], []], |
3162
|
|
|
[[0 => null], []], |
3163
|
|
|
[[0 => 1, 1 => 2], [0 => 1, 1 => 3]], |
3164
|
|
|
[['a', 'b' => [1, 2]], ['a', 'b' => [2, 1]]], |
3165
|
|
|
// objects |
3166
|
|
|
[new \SampleClass(4, 8, 15), new \SampleClass(16, 23, 42)], |
3167
|
|
|
[$object1, $object2], |
3168
|
|
|
[$book1, $book2], |
3169
|
|
|
[$book3, $book4], // same content, different class |
3170
|
|
|
// resources |
3171
|
|
|
[\fopen($file, 'r'), \fopen($file, 'r')], |
3172
|
|
|
// SplObjectStorage |
3173
|
|
|
[$storage1, $storage2], |
3174
|
|
|
// DOMDocument |
3175
|
|
|
[ |
3176
|
|
|
Xml::load('<root></root>'), |
3177
|
|
|
Xml::load('<bar/>'), |
3178
|
|
|
], |
3179
|
|
|
[ |
3180
|
|
|
Xml::load('<foo attr1="bar"/>'), |
3181
|
|
|
Xml::load('<foo attr1="foobar"/>'), |
3182
|
|
|
], |
3183
|
|
|
[ |
3184
|
|
|
Xml::load('<foo> bar </foo>'), |
3185
|
|
|
Xml::load('<foo />'), |
3186
|
|
|
], |
3187
|
|
|
[ |
3188
|
|
|
Xml::load('<foo xmlns="urn:myns:bar"/>'), |
3189
|
|
|
Xml::load('<foo xmlns="urn:notmyns:bar"/>'), |
3190
|
|
|
], |
3191
|
|
|
[ |
3192
|
|
|
Xml::load('<foo> bar </foo>'), |
3193
|
|
|
Xml::load('<foo> bir </foo>'), |
3194
|
|
|
], |
3195
|
|
|
[ |
3196
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')), |
3197
|
|
|
new \DateTime('2013-03-29 03:13:35', new \DateTimeZone('America/New_York')), |
3198
|
|
|
], |
3199
|
|
|
[ |
3200
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')), |
3201
|
|
|
new \DateTime('2013-03-29 03:13:35', new \DateTimeZone('America/New_York')), |
3202
|
|
|
3500, |
3203
|
|
|
], |
3204
|
|
|
[ |
3205
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')), |
3206
|
|
|
new \DateTime('2013-03-29 05:13:35', new \DateTimeZone('America/New_York')), |
3207
|
|
|
3500, |
3208
|
|
|
], |
3209
|
|
|
[ |
3210
|
|
|
new \DateTime('2013-03-29', new \DateTimeZone('America/New_York')), |
3211
|
|
|
new \DateTime('2013-03-30', new \DateTimeZone('America/New_York')), |
3212
|
|
|
], |
3213
|
|
|
[ |
3214
|
|
|
new \DateTime('2013-03-29', new \DateTimeZone('America/New_York')), |
3215
|
|
|
new \DateTime('2013-03-30', new \DateTimeZone('America/New_York')), |
3216
|
|
|
43200, |
3217
|
|
|
], |
3218
|
|
|
[ |
3219
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')), |
3220
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/Chicago')), |
3221
|
|
|
], |
3222
|
|
|
[ |
3223
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')), |
3224
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/Chicago')), |
3225
|
|
|
3500, |
3226
|
|
|
], |
3227
|
|
|
[ |
3228
|
|
|
new \DateTime('2013-03-30', new \DateTimeZone('America/New_York')), |
3229
|
|
|
new \DateTime('2013-03-30', new \DateTimeZone('America/Chicago')), |
3230
|
|
|
], |
3231
|
|
|
[ |
3232
|
|
|
new \DateTime('2013-03-29T05:13:35-0600'), |
3233
|
|
|
new \DateTime('2013-03-29T04:13:35-0600'), |
3234
|
|
|
], |
3235
|
|
|
[ |
3236
|
|
|
new \DateTime('2013-03-29T05:13:35-0600'), |
3237
|
|
|
new \DateTime('2013-03-29T05:13:35-0500'), |
3238
|
|
|
], |
3239
|
|
|
// Exception |
3240
|
|
|
//array(new Exception('Exception 1'), new Exception('Exception 2')), |
3241
|
|
|
// different types |
3242
|
|
|
[new \SampleClass(4, 8, 15), false], |
3243
|
|
|
[false, new \SampleClass(4, 8, 15)], |
3244
|
|
|
[[0 => 1, 1 => 2], false], |
3245
|
|
|
[false, [0 => 1, 1 => 2]], |
3246
|
|
|
[[], new \stdClass], |
3247
|
|
|
[new \stdClass, []], |
3248
|
|
|
// PHP: 0 == 'Foobar' => true! |
3249
|
|
|
// We want these values to differ |
3250
|
|
|
[0, 'Foobar'], |
3251
|
|
|
['Foobar', 0], |
3252
|
|
|
[3, \acos(8)], |
3253
|
|
|
[\acos(8), 3], |
3254
|
|
|
]; |
3255
|
|
|
} |
3256
|
|
|
|
3257
|
|
|
protected function equalValues(): array |
3258
|
|
|
{ |
3259
|
|
|
// cyclic dependencies |
3260
|
|
|
$book1 = new \Book; |
3261
|
|
|
$book1->author = new \Author('Terry Pratchett'); |
3262
|
|
|
$book1->author->books[] = $book1; |
3263
|
|
|
$book2 = new \Book; |
3264
|
|
|
$book2->author = new \Author('Terry Pratchett'); |
3265
|
|
|
$book2->author->books[] = $book2; |
3266
|
|
|
|
3267
|
|
|
$object1 = new \SampleClass(4, 8, 15); |
3268
|
|
|
$object2 = new \SampleClass(4, 8, 15); |
3269
|
|
|
$storage1 = new \SplObjectStorage; |
3270
|
|
|
$storage1->attach($object1); |
3271
|
|
|
$storage2 = new \SplObjectStorage; |
3272
|
|
|
$storage2->attach($object1); |
3273
|
|
|
|
3274
|
|
|
return [ |
3275
|
|
|
// strings |
3276
|
|
|
['a', 'A', 0, false, true], // ignore case |
3277
|
|
|
// arrays |
3278
|
|
|
[['a' => 1, 'b' => 2], ['b' => 2, 'a' => 1]], |
3279
|
|
|
[[1], ['1']], |
3280
|
|
|
[[3, 2, 1], [2, 3, 1], 0, true], // canonicalized comparison |
3281
|
|
|
// floats |
3282
|
|
|
[2.3, 2.5, 0.5], |
3283
|
|
|
[[2.3], [2.5], 0.5], |
3284
|
|
|
[[[2.3]], [[2.5]], 0.5], |
3285
|
|
|
[new \Struct(2.3), new \Struct(2.5), 0.5], |
3286
|
|
|
[[new \Struct(2.3)], [new \Struct(2.5)], 0.5], |
3287
|
|
|
// numeric with delta |
3288
|
|
|
[1, 2, 1], |
3289
|
|
|
// objects |
3290
|
|
|
[$object1, $object2], |
3291
|
|
|
[$book1, $book2], |
3292
|
|
|
// SplObjectStorage |
3293
|
|
|
[$storage1, $storage2], |
3294
|
|
|
// DOMDocument |
3295
|
|
|
[ |
3296
|
|
|
Xml::load('<root></root>'), |
3297
|
|
|
Xml::load('<root/>'), |
3298
|
|
|
], |
3299
|
|
|
[ |
3300
|
|
|
Xml::load('<root attr="bar"></root>'), |
3301
|
|
|
Xml::load('<root attr="bar"/>'), |
3302
|
|
|
], |
3303
|
|
|
[ |
3304
|
|
|
Xml::load('<root><foo attr="bar"></foo></root>'), |
3305
|
|
|
Xml::load('<root><foo attr="bar"/></root>'), |
3306
|
|
|
], |
3307
|
|
|
[ |
3308
|
|
|
Xml::load("<root>\n <child/>\n</root>"), |
3309
|
|
|
Xml::load('<root><child/></root>'), |
3310
|
|
|
], |
3311
|
|
|
[ |
3312
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')), |
3313
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')), |
3314
|
|
|
], |
3315
|
|
|
[ |
3316
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')), |
3317
|
|
|
new \DateTime('2013-03-29 04:13:25', new \DateTimeZone('America/New_York')), |
3318
|
|
|
10, |
3319
|
|
|
], |
3320
|
|
|
[ |
3321
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')), |
3322
|
|
|
new \DateTime('2013-03-29 04:14:40', new \DateTimeZone('America/New_York')), |
3323
|
|
|
65, |
3324
|
|
|
], |
3325
|
|
|
[ |
3326
|
|
|
new \DateTime('2013-03-29', new \DateTimeZone('America/New_York')), |
3327
|
|
|
new \DateTime('2013-03-29', new \DateTimeZone('America/New_York')), |
3328
|
|
|
], |
3329
|
|
|
[ |
3330
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')), |
3331
|
|
|
new \DateTime('2013-03-29 03:13:35', new \DateTimeZone('America/Chicago')), |
3332
|
|
|
], |
3333
|
|
|
[ |
3334
|
|
|
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')), |
3335
|
|
|
new \DateTime('2013-03-29 03:13:49', new \DateTimeZone('America/Chicago')), |
3336
|
|
|
15, |
3337
|
|
|
], |
3338
|
|
|
[ |
3339
|
|
|
new \DateTime('2013-03-30', new \DateTimeZone('America/New_York')), |
3340
|
|
|
new \DateTime('2013-03-29 23:00:00', new \DateTimeZone('America/Chicago')), |
3341
|
|
|
], |
3342
|
|
|
[ |
3343
|
|
|
new \DateTime('2013-03-30', new \DateTimeZone('America/New_York')), |
3344
|
|
|
new \DateTime('2013-03-29 23:01:30', new \DateTimeZone('America/Chicago')), |
3345
|
|
|
100, |
3346
|
|
|
], |
3347
|
|
|
[ |
3348
|
|
|
new \DateTime('@1364616000'), |
3349
|
|
|
new \DateTime('2013-03-29 23:00:00', new \DateTimeZone('America/Chicago')), |
3350
|
|
|
], |
3351
|
|
|
[ |
3352
|
|
|
new \DateTime('2013-03-29T05:13:35-0500'), |
3353
|
|
|
new \DateTime('2013-03-29T04:13:35-0600'), |
3354
|
|
|
], |
3355
|
|
|
// Exception |
3356
|
|
|
//array(new Exception('Exception 1'), new Exception('Exception 1')), |
3357
|
|
|
// mixed types |
3358
|
|
|
[0, '0'], |
3359
|
|
|
['0', 0], |
3360
|
|
|
[2.3, '2.3'], |
3361
|
|
|
['2.3', 2.3], |
3362
|
|
|
[(string) (1 / 3), 1 - 2 / 3], |
3363
|
|
|
[1 / 3, (string) (1 - 2 / 3)], |
3364
|
|
|
['string representation', new \ClassWithToString], |
3365
|
|
|
[new \ClassWithToString, 'string representation'], |
3366
|
|
|
]; |
3367
|
|
|
} |
3368
|
|
|
} |
3369
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.