Completed
Branch development (b1b115)
by Johannes
10:28
created

Framework_AssertTest   F

Complexity

Total Complexity 466

Size/Duplication

Total Lines 3755
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 466
c 0
b 0
f 0
dl 0
loc 3755
rs 0.8

How to fix   Complexity   

Complex Class

Complex classes like Framework_AssertTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Framework_AssertTest, and based on these observations, apply Extract Interface, too.

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