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

Framework_ConstraintTest   F

Complexity

Total Complexity 221

Size/Duplication

Total Lines 3041
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 221
c 0
b 0
f 0
dl 0
loc 3041
rs 0.8

How to fix   Complexity   

Complex Class

Complex classes like Framework_ConstraintTest 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_ConstraintTest, 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_ConstraintTest extends PHPUnit_Framework_TestCase
12
{
13
    public function testConstraintArrayHasKey()
14
    {
15
        $constraint = PHPUnit_Framework_Assert::arrayHasKey(0);
16
17
        $this->assertFalse($constraint->evaluate([], '', true));
18
        $this->assertEquals('has the key 0', $constraint->toString());
19
        $this->assertCount(1, $constraint);
20
21
        try {
22
            $constraint->evaluate([]);
23
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
24
            $this->assertEquals(<<<EOF
25
Failed asserting that an array has the key 0.
26
27
EOF
28
              ,
29
              PHPUnit_Framework_TestFailure::exceptionToString($e)
30
            );
31
32
            return;
33
        }
34
35
        $this->fail();
36
    }
37
38
    public function testConstraintArrayHasKey2()
39
    {
40
        $constraint = PHPUnit_Framework_Assert::arrayHasKey(0);
41
42
        try {
43
            $constraint->evaluate([], 'custom message');
44
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
45
            $this->assertEquals(
46
              <<<EOF
47
custom message\nFailed asserting that an array has the key 0.
48
49
EOF
50
              ,
51
              PHPUnit_Framework_TestFailure::exceptionToString($e)
52
            );
53
54
            return;
55
        }
56
57
        $this->fail();
58
    }
59
60
    public function testConstraintArrayNotHasKey()
61
    {
62
        $constraint = PHPUnit_Framework_Assert::logicalNot(
63
          PHPUnit_Framework_Assert::arrayHasKey(0)
64
        );
65
66
        $this->assertFalse($constraint->evaluate([0 => 1], '', true));
67
        $this->assertEquals('does not have the key 0', $constraint->toString());
68
        $this->assertCount(1, $constraint);
69
70
        try {
71
            $constraint->evaluate([0 => 1]);
72
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
73
            $this->assertEquals(
74
              <<<EOF
75
Failed asserting that an array does not have the key 0.
76
77
EOF
78
              ,
79
              PHPUnit_Framework_TestFailure::exceptionToString($e)
80
            );
81
82
            return;
83
        }
84
85
        $this->fail();
86
    }
87
88
    public function testConstraintArrayNotHasKey2()
89
    {
90
        $constraint = PHPUnit_Framework_Assert::logicalNot(
91
          PHPUnit_Framework_Assert::arrayHasKey(0)
92
        );
93
94
        try {
95
            $constraint->evaluate([0], 'custom message');
96
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
97
            $this->assertEquals(
98
              <<<EOF
99
custom message
100
Failed asserting that an array does not have the key 0.
101
102
EOF
103
              ,
104
              PHPUnit_Framework_TestFailure::exceptionToString($e)
105
            );
106
107
            return;
108
        }
109
110
        $this->fail();
111
    }
112
113
    public function testConstraintIsReadable()
114
    {
115
        $constraint = PHPUnit_Framework_Assert::isReadable();
116
117
        $this->assertFalse($constraint->evaluate('foo', '', true));
118
        $this->assertEquals('is readable', $constraint->toString());
119
        $this->assertCount(1, $constraint);
120
121
        try {
122
            $constraint->evaluate('foo');
123
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
124
            $this->assertEquals(
125
                <<<EOF
126
Failed asserting that "foo" is readable.
127
128
EOF
129
                ,
130
                PHPUnit_Framework_TestFailure::exceptionToString($e)
131
            );
132
133
            return;
134
        }
135
136
        $this->fail();
137
    }
138
139
    public function testConstraintIsWritable()
140
    {
141
        $constraint = PHPUnit_Framework_Assert::isWritable();
142
143
        $this->assertFalse($constraint->evaluate('foo', '', true));
144
        $this->assertEquals('is writable', $constraint->toString());
145
        $this->assertCount(1, $constraint);
146
147
        try {
148
            $constraint->evaluate('foo');
149
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
150
            $this->assertEquals(
151
                <<<EOF
152
Failed asserting that "foo" is writable.
153
154
EOF
155
                ,
156
                PHPUnit_Framework_TestFailure::exceptionToString($e)
157
            );
158
159
            return;
160
        }
161
162
        $this->fail();
163
    }
164
165
    public function testConstraintDirectoryExists()
166
    {
167
        $constraint = PHPUnit_Framework_Assert::directoryExists();
168
169
        $this->assertFalse($constraint->evaluate('foo', '', true));
170
        $this->assertEquals('directory exists', $constraint->toString());
171
        $this->assertCount(1, $constraint);
172
173
        try {
174
            $constraint->evaluate('foo');
175
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
176
            $this->assertEquals(
177
                <<<EOF
178
Failed asserting that directory "foo" exists.
179
180
EOF
181
                ,
182
                PHPUnit_Framework_TestFailure::exceptionToString($e)
183
            );
184
185
            return;
186
        }
187
188
        $this->fail();
189
    }
190
191
    public function testConstraintFileExists()
192
    {
193
        $constraint = PHPUnit_Framework_Assert::fileExists();
194
195
        $this->assertFalse($constraint->evaluate('foo', '', true));
196
        $this->assertEquals('file exists', $constraint->toString());
197
        $this->assertCount(1, $constraint);
198
199
        try {
200
            $constraint->evaluate('foo');
201
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
202
            $this->assertEquals(
203
              <<<EOF
204
Failed asserting that file "foo" exists.
205
206
EOF
207
              ,
208
              PHPUnit_Framework_TestFailure::exceptionToString($e)
209
            );
210
211
            return;
212
        }
213
214
        $this->fail();
215
    }
216
217
    public function testConstraintFileExists2()
218
    {
219
        $constraint = PHPUnit_Framework_Assert::fileExists();
220
221
        try {
222
            $constraint->evaluate('foo', 'custom message');
223
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
224
            $this->assertEquals(<<<EOF
225
custom message
226
Failed asserting that file "foo" exists.
227
228
EOF
229
              ,
230
              PHPUnit_Framework_TestFailure::exceptionToString($e)
231
            );
232
233
            return;
234
        }
235
236
        $this->fail();
237
    }
238
239
    public function testConstraintFileNotExists()
240
    {
241
        $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ClassWithNonPublicAttributes.php';
242
243
        $constraint = PHPUnit_Framework_Assert::logicalNot(
244
          PHPUnit_Framework_Assert::fileExists()
245
        );
246
247
        $this->assertFalse($constraint->evaluate($file, '', true));
248
        $this->assertEquals('file does not exist', $constraint->toString());
249
        $this->assertCount(1, $constraint);
250
251
        try {
252
            $constraint->evaluate($file);
253
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
254
            $this->assertEquals(
255
              <<<EOF
256
Failed asserting that file "$file" does not exist.
257
258
EOF
259
              ,
260
              PHPUnit_Framework_TestFailure::exceptionToString($e)
261
            );
262
263
            return;
264
        }
265
266
        $this->fail();
267
    }
268
269
    public function testConstraintFileNotExists2()
270
    {
271
        $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ClassWithNonPublicAttributes.php';
272
273
        $constraint = PHPUnit_Framework_Assert::logicalNot(
274
          PHPUnit_Framework_Assert::fileExists()
275
        );
276
277
        try {
278
            $constraint->evaluate($file, 'custom message');
279
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
280
            $this->assertEquals(<<<EOF
281
custom message
282
Failed asserting that file "$file" does not exist.
283
284
EOF
285
              ,
286
              PHPUnit_Framework_TestFailure::exceptionToString($e)
287
            );
288
289
            return;
290
        }
291
292
        $this->fail();
293
    }
294
295
    public function testConstraintGreaterThan()
296
    {
297
        $constraint = PHPUnit_Framework_Assert::greaterThan(1);
298
299
        $this->assertFalse($constraint->evaluate(0, '', true));
300
        $this->assertTrue($constraint->evaluate(2, '', true));
301
        $this->assertEquals('is greater than 1', $constraint->toString());
302
        $this->assertCount(1, $constraint);
303
304
        try {
305
            $constraint->evaluate(0);
306
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
307
            $this->assertEquals(
308
              <<<EOF
309
Failed asserting that 0 is greater than 1.
310
311
EOF
312
              ,
313
              PHPUnit_Framework_TestFailure::exceptionToString($e)
314
            );
315
316
            return;
317
        }
318
319
        $this->fail();
320
    }
321
322
    public function testConstraintGreaterThan2()
323
    {
324
        $constraint = PHPUnit_Framework_Assert::greaterThan(1);
325
326
        try {
327
            $constraint->evaluate(0, 'custom message');
328
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
329
            $this->assertEquals(
330
              <<<EOF
331
custom message
332
Failed asserting that 0 is greater than 1.
333
334
EOF
335
              ,
336
              PHPUnit_Framework_TestFailure::exceptionToString($e)
337
            );
338
339
            return;
340
        }
341
342
        $this->fail();
343
    }
344
345
    public function testConstraintNotGreaterThan()
346
    {
347
        $constraint = PHPUnit_Framework_Assert::logicalNot(
348
          PHPUnit_Framework_Assert::greaterThan(1)
349
        );
350
351
        $this->assertTrue($constraint->evaluate(1, '', true));
352
        $this->assertEquals('is not greater than 1', $constraint->toString());
353
        $this->assertCount(1, $constraint);
354
355
        try {
356
            $constraint->evaluate(2);
357
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
358
            $this->assertEquals(
359
              <<<EOF
360
Failed asserting that 2 is not greater than 1.
361
362
EOF
363
              ,
364
              PHPUnit_Framework_TestFailure::exceptionToString($e)
365
            );
366
367
            return;
368
        }
369
370
        $this->fail();
371
    }
372
373
    public function testConstraintNotGreaterThan2()
374
    {
375
        $constraint = PHPUnit_Framework_Assert::logicalNot(
376
          PHPUnit_Framework_Assert::greaterThan(1)
377
        );
378
379
        try {
380
            $constraint->evaluate(2, 'custom message');
381
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
382
            $this->assertEquals(
383
              <<<EOF
384
custom message
385
Failed asserting that 2 is not greater than 1.
386
387
EOF
388
              ,
389
              PHPUnit_Framework_TestFailure::exceptionToString($e)
390
            );
391
392
            return;
393
        }
394
395
        $this->fail();
396
    }
397
398
    public function testConstraintGreaterThanOrEqual()
399
    {
400
        $constraint = PHPUnit_Framework_Assert::greaterThanOrEqual(1);
401
402
        $this->assertTrue($constraint->evaluate(1, '', true));
403
        $this->assertFalse($constraint->evaluate(0, '', true));
404
        $this->assertEquals('is equal to 1 or is greater than 1', $constraint->toString());
405
        $this->assertCount(2, $constraint);
406
407
        try {
408
            $constraint->evaluate(0);
409
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
410
            $this->assertEquals(
411
              <<<EOF
412
Failed asserting that 0 is equal to 1 or is greater than 1.
413
414
EOF
415
              ,
416
              PHPUnit_Framework_TestFailure::exceptionToString($e)
417
            );
418
419
            return;
420
        }
421
422
        $this->fail();
423
    }
424
425
    public function testConstraintGreaterThanOrEqual2()
426
    {
427
        $constraint = PHPUnit_Framework_Assert::greaterThanOrEqual(1);
428
429
        try {
430
            $constraint->evaluate(0, 'custom message');
431
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
432
            $this->assertEquals(
433
              <<<EOF
434
custom message
435
Failed asserting that 0 is equal to 1 or is greater than 1.
436
437
EOF
438
              ,
439
              PHPUnit_Framework_TestFailure::exceptionToString($e)
440
            );
441
442
            return;
443
        }
444
445
        $this->fail();
446
    }
447
448
    public function testConstraintNotGreaterThanOrEqual()
449
    {
450
        $constraint = PHPUnit_Framework_Assert::logicalNot(
451
          PHPUnit_Framework_Assert::greaterThanOrEqual(1)
452
        );
453
454
        $this->assertFalse($constraint->evaluate(1, '', true));
455
        $this->assertEquals('not( is equal to 1 or is greater than 1 )', $constraint->toString());
456
        $this->assertCount(2, $constraint);
457
458
        try {
459
            $constraint->evaluate(1);
460
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
461
            $this->assertEquals(
462
              <<<EOF
463
Failed asserting that not( 1 is equal to 1 or is greater than 1 ).
464
465
EOF
466
              ,
467
              PHPUnit_Framework_TestFailure::exceptionToString($e)
468
            );
469
470
            return;
471
        }
472
473
        $this->fail();
474
    }
475
476
    public function testConstraintNotGreaterThanOrEqual2()
477
    {
478
        $constraint = PHPUnit_Framework_Assert::logicalNot(
479
          PHPUnit_Framework_Assert::greaterThanOrEqual(1)
480
        );
481
482
        try {
483
            $constraint->evaluate(1, 'custom message');
484
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
485
            $this->assertEquals(
486
              <<<EOF
487
custom message
488
Failed asserting that not( 1 is equal to 1 or is greater than 1 ).
489
490
EOF
491
              ,
492
              PHPUnit_Framework_TestFailure::exceptionToString($e)
493
            );
494
495
            return;
496
        }
497
498
        $this->fail();
499
    }
500
501
    public function testConstraintIsAnything()
502
    {
503
        $constraint = PHPUnit_Framework_Assert::anything();
504
505
        $this->assertTrue($constraint->evaluate(null, '', true));
506
        $this->assertNull($constraint->evaluate(null));
507
        $this->assertEquals('is anything', $constraint->toString());
508
        $this->assertCount(0, $constraint);
509
    }
510
511
    public function testConstraintNotIsAnything()
512
    {
513
        $constraint = PHPUnit_Framework_Assert::logicalNot(
514
          PHPUnit_Framework_Assert::anything()
515
        );
516
517
        $this->assertFalse($constraint->evaluate(null, '', true));
518
        $this->assertEquals('is not anything', $constraint->toString());
519
        $this->assertCount(0, $constraint);
520
521
        try {
522
            $constraint->evaluate(null);
523
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
524
            $this->assertEquals(
525
              <<<EOF
526
Failed asserting that null is not anything.
527
528
EOF
529
              ,
530
              PHPUnit_Framework_TestFailure::exceptionToString($e)
531
            );
532
533
            return;
534
        }
535
536
        $this->fail();
537
    }
538
539
    public function testConstraintIsEqual()
540
    {
541
        $constraint = PHPUnit_Framework_Assert::equalTo(1);
542
543
        $this->assertTrue($constraint->evaluate(1, '', true));
544
        $this->assertFalse($constraint->evaluate(0, '', true));
545
        $this->assertEquals('is equal to 1', $constraint->toString());
546
        $this->assertCount(1, $constraint);
547
548
        try {
549
            $constraint->evaluate(0);
550
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
551
            $this->assertEquals(
552
              <<<EOF
553
Failed asserting that 0 matches expected 1.
554
555
EOF
556
              ,
557
              PHPUnit_Framework_TestFailure::exceptionToString($e)
558
            );
559
560
            return;
561
        }
562
563
        $this->fail();
564
    }
565
566
    public function isEqualProvider()
567
    {
568
        $a      = new stdClass;
569
        $a->foo = 'bar';
570
        $b      = new stdClass;
571
        $ahash  = spl_object_hash($a);
572
        $bhash  = spl_object_hash($b);
573
574
        $c               = new stdClass;
575
        $c->foo          = 'bar';
576
        $c->int          = 1;
577
        $c->array        = [0, [1], [2], 3];
578
        $c->related      = new stdClass;
579
        $c->related->foo = "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk";
580
        $c->self         = $c;
581
        $c->c            = $c;
582
        $d               = new stdClass;
583
        $d->foo          = 'bar';
584
        $d->int          = 2;
585
        $d->array        = [0, [4], [2], 3];
586
        $d->related      = new stdClass;
587
        $d->related->foo = "a\np\nc\nd\ne\nf\ng\nh\ni\nw\nk";
588
        $d->self         = $d;
589
        $d->c            = $c;
590
591
        $storage1 = new SplObjectStorage;
592
        $storage1->attach($a);
593
        $storage1->attach($b);
594
        $storage2 = new SplObjectStorage;
595
        $storage2->attach($b);
596
        $storage1hash = spl_object_hash($storage1);
597
        $storage2hash = spl_object_hash($storage2);
598
599
        $dom1                     = new DOMDocument;
600
        $dom1->preserveWhiteSpace = false;
601
        $dom1->loadXML('<root></root>');
602
        $dom2                     = new DOMDocument;
603
        $dom2->preserveWhiteSpace = false;
604
        $dom2->loadXML('<root><foo/></root>');
605
606
        $data = [
607
            [1, 0, <<<EOF
608
Failed asserting that 0 matches expected 1.
609
610
EOF
611
            ],
612
            [1.1, 0, <<<EOF
613
Failed asserting that 0 matches expected 1.1.
614
615
EOF
616
            ],
617
            ['a', 'b', <<<EOF
618
Failed asserting that two strings are equal.
619
--- Expected
620
+++ Actual
621
@@ @@
622
-'a'
623
+'b'
624
625
EOF
626
            ],
627
            ["a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk", "a\np\nc\nd\ne\nf\ng\nh\ni\nw\nk", <<<EOF
628
Failed asserting that two strings are equal.
629
--- Expected
630
+++ Actual
631
@@ @@
632
 'a
633
-b
634
+p
635
@@ @@
636
 i
637
-j
638
+w
639
 k'
640
641
EOF
642
            ],
643
            [1, [0], <<<EOF
644
Array (...) does not match expected type "integer".
645
646
EOF
647
            ],
648
            [[0], 1, <<<EOF
649
1 does not match expected type "array".
650
651
EOF
652
            ],
653
            [[0], [1], <<<EOF
654
Failed asserting that two arrays are equal.
655
--- Expected
656
+++ Actual
657
@@ @@
658
 Array (
659
-    0 => 0
660
+    0 => 1
661
 )
662
663
EOF
664
            ],
665
            [[true], ['true'], <<<EOF
666
Failed asserting that two arrays are equal.
667
--- Expected
668
+++ Actual
669
@@ @@
670
 Array (
671
-    0 => true
672
+    0 => 'true'
673
 )
674
675
EOF
676
            ],
677
            [[0, [1], [2], 3], [0, [4], [2], 3], <<<EOF
678
Failed asserting that two arrays are equal.
679
--- Expected
680
+++ Actual
681
@@ @@
682
 Array (
683
     0 => 0
684
     1 => Array (
685
-        0 => 1
686
+        0 => 4
687
     )
688
     2 => Array (...)
689
     3 => 3
690
 )
691
692
EOF
693
            ],
694
            [$a, [0], <<<EOF
695
Array (...) does not match expected type "object".
696
697
EOF
698
            ],
699
            [[0], $a, <<<EOF
700
stdClass Object (...) does not match expected type "array".
701
702
EOF
703
            ],
704
            [$a, $b, <<<EOF
705
Failed asserting that two objects are equal.
706
--- Expected
707
+++ Actual
708
@@ @@
709
 stdClass Object (
710
-    'foo' => 'bar'
711
 )
712
713
EOF
714
            ],
715
            [$c, $d, <<<EOF
716
Failed asserting that two objects are equal.
717
--- Expected
718
+++ Actual
719
@@ @@
720
 stdClass Object (
721
     'foo' => 'bar'
722
-    'int' => 1
723
+    'int' => 2
724
     'array' => Array (
725
         0 => 0
726
         1 => Array (
727
-            0 => 1
728
+            0 => 4
729
@@ @@
730
         'foo' => 'a
731
-        b
732
+        p
733
@@ @@
734
         i
735
-        j
736
+        w
737
         k'
738
     )
739
     'self' => stdClass Object (...)
740
     'c' => stdClass Object (...)
741
 )
742
743
EOF
744
            ],
745
            [$dom1, $dom2, <<<EOF
746
Failed asserting that two DOM documents are equal.
747
--- Expected
748
+++ Actual
749
@@ @@
750
 <?xml version="1.0"?>
751
-<root/>
752
+<root>
753
+  <foo/>
754
+</root>
755
756
EOF
757
            ],
758
            [
759
              new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
760
              new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/Chicago')),
761
              <<<EOF
762
Failed asserting that two DateTime objects are equal.
763
--- Expected
764
+++ Actual
765
@@ @@
766
-2013-03-29T04:13:35.000000-0400
767
+2013-03-29T04:13:35.000000-0500
768
769
EOF
770
            ],
771
        ];
772
773
        if (PHP_MAJOR_VERSION < 7) {
774
            $data[] = [$storage1, $storage2, <<<EOF
775
Failed asserting that two objects are equal.
776
--- Expected
777
+++ Actual
778
@@ @@
779
-SplObjectStorage Object &$storage1hash (
780
-    '$ahash' => Array &0 (
781
-        'obj' => stdClass Object &$ahash (
782
-            'foo' => 'bar'
783
-        )
784
-        'inf' => null
785
-    )
786
-    '$bhash' => Array &1 (
787
+SplObjectStorage Object &$storage2hash (
788
+    '$bhash' => Array &0 (
789
         'obj' => stdClass Object &$bhash ()
790
         'inf' => null
791
     )
792
 )
793
794
EOF
795
            ];
796
        } else {
797
            $data[] = [$storage1, $storage2, <<<EOF
798
Failed asserting that two objects are equal.
799
--- Expected
800
+++ Actual
801
@@ @@
802
-SplObjectStorage Object &$storage1hash (
803
-    '$ahash' => Array &0 (
804
-        'obj' => stdClass Object &$ahash (
805
-            'foo' => 'bar'
806
-        )
807
-        'inf' => null
808
-    )
809
-    '$bhash' => Array &1 (
810
+SplObjectStorage Object &$storage2hash (
811
+    '$bhash' => Array &0 (
812
         'obj' => stdClass Object &$bhash ()
813
         'inf' => null
814
     )
815
 )
816
817
EOF
818
            ];
819
        }
820
821
        return $data;
822
    }
823
824
    /**
825
     * @dataProvider isEqualProvider
826
     */
827
    public function testConstraintIsEqual2($expected, $actual, $message)
828
    {
829
        $constraint = PHPUnit_Framework_Assert::equalTo($expected);
830
831
        try {
832
            $constraint->evaluate($actual, 'custom message');
833
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
834
            $this->assertEquals(
835
              "custom message\n$message",
836
              $this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
837
            );
838
839
            return;
840
        }
841
842
        $this->fail();
843
    }
844
845
    public function testConstraintIsNotEqual()
846
    {
847
        $constraint = PHPUnit_Framework_Assert::logicalNot(
848
          PHPUnit_Framework_Assert::equalTo(1)
849
        );
850
851
        $this->assertTrue($constraint->evaluate(0, '', true));
852
        $this->assertFalse($constraint->evaluate(1, '', true));
853
        $this->assertEquals('is not equal to 1', $constraint->toString());
854
        $this->assertCount(1, $constraint);
855
856
        try {
857
            $constraint->evaluate(1);
858
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
859
            $this->assertEquals(
860
              <<<EOF
861
Failed asserting that 1 is not equal to 1.
862
863
EOF
864
              ,
865
              PHPUnit_Framework_TestFailure::exceptionToString($e)
866
            );
867
868
            return;
869
        }
870
871
        $this->fail();
872
    }
873
874
    public function testConstraintIsNotEqual2()
875
    {
876
        $constraint = PHPUnit_Framework_Assert::logicalNot(
877
          PHPUnit_Framework_Assert::equalTo(1)
878
        );
879
880
        try {
881
            $constraint->evaluate(1, 'custom message');
882
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
883
            $this->assertEquals(
884
              <<<EOF
885
custom message
886
Failed asserting that 1 is not equal to 1.
887
888
EOF
889
              ,
890
              PHPUnit_Framework_TestFailure::exceptionToString($e)
891
            );
892
893
            return;
894
        }
895
896
        $this->fail();
897
    }
898
899
    public function testConstraintIsIdentical()
900
    {
901
        $a = new stdClass;
902
        $b = new stdClass;
903
904
        $constraint = PHPUnit_Framework_Assert::identicalTo($a);
905
906
        $this->assertFalse($constraint->evaluate($b, '', true));
907
        $this->assertTrue($constraint->evaluate($a, '', true));
908
        $this->assertEquals('is identical to an object of class "stdClass"', $constraint->toString());
909
        $this->assertCount(1, $constraint);
910
911
        try {
912
            $constraint->evaluate($b);
913
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
914
            $this->assertEquals(<<<EOF
915
Failed asserting that two variables reference the same object.
916
917
EOF
918
              ,
919
              PHPUnit_Framework_TestFailure::exceptionToString($e)
920
            );
921
922
            return;
923
        }
924
925
        $this->fail();
926
    }
927
928
    public function testConstraintIsIdentical2()
929
    {
930
        $a = new stdClass;
931
        $b = new stdClass;
932
933
        $constraint = PHPUnit_Framework_Assert::identicalTo($a);
934
935
        try {
936
            $constraint->evaluate($b, 'custom message');
937
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
938
            $this->assertEquals(<<<EOF
939
custom message
940
Failed asserting that two variables reference the same object.
941
942
EOF
943
              ,
944
              PHPUnit_Framework_TestFailure::exceptionToString($e)
945
            );
946
947
            return;
948
        }
949
950
        $this->fail();
951
    }
952
953
    public function testConstraintIsIdentical3()
954
    {
955
        $constraint = PHPUnit_Framework_Assert::identicalTo('a');
956
957
        try {
958
            $constraint->evaluate('b', 'custom message');
959
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
960
            $this->assertEquals(<<<EOF
961
custom message
962
Failed asserting that two strings are identical.
963
--- Expected
964
+++ Actual
965
@@ @@
966
-a
967
+b
968
969
EOF
970
              ,
971
              PHPUnit_Framework_TestFailure::exceptionToString($e)
972
            );
973
974
            return;
975
        }
976
977
        $this->fail();
978
    }
979
980
    public function testConstraintIsNotIdentical()
981
    {
982
        $a = new stdClass;
983
        $b = new stdClass;
984
985
        $constraint = PHPUnit_Framework_Assert::logicalNot(
986
          PHPUnit_Framework_Assert::identicalTo($a)
987
        );
988
989
        $this->assertTrue($constraint->evaluate($b, '', true));
990
        $this->assertFalse($constraint->evaluate($a, '', true));
991
        $this->assertEquals('is not identical to an object of class "stdClass"', $constraint->toString());
992
        $this->assertCount(1, $constraint);
993
994
        try {
995
            $constraint->evaluate($a);
996
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
997
            $this->assertEquals(<<<EOF
998
Failed asserting that two variables don't reference the same object.
999
1000
EOF
1001
              ,
1002
              $this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1003
            );
1004
1005
            return;
1006
        }
1007
1008
        $this->fail();
1009
    }
1010
1011
    public function testConstraintIsNotIdentical2()
1012
    {
1013
        $a = new stdClass;
1014
1015
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1016
          PHPUnit_Framework_Assert::identicalTo($a)
1017
        );
1018
1019
        try {
1020
            $constraint->evaluate($a, 'custom message');
1021
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1022
            $this->assertEquals(<<<EOF
1023
custom message
1024
Failed asserting that two variables don't reference the same object.
1025
1026
EOF
1027
              ,
1028
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1029
            );
1030
1031
            return;
1032
        }
1033
1034
        $this->fail();
1035
    }
1036
1037
    public function testConstraintIsNotIdentical3()
1038
    {
1039
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1040
          PHPUnit_Framework_Assert::identicalTo('a')
1041
        );
1042
1043
        try {
1044
            $constraint->evaluate('a', 'custom message');
1045
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1046
            $this->assertEquals(<<<EOF
1047
custom message
1048
Failed asserting that two strings are not identical.
1049
1050
EOF
1051
              ,
1052
              $this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1053
            );
1054
1055
            return;
1056
        }
1057
1058
        $this->fail();
1059
    }
1060
1061
    public function testConstraintIsInstanceOf()
1062
    {
1063
        $constraint = PHPUnit_Framework_Assert::isInstanceOf('Exception');
1064
1065
        $this->assertFalse($constraint->evaluate(new stdClass, '', true));
1066
        $this->assertTrue($constraint->evaluate(new Exception, '', true));
1067
        $this->assertEquals('is instance of class "Exception"', $constraint->toString());
1068
        $this->assertCount(1, $constraint);
1069
1070
        $interfaceConstraint = PHPUnit_Framework_Assert::isInstanceOf('Countable');
1071
        $this->assertFalse($interfaceConstraint->evaluate(new stdClass, '', true));
1072
        $this->assertTrue($interfaceConstraint->evaluate(new ArrayObject, '', true));
1073
        $this->assertEquals('is instance of interface "Countable"', $interfaceConstraint->toString());
1074
1075
        try {
1076
            $constraint->evaluate(new stdClass);
1077
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1078
            $this->assertEquals(
1079
              <<<EOF
1080
Failed asserting that stdClass Object () is an instance of class "Exception".
1081
1082
EOF
1083
              ,
1084
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1085
            );
1086
1087
            return;
1088
        }
1089
1090
        $this->fail();
1091
    }
1092
1093
    public function testConstraintIsInstanceOf2()
1094
    {
1095
        $constraint = PHPUnit_Framework_Assert::isInstanceOf('Exception');
1096
1097
        try {
1098
            $constraint->evaluate(new stdClass, 'custom message');
1099
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1100
            $this->assertEquals(<<<EOF
1101
custom message
1102
Failed asserting that stdClass Object () is an instance of class "Exception".
1103
1104
EOF
1105
              ,
1106
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1107
            );
1108
1109
            return;
1110
        }
1111
1112
        $this->fail();
1113
    }
1114
1115
    public function testConstraintIsNotInstanceOf()
1116
    {
1117
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1118
          PHPUnit_Framework_Assert::isInstanceOf('stdClass')
1119
        );
1120
1121
        $this->assertFalse($constraint->evaluate(new stdClass, '', true));
1122
        $this->assertTrue($constraint->evaluate(new Exception, '', true));
1123
        $this->assertEquals('is not instance of class "stdClass"', $constraint->toString());
1124
        $this->assertCount(1, $constraint);
1125
1126
        try {
1127
            $constraint->evaluate(new stdClass);
1128
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1129
            $this->assertEquals(
1130
              <<<EOF
1131
Failed asserting that stdClass Object () is not an instance of class "stdClass".
1132
1133
EOF
1134
              ,
1135
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1136
            );
1137
1138
            return;
1139
        }
1140
1141
        $this->fail();
1142
    }
1143
1144
    public function testConstraintIsNotInstanceOf2()
1145
    {
1146
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1147
          PHPUnit_Framework_Assert::isInstanceOf('stdClass')
1148
        );
1149
1150
        try {
1151
            $constraint->evaluate(new stdClass, 'custom message');
1152
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1153
            $this->assertEquals(<<<EOF
1154
custom message
1155
Failed asserting that stdClass Object () is not an instance of class "stdClass".
1156
1157
EOF
1158
              ,
1159
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1160
            );
1161
1162
            return;
1163
        }
1164
1165
        $this->fail();
1166
    }
1167
1168
    public function testConstraintIsType()
1169
    {
1170
        $constraint = PHPUnit_Framework_Assert::isType('string');
1171
1172
        $this->assertFalse($constraint->evaluate(0, '', true));
1173
        $this->assertTrue($constraint->evaluate('', '', true));
1174
        $this->assertEquals('is of type "string"', $constraint->toString());
1175
        $this->assertCount(1, $constraint);
1176
1177
        try {
1178
            $constraint->evaluate(new stdClass);
1179
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1180
            $this->assertStringMatchesFormat(<<<EOF
1181
Failed asserting that stdClass Object &%x () is of type "string".
1182
1183
EOF
1184
              ,
1185
              $this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1186
            );
1187
1188
            return;
1189
        }
1190
1191
        $this->fail();
1192
    }
1193
1194
    public function testConstraintIsType2()
1195
    {
1196
        $constraint = PHPUnit_Framework_Assert::isType('string');
1197
1198
        try {
1199
            $constraint->evaluate(new stdClass, 'custom message');
1200
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1201
            $this->assertStringMatchesFormat(<<<EOF
1202
custom message
1203
Failed asserting that stdClass Object &%x () is of type "string".
1204
1205
EOF
1206
              ,
1207
              $this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1208
            );
1209
1210
            return;
1211
        }
1212
1213
        $this->fail();
1214
    }
1215
1216
    public function resources()
1217
    {
1218
        $fh = fopen(__FILE__, 'r');
1219
        fclose($fh);
1220
1221
        return [
1222
            'open resource'     => [fopen(__FILE__, 'r')],
1223
            'closed resource'   => [$fh],
1224
        ];
1225
    }
1226
1227
    /**
1228
     * @dataProvider resources
1229
     */
1230
    public function testConstraintIsResourceTypeEvaluatesCorrectlyWithResources($resource)
1231
    {
1232
        $constraint = PHPUnit_Framework_Assert::isType('resource');
1233
1234
        $this->assertTrue($constraint->evaluate($resource, '', true));
1235
1236
        @fclose($resource);
1237
    }
1238
1239
    public function testConstraintIsNotType()
1240
    {
1241
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1242
          PHPUnit_Framework_Assert::isType('string')
1243
        );
1244
1245
        $this->assertTrue($constraint->evaluate(0, '', true));
1246
        $this->assertFalse($constraint->evaluate('', '', true));
1247
        $this->assertEquals('is not of type "string"', $constraint->toString());
1248
        $this->assertCount(1, $constraint);
1249
1250
        try {
1251
            $constraint->evaluate('');
1252
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1253
            $this->assertEquals(
1254
              <<<EOF
1255
Failed asserting that '' is not of type "string".
1256
1257
EOF
1258
              ,
1259
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1260
            );
1261
1262
            return;
1263
        }
1264
1265
        $this->fail();
1266
    }
1267
1268
    public function testConstraintIsNotType2()
1269
    {
1270
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1271
          PHPUnit_Framework_Assert::isType('string')
1272
        );
1273
1274
        try {
1275
            $constraint->evaluate('', 'custom message');
1276
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1277
            $this->assertEquals(<<<EOF
1278
custom message
1279
Failed asserting that '' is not of type "string".
1280
1281
EOF
1282
              ,
1283
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1284
            );
1285
1286
            return;
1287
        }
1288
1289
        $this->fail();
1290
    }
1291
1292
    public function testConstraintIsNull()
1293
    {
1294
        $constraint = PHPUnit_Framework_Assert::isNull();
1295
1296
        $this->assertFalse($constraint->evaluate(0, '', true));
1297
        $this->assertTrue($constraint->evaluate(null, '', true));
1298
        $this->assertEquals('is null', $constraint->toString());
1299
        $this->assertCount(1, $constraint);
1300
1301
        try {
1302
            $constraint->evaluate(0);
1303
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1304
            $this->assertEquals(<<<EOF
1305
Failed asserting that 0 is null.
1306
1307
EOF
1308
              ,
1309
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1310
            );
1311
1312
            return;
1313
        }
1314
1315
        $this->fail();
1316
    }
1317
1318
    public function testConstraintIsNull2()
1319
    {
1320
        $constraint = PHPUnit_Framework_Assert::isNull();
1321
1322
        try {
1323
            $constraint->evaluate(0, 'custom message');
1324
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1325
            $this->assertEquals(<<<EOF
1326
custom message
1327
Failed asserting that 0 is null.
1328
1329
EOF
1330
              ,
1331
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1332
            );
1333
1334
            return;
1335
        }
1336
1337
        $this->fail();
1338
    }
1339
1340
    public function testConstraintIsNotNull()
1341
    {
1342
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1343
          PHPUnit_Framework_Assert::isNull()
1344
        );
1345
1346
        $this->assertFalse($constraint->evaluate(null, '', true));
1347
        $this->assertTrue($constraint->evaluate(0, '', true));
1348
        $this->assertEquals('is not null', $constraint->toString());
1349
        $this->assertCount(1, $constraint);
1350
1351
        try {
1352
            $constraint->evaluate(null);
1353
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1354
            $this->assertEquals(<<<EOF
1355
Failed asserting that null is not null.
1356
1357
EOF
1358
              ,
1359
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1360
            );
1361
1362
            return;
1363
        }
1364
1365
        $this->fail();
1366
    }
1367
1368
    public function testConstraintIsNotNull2()
1369
    {
1370
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1371
          PHPUnit_Framework_Assert::isNull()
1372
        );
1373
1374
        try {
1375
            $constraint->evaluate(null, 'custom message');
1376
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1377
            $this->assertEquals(<<<EOF
1378
custom message
1379
Failed asserting that null is not null.
1380
1381
EOF
1382
              ,
1383
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1384
            );
1385
1386
            return;
1387
        }
1388
1389
        $this->fail();
1390
    }
1391
1392
    public function testConstraintLessThan()
1393
    {
1394
        $constraint = PHPUnit_Framework_Assert::lessThan(1);
1395
1396
        $this->assertTrue($constraint->evaluate(0, '', true));
1397
        $this->assertFalse($constraint->evaluate(1, '', true));
1398
        $this->assertEquals('is less than 1', $constraint->toString());
1399
        $this->assertCount(1, $constraint);
1400
1401
        try {
1402
            $constraint->evaluate(1);
1403
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1404
            $this->assertEquals(
1405
              <<<EOF
1406
Failed asserting that 1 is less than 1.
1407
1408
EOF
1409
              ,
1410
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1411
            );
1412
1413
            return;
1414
        }
1415
1416
        $this->fail();
1417
    }
1418
1419
    public function testConstraintLessThan2()
1420
    {
1421
        $constraint = PHPUnit_Framework_Assert::lessThan(1);
1422
1423
        try {
1424
            $constraint->evaluate(1, 'custom message');
1425
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1426
            $this->assertEquals(
1427
              <<<EOF
1428
custom message
1429
Failed asserting that 1 is less than 1.
1430
1431
EOF
1432
              ,
1433
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1434
            );
1435
1436
            return;
1437
        }
1438
1439
        $this->fail();
1440
    }
1441
1442
    public function testConstraintNotLessThan()
1443
    {
1444
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1445
          PHPUnit_Framework_Assert::lessThan(1)
1446
        );
1447
1448
        $this->assertTrue($constraint->evaluate(1, '', true));
1449
        $this->assertFalse($constraint->evaluate(0, '', true));
1450
        $this->assertEquals('is not less than 1', $constraint->toString());
1451
        $this->assertCount(1, $constraint);
1452
1453
        try {
1454
            $constraint->evaluate(0);
1455
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1456
            $this->assertEquals(
1457
              <<<EOF
1458
Failed asserting that 0 is not less than 1.
1459
1460
EOF
1461
              ,
1462
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1463
            );
1464
1465
            return;
1466
        }
1467
1468
        $this->fail();
1469
    }
1470
1471
    public function testConstraintNotLessThan2()
1472
    {
1473
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1474
          PHPUnit_Framework_Assert::lessThan(1)
1475
        );
1476
1477
        try {
1478
            $constraint->evaluate(0, 'custom message');
1479
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1480
            $this->assertEquals(
1481
              <<<EOF
1482
custom message
1483
Failed asserting that 0 is not less than 1.
1484
1485
EOF
1486
              ,
1487
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1488
            );
1489
1490
            return;
1491
        }
1492
1493
        $this->fail();
1494
    }
1495
1496
    public function testConstraintLessThanOrEqual()
1497
    {
1498
        $constraint = PHPUnit_Framework_Assert::lessThanOrEqual(1);
1499
1500
        $this->assertTrue($constraint->evaluate(1, '', true));
1501
        $this->assertFalse($constraint->evaluate(2, '', true));
1502
        $this->assertEquals('is equal to 1 or is less than 1', $constraint->toString());
1503
        $this->assertCount(2, $constraint);
1504
1505
        try {
1506
            $constraint->evaluate(2);
1507
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1508
            $this->assertEquals(
1509
              <<<EOF
1510
Failed asserting that 2 is equal to 1 or is less than 1.
1511
1512
EOF
1513
              ,
1514
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1515
            );
1516
1517
            return;
1518
        }
1519
1520
        $this->fail();
1521
    }
1522
1523
    public function testConstraintCallback()
1524
    {
1525
        $closureReflect = function ($parameter) {
1526
            return $parameter;
1527
        };
1528
1529
        $closureWithoutParameter = function () {
1530
            return true;
1531
        };
1532
1533
        $constraint = PHPUnit_Framework_Assert::callback($closureWithoutParameter);
1534
        $this->assertTrue($constraint->evaluate('', '', true));
1535
1536
        $constraint = PHPUnit_Framework_Assert::callback($closureReflect);
1537
        $this->assertTrue($constraint->evaluate(true, '', true));
1538
        $this->assertFalse($constraint->evaluate(false, '', true));
1539
1540
        $callback   = [$this, 'callbackReturningTrue'];
1541
        $constraint = PHPUnit_Framework_Assert::callback($callback);
1542
        $this->assertTrue($constraint->evaluate(false, '', true));
1543
1544
        $callback   = ['Framework_ConstraintTest', 'staticCallbackReturningTrue'];
1545
        $constraint = PHPUnit_Framework_Assert::callback($callback);
1546
        $this->assertTrue($constraint->evaluate(null, '', true));
1547
1548
        $this->assertEquals('is accepted by specified callback', $constraint->toString());
1549
    }
1550
1551
    /**
1552
     * @expectedException PHPUnit_Framework_ExpectationFailedException
1553
     * @expectedExceptionMessage Failed asserting that 'This fails' is accepted by specified callback.
1554
     */
1555
    public function testConstraintCallbackFailure()
1556
    {
1557
        $constraint = PHPUnit_Framework_Assert::callback(function () {
1558
            return false;
1559
        });
1560
        $constraint->evaluate('This fails');
1561
    }
1562
1563
    public function callbackReturningTrue()
1564
    {
1565
        return true;
1566
    }
1567
1568
    public static function staticCallbackReturningTrue()
1569
    {
1570
        return true;
1571
    }
1572
1573
    public function testConstraintLessThanOrEqual2()
1574
    {
1575
        $constraint = PHPUnit_Framework_Assert::lessThanOrEqual(1);
1576
1577
        try {
1578
            $constraint->evaluate(2, 'custom message');
1579
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1580
            $this->assertEquals(
1581
              <<<EOF
1582
custom message
1583
Failed asserting that 2 is equal to 1 or is less than 1.
1584
1585
EOF
1586
              ,
1587
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1588
            );
1589
1590
            return;
1591
        }
1592
1593
        $this->fail();
1594
    }
1595
1596
    public function testConstraintNotLessThanOrEqual()
1597
    {
1598
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1599
          PHPUnit_Framework_Assert::lessThanOrEqual(1)
1600
        );
1601
1602
        $this->assertTrue($constraint->evaluate(2, '', true));
1603
        $this->assertFalse($constraint->evaluate(1, '', true));
1604
        $this->assertEquals('not( is equal to 1 or is less than 1 )', $constraint->toString());
1605
        $this->assertCount(2, $constraint);
1606
1607
        try {
1608
            $constraint->evaluate(1);
1609
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1610
            $this->assertEquals(
1611
              <<<EOF
1612
Failed asserting that not( 1 is equal to 1 or is less than 1 ).
1613
1614
EOF
1615
              ,
1616
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1617
            );
1618
1619
            return;
1620
        }
1621
1622
        $this->fail();
1623
    }
1624
1625
    public function testConstraintNotLessThanOrEqual2()
1626
    {
1627
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1628
          PHPUnit_Framework_Assert::lessThanOrEqual(1)
1629
        );
1630
1631
        try {
1632
            $constraint->evaluate(1, 'custom message');
1633
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1634
            $this->assertEquals(
1635
              <<<EOF
1636
custom message
1637
Failed asserting that not( 1 is equal to 1 or is less than 1 ).
1638
1639
EOF
1640
              ,
1641
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1642
            );
1643
1644
            return;
1645
        }
1646
1647
        $this->fail();
1648
    }
1649
1650
    public function testConstraintClassHasAttribute()
1651
    {
1652
        $constraint = PHPUnit_Framework_Assert::classHasAttribute('privateAttribute');
1653
1654
        $this->assertTrue($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
1655
        $this->assertFalse($constraint->evaluate('stdClass', '', true));
1656
        $this->assertEquals('has attribute "privateAttribute"', $constraint->toString());
1657
        $this->assertCount(1, $constraint);
1658
1659
        try {
1660
            $constraint->evaluate('stdClass');
1661
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1662
            $this->assertEquals(
1663
              <<<EOF
1664
Failed asserting that class "stdClass" has attribute "privateAttribute".
1665
1666
EOF
1667
              ,
1668
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1669
            );
1670
1671
            return;
1672
        }
1673
1674
        $this->fail();
1675
    }
1676
1677
    public function testConstraintClassHasAttribute2()
1678
    {
1679
        $constraint = PHPUnit_Framework_Assert::classHasAttribute('privateAttribute');
1680
1681
        try {
1682
            $constraint->evaluate('stdClass', 'custom message');
1683
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1684
            $this->assertEquals(<<<EOF
1685
custom message
1686
Failed asserting that class "stdClass" has attribute "privateAttribute".
1687
1688
EOF
1689
              ,
1690
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1691
            );
1692
1693
            return;
1694
        }
1695
1696
        $this->fail();
1697
    }
1698
1699
    public function testConstraintClassNotHasAttribute()
1700
    {
1701
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1702
          PHPUnit_Framework_Assert::classHasAttribute('privateAttribute')
1703
        );
1704
1705
        $this->assertTrue($constraint->evaluate('stdClass', '', true));
1706
        $this->assertFalse($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
1707
        $this->assertEquals('does not have attribute "privateAttribute"', $constraint->toString());
1708
        $this->assertCount(1, $constraint);
1709
1710
        try {
1711
            $constraint->evaluate('ClassWithNonPublicAttributes');
1712
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1713
            $this->assertEquals(
1714
              <<<EOF
1715
Failed asserting that class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
1716
1717
EOF
1718
              ,
1719
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1720
            );
1721
1722
            return;
1723
        }
1724
1725
        $this->fail();
1726
    }
1727
1728
    public function testConstraintClassNotHasAttribute2()
1729
    {
1730
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1731
          PHPUnit_Framework_Assert::classHasAttribute('privateAttribute')
1732
        );
1733
1734
        try {
1735
            $constraint->evaluate('ClassWithNonPublicAttributes', 'custom message');
1736
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1737
            $this->assertEquals(<<<EOF
1738
custom message
1739
Failed asserting that class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
1740
1741
EOF
1742
              ,
1743
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1744
            );
1745
1746
            return;
1747
        }
1748
1749
        $this->fail();
1750
    }
1751
1752
    public function testConstraintClassHasStaticAttribute()
1753
    {
1754
        $constraint = PHPUnit_Framework_Assert::classHasStaticAttribute('privateStaticAttribute');
1755
1756
        $this->assertTrue($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
1757
        $this->assertFalse($constraint->evaluate('stdClass', '', true));
1758
        $this->assertEquals('has static attribute "privateStaticAttribute"', $constraint->toString());
1759
        $this->assertCount(1, $constraint);
1760
1761
        try {
1762
            $constraint->evaluate('stdClass');
1763
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1764
            $this->assertEquals(
1765
              <<<EOF
1766
Failed asserting that class "stdClass" has static attribute "privateStaticAttribute".
1767
1768
EOF
1769
              ,
1770
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1771
            );
1772
1773
            return;
1774
        }
1775
1776
        $this->fail();
1777
    }
1778
1779
    public function testConstraintClassHasStaticAttribute2()
1780
    {
1781
        $constraint = PHPUnit_Framework_Assert::classHasStaticAttribute('foo');
1782
1783
        try {
1784
            $constraint->evaluate('stdClass', 'custom message');
1785
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1786
            $this->assertEquals(<<<EOF
1787
custom message
1788
Failed asserting that class "stdClass" has static attribute "foo".
1789
1790
EOF
1791
              ,
1792
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1793
            );
1794
1795
            return;
1796
        }
1797
1798
        $this->fail();
1799
    }
1800
1801
    public function testConstraintClassNotHasStaticAttribute()
1802
    {
1803
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1804
          PHPUnit_Framework_Assert::classHasStaticAttribute('privateStaticAttribute')
1805
        );
1806
1807
        $this->assertTrue($constraint->evaluate('stdClass', '', true));
1808
        $this->assertFalse($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
1809
        $this->assertEquals('does not have static attribute "privateStaticAttribute"', $constraint->toString());
1810
        $this->assertCount(1, $constraint);
1811
1812
        try {
1813
            $constraint->evaluate('ClassWithNonPublicAttributes');
1814
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1815
            $this->assertEquals(
1816
              <<<EOF
1817
Failed asserting that class "ClassWithNonPublicAttributes" does not have static attribute "privateStaticAttribute".
1818
1819
EOF
1820
              ,
1821
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1822
            );
1823
1824
            return;
1825
        }
1826
1827
        $this->fail();
1828
    }
1829
1830
    public function testConstraintClassNotHasStaticAttribute2()
1831
    {
1832
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1833
          PHPUnit_Framework_Assert::classHasStaticAttribute('privateStaticAttribute')
1834
        );
1835
1836
        try {
1837
            $constraint->evaluate('ClassWithNonPublicAttributes', 'custom message');
1838
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1839
            $this->assertEquals(<<<EOF
1840
custom message
1841
Failed asserting that class "ClassWithNonPublicAttributes" does not have static attribute "privateStaticAttribute".
1842
1843
EOF
1844
              ,
1845
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1846
            );
1847
1848
            return;
1849
        }
1850
1851
        $this->fail();
1852
    }
1853
1854
    public function testConstraintObjectHasAttribute()
1855
    {
1856
        $constraint = PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute');
1857
1858
        $this->assertTrue($constraint->evaluate(new ClassWithNonPublicAttributes, '', true));
1859
        $this->assertFalse($constraint->evaluate(new stdClass, '', true));
1860
        $this->assertEquals('has attribute "privateAttribute"', $constraint->toString());
1861
        $this->assertCount(1, $constraint);
1862
1863
        try {
1864
            $constraint->evaluate(new stdClass);
1865
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1866
            $this->assertEquals(
1867
              <<<EOF
1868
Failed asserting that object of class "stdClass" has attribute "privateAttribute".
1869
1870
EOF
1871
              ,
1872
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1873
            );
1874
1875
            return;
1876
        }
1877
1878
        $this->fail();
1879
    }
1880
1881
    public function testConstraintObjectHasAttribute2()
1882
    {
1883
        $constraint = PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute');
1884
1885
        try {
1886
            $constraint->evaluate(new stdClass, 'custom message');
1887
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1888
            $this->assertEquals(<<<EOF
1889
custom message
1890
Failed asserting that object of class "stdClass" has attribute "privateAttribute".
1891
1892
EOF
1893
              ,
1894
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1895
            );
1896
1897
            return;
1898
        }
1899
1900
        $this->fail();
1901
    }
1902
1903
    public function testConstraintObjectNotHasAttribute()
1904
    {
1905
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1906
          PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute')
1907
        );
1908
1909
        $this->assertTrue($constraint->evaluate(new stdClass, '', true));
1910
        $this->assertFalse($constraint->evaluate(new ClassWithNonPublicAttributes, '', true));
1911
        $this->assertEquals('does not have attribute "privateAttribute"', $constraint->toString());
1912
        $this->assertCount(1, $constraint);
1913
1914
        try {
1915
            $constraint->evaluate(new ClassWithNonPublicAttributes);
1916
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1917
            $this->assertEquals(
1918
              <<<EOF
1919
Failed asserting that object of class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
1920
1921
EOF
1922
              ,
1923
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1924
            );
1925
1926
            return;
1927
        }
1928
1929
        $this->fail();
1930
    }
1931
1932
    public function testConstraintObjectNotHasAttribute2()
1933
    {
1934
        $constraint = PHPUnit_Framework_Assert::logicalNot(
1935
          PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute')
1936
        );
1937
1938
        try {
1939
            $constraint->evaluate(new ClassWithNonPublicAttributes, 'custom message');
1940
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1941
            $this->assertEquals(<<<EOF
1942
custom message
1943
Failed asserting that object of class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
1944
1945
EOF
1946
              ,
1947
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1948
            );
1949
1950
            return;
1951
        }
1952
1953
        $this->fail();
1954
    }
1955
1956
    public function testConstraintPCREMatch()
1957
    {
1958
        $constraint = PHPUnit_Framework_Assert::matchesRegularExpression('/foo/');
1959
1960
        $this->assertFalse($constraint->evaluate('barbazbar', '', true));
1961
        $this->assertTrue($constraint->evaluate('barfoobar', '', true));
1962
        $this->assertEquals('matches PCRE pattern "/foo/"', $constraint->toString());
1963
        $this->assertCount(1, $constraint);
1964
1965
        try {
1966
            $constraint->evaluate('barbazbar');
1967
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1968
            $this->assertEquals(
1969
              <<<EOF
1970
Failed asserting that 'barbazbar' matches PCRE pattern "/foo/".
1971
1972
EOF
1973
              ,
1974
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1975
            );
1976
1977
            return;
1978
        }
1979
1980
        $this->fail();
1981
    }
1982
1983
    public function testConstraintPCREMatch2()
1984
    {
1985
        $constraint = PHPUnit_Framework_Assert::matchesRegularExpression('/foo/');
1986
1987
        try {
1988
            $constraint->evaluate('barbazbar', 'custom message');
1989
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1990
            $this->assertEquals(<<<EOF
1991
custom message
1992
Failed asserting that 'barbazbar' matches PCRE pattern "/foo/".
1993
1994
EOF
1995
              ,
1996
              PHPUnit_Framework_TestFailure::exceptionToString($e)
1997
            );
1998
1999
            return;
2000
        }
2001
2002
        $this->fail();
2003
    }
2004
2005
    public function testConstraintPCRENotMatch()
2006
    {
2007
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2008
          PHPUnit_Framework_Assert::matchesRegularExpression('/foo/')
2009
        );
2010
2011
        $this->assertTrue($constraint->evaluate('barbazbar', '', true));
2012
        $this->assertFalse($constraint->evaluate('barfoobar', '', true));
2013
        $this->assertEquals('does not match PCRE pattern "/foo/"', $constraint->toString());
2014
        $this->assertCount(1, $constraint);
2015
2016
        try {
2017
            $constraint->evaluate('barfoobar');
2018
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2019
            $this->assertEquals(
2020
              <<<EOF
2021
Failed asserting that 'barfoobar' does not match PCRE pattern "/foo/".
2022
2023
EOF
2024
              ,
2025
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2026
            );
2027
2028
            return;
2029
        }
2030
2031
        $this->fail();
2032
    }
2033
2034
    public function testConstraintPCRENotMatch2()
2035
    {
2036
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2037
          PHPUnit_Framework_Assert::matchesRegularExpression('/foo/')
2038
        );
2039
2040
        try {
2041
            $constraint->evaluate('barfoobar', 'custom message');
2042
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2043
            $this->assertEquals(<<<EOF
2044
custom message
2045
Failed asserting that 'barfoobar' does not match PCRE pattern "/foo/".
2046
2047
EOF
2048
              ,
2049
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2050
            );
2051
2052
            return;
2053
        }
2054
2055
        $this->fail();
2056
    }
2057
2058
    public function testConstraintStringMatches()
2059
    {
2060
        $constraint = PHPUnit_Framework_Assert::matches('*%c*');
2061
        $this->assertFalse($constraint->evaluate('**', '', true));
2062
        $this->assertTrue($constraint->evaluate('***', '', true));
2063
        $this->assertEquals('matches PCRE pattern "/^\*.\*$/s"', $constraint->toString());
2064
        $this->assertCount(1, $constraint);
2065
    }
2066
2067
    public function testConstraintStringMatches2()
2068
    {
2069
        $constraint = PHPUnit_Framework_Assert::matches('*%s*');
2070
        $this->assertFalse($constraint->evaluate('**', '', true));
2071
        $this->assertTrue($constraint->evaluate('***', '', true));
2072
        $this->assertEquals('matches PCRE pattern "/^\*[^\r\n]+\*$/s"', $constraint->toString());
2073
        $this->assertCount(1, $constraint);
2074
    }
2075
2076
    public function testConstraintStringMatches3()
2077
    {
2078
        $constraint = PHPUnit_Framework_Assert::matches('*%i*');
2079
        $this->assertFalse($constraint->evaluate('**', '', true));
2080
        $this->assertTrue($constraint->evaluate('*0*', '', true));
2081
        $this->assertEquals('matches PCRE pattern "/^\*[+-]?\d+\*$/s"', $constraint->toString());
2082
        $this->assertCount(1, $constraint);
2083
    }
2084
2085
    public function testConstraintStringMatches4()
2086
    {
2087
        $constraint = PHPUnit_Framework_Assert::matches('*%d*');
2088
        $this->assertFalse($constraint->evaluate('**', '', true));
2089
        $this->assertTrue($constraint->evaluate('*0*', '', true));
2090
        $this->assertEquals('matches PCRE pattern "/^\*\d+\*$/s"', $constraint->toString());
2091
        $this->assertCount(1, $constraint);
2092
    }
2093
2094
    public function testConstraintStringMatches5()
2095
    {
2096
        $constraint = PHPUnit_Framework_Assert::matches('*%x*');
2097
        $this->assertFalse($constraint->evaluate('**', '', true));
2098
        $this->assertTrue($constraint->evaluate('*0f0f0f*', '', true));
2099
        $this->assertEquals('matches PCRE pattern "/^\*[0-9a-fA-F]+\*$/s"', $constraint->toString());
2100
        $this->assertCount(1, $constraint);
2101
    }
2102
2103
    public function testConstraintStringMatches6()
2104
    {
2105
        $constraint = PHPUnit_Framework_Assert::matches('*%f*');
2106
        $this->assertFalse($constraint->evaluate('**', '', true));
2107
        $this->assertTrue($constraint->evaluate('*1.0*', '', true));
2108
        $this->assertEquals('matches PCRE pattern "/^\*[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?\*$/s"', $constraint->toString());
2109
        $this->assertCount(1, $constraint);
2110
    }
2111
2112
    public function testConstraintStringStartsWith()
2113
    {
2114
        $constraint = PHPUnit_Framework_Assert::stringStartsWith('prefix');
2115
2116
        $this->assertFalse($constraint->evaluate('foo', '', true));
2117
        $this->assertTrue($constraint->evaluate('prefixfoo', '', true));
2118
        $this->assertEquals('starts with "prefix"', $constraint->toString());
2119
        $this->assertCount(1, $constraint);
2120
2121
        try {
2122
            $constraint->evaluate('foo');
2123
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2124
            $this->assertEquals(
2125
              <<<EOF
2126
Failed asserting that 'foo' starts with "prefix".
2127
2128
EOF
2129
              ,
2130
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2131
            );
2132
2133
            return;
2134
        }
2135
2136
        $this->fail();
2137
    }
2138
2139
    public function testConstraintStringStartsWith2()
2140
    {
2141
        $constraint = PHPUnit_Framework_Assert::stringStartsWith('prefix');
2142
2143
        try {
2144
            $constraint->evaluate('foo', 'custom message');
2145
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2146
            $this->assertEquals(
2147
              <<<EOF
2148
custom message\nFailed asserting that 'foo' starts with "prefix".
2149
2150
EOF
2151
              ,
2152
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2153
            );
2154
2155
            return;
2156
        }
2157
2158
        $this->fail();
2159
    }
2160
2161
    public function testConstraintStringStartsNotWith()
2162
    {
2163
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2164
          PHPUnit_Framework_Assert::stringStartsWith('prefix')
2165
        );
2166
2167
        $this->assertTrue($constraint->evaluate('foo', '', true));
2168
        $this->assertFalse($constraint->evaluate('prefixfoo', '', true));
2169
        $this->assertEquals('starts not with "prefix"', $constraint->toString());
2170
        $this->assertCount(1, $constraint);
2171
2172
        try {
2173
            $constraint->evaluate('prefixfoo');
2174
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2175
            $this->assertEquals(
2176
              <<<EOF
2177
Failed asserting that 'prefixfoo' starts not with "prefix".
2178
2179
EOF
2180
              ,
2181
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2182
            );
2183
2184
            return;
2185
        }
2186
2187
        $this->fail();
2188
    }
2189
2190
    public function testConstraintStringStartsNotWith2()
2191
    {
2192
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2193
          PHPUnit_Framework_Assert::stringStartsWith('prefix')
2194
        );
2195
2196
        try {
2197
            $constraint->evaluate('prefixfoo', 'custom message');
2198
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2199
            $this->assertEquals(
2200
              <<<EOF
2201
custom message
2202
Failed asserting that 'prefixfoo' starts not with "prefix".
2203
2204
EOF
2205
              ,
2206
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2207
            );
2208
2209
            return;
2210
        }
2211
2212
        $this->fail();
2213
    }
2214
2215
    public function testConstraintStringContains()
2216
    {
2217
        $constraint = PHPUnit_Framework_Assert::stringContains('foo');
2218
2219
        $this->assertFalse($constraint->evaluate('barbazbar', '', true));
2220
        $this->assertTrue($constraint->evaluate('barfoobar', '', true));
2221
        $this->assertEquals('contains "foo"', $constraint->toString());
2222
        $this->assertCount(1, $constraint);
2223
2224
        try {
2225
            $constraint->evaluate('barbazbar');
2226
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2227
            $this->assertEquals(
2228
              <<<EOF
2229
Failed asserting that 'barbazbar' contains "foo".
2230
2231
EOF
2232
              ,
2233
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2234
            );
2235
2236
            return;
2237
        }
2238
2239
        $this->fail();
2240
    }
2241
2242
    public function testConstraintStringContainsWhenIgnoreCase()
2243
    {
2244
        $constraint = PHPUnit_Framework_Assert::stringContains('oryginał', true);
2245
2246
        $this->assertFalse($constraint->evaluate('oryginal', '', true));
2247
        $this->assertTrue($constraint->evaluate('ORYGINAŁ', '', true));
2248
        $this->assertTrue($constraint->evaluate('oryginał', '', true));
2249
        $this->assertEquals('contains "oryginał"', $constraint->toString());
2250
        $this->assertEquals(1, count($constraint));
2251
2252
        try {
2253
            $constraint->evaluate('oryginal');
2254
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2255
            $this->assertEquals(
2256
                <<<EOF
2257
Failed asserting that 'oryginal' contains "oryginał".
2258
2259
EOF
2260
                ,
2261
                PHPUnit_Framework_TestFailure::exceptionToString($e)
2262
            );
2263
2264
            return;
2265
        }
2266
2267
        $this->fail();
2268
    }
2269
2270
    public function testConstraintStringContainsForUtf8StringWhenNotIgnoreCase()
2271
    {
2272
        $constraint = PHPUnit_Framework_Assert::stringContains('oryginał', false);
2273
2274
        $this->assertFalse($constraint->evaluate('oryginal', '', true));
2275
        $this->assertFalse($constraint->evaluate('ORYGINAŁ', '', true));
2276
        $this->assertTrue($constraint->evaluate('oryginał', '', true));
2277
        $this->assertEquals('contains "oryginał"', $constraint->toString());
2278
        $this->assertEquals(1, count($constraint));
2279
2280
        try {
2281
            $constraint->evaluate('oryginal');
2282
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2283
            $this->assertEquals(
2284
                <<<EOF
2285
Failed asserting that 'oryginal' contains "oryginał".
2286
2287
EOF
2288
                ,
2289
                PHPUnit_Framework_TestFailure::exceptionToString($e)
2290
            );
2291
2292
            return;
2293
        }
2294
2295
        $this->fail();
2296
    }
2297
2298
    public function testConstraintStringContains2()
2299
    {
2300
        $constraint = PHPUnit_Framework_Assert::stringContains('foo');
2301
2302
        try {
2303
            $constraint->evaluate('barbazbar', 'custom message');
2304
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2305
            $this->assertEquals(
2306
              <<<EOF
2307
custom message
2308
Failed asserting that 'barbazbar' contains "foo".
2309
2310
EOF
2311
              ,
2312
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2313
            );
2314
2315
            return;
2316
        }
2317
2318
        $this->fail();
2319
    }
2320
2321
    public function testConstraintStringNotContains()
2322
    {
2323
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2324
          PHPUnit_Framework_Assert::stringContains('foo')
2325
        );
2326
2327
        $this->assertTrue($constraint->evaluate('barbazbar', '', true));
2328
        $this->assertFalse($constraint->evaluate('barfoobar', '', true));
2329
        $this->assertEquals('does not contain "foo"', $constraint->toString());
2330
        $this->assertCount(1, $constraint);
2331
2332
        try {
2333
            $constraint->evaluate('barfoobar');
2334
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2335
            $this->assertEquals(
2336
              <<<EOF
2337
Failed asserting that 'barfoobar' does not contain "foo".
2338
2339
EOF
2340
              ,
2341
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2342
            );
2343
2344
            return;
2345
        }
2346
2347
        $this->fail();
2348
    }
2349
2350
    public function testConstraintStringNotContainsWhenIgnoreCase()
2351
    {
2352
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2353
            PHPUnit_Framework_Assert::stringContains('oryginał')
2354
        );
2355
2356
        $this->assertTrue($constraint->evaluate('original', '', true));
2357
        $this->assertFalse($constraint->evaluate('ORYGINAŁ', '', true));
2358
        $this->assertFalse($constraint->evaluate('oryginał', '', true));
2359
        $this->assertEquals('does not contain "oryginał"', $constraint->toString());
2360
        $this->assertEquals(1, count($constraint));
2361
2362
        try {
2363
            $constraint->evaluate('ORYGINAŁ');
2364
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2365
            $this->assertEquals(
2366
                <<<EOF
2367
Failed asserting that 'ORYGINAŁ' does not contain "oryginał".
2368
2369
EOF
2370
                ,
2371
                PHPUnit_Framework_TestFailure::exceptionToString($e)
2372
            );
2373
2374
            return;
2375
        }
2376
2377
        $this->fail();
2378
    }
2379
2380
    public function testConstraintStringNotContainsForUtf8StringWhenNotIgnoreCase()
2381
    {
2382
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2383
            PHPUnit_Framework_Assert::stringContains('oryginał', false)
2384
        );
2385
2386
        $this->assertTrue($constraint->evaluate('original', '', true));
2387
        $this->assertTrue($constraint->evaluate('ORYGINAŁ', '', true));
2388
        $this->assertFalse($constraint->evaluate('oryginał', '', true));
2389
        $this->assertEquals('does not contain "oryginał"', $constraint->toString());
2390
        $this->assertEquals(1, count($constraint));
2391
2392
        try {
2393
            $constraint->evaluate('oryginał');
2394
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2395
            $this->assertEquals(
2396
                <<<EOF
2397
Failed asserting that 'oryginał' does not contain "oryginał".
2398
2399
EOF
2400
                ,
2401
                PHPUnit_Framework_TestFailure::exceptionToString($e)
2402
            );
2403
2404
            return;
2405
        }
2406
2407
        $this->fail();
2408
    }
2409
2410
    public function testConstraintStringNotContains2()
2411
    {
2412
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2413
          PHPUnit_Framework_Assert::stringContains('foo')
2414
        );
2415
2416
        try {
2417
            $constraint->evaluate('barfoobar', 'custom message');
2418
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2419
            $this->assertEquals(
2420
              <<<EOF
2421
custom message
2422
Failed asserting that 'barfoobar' does not contain "foo".
2423
2424
EOF
2425
              ,
2426
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2427
            );
2428
2429
            return;
2430
        }
2431
2432
        $this->fail();
2433
    }
2434
2435
    public function testConstraintStringEndsWith()
2436
    {
2437
        $constraint = PHPUnit_Framework_Assert::stringEndsWith('suffix');
2438
2439
        $this->assertFalse($constraint->evaluate('foo', '', true));
2440
        $this->assertTrue($constraint->evaluate('foosuffix', '', true));
2441
        $this->assertEquals('ends with "suffix"', $constraint->toString());
2442
        $this->assertCount(1, $constraint);
2443
2444
        try {
2445
            $constraint->evaluate('foo');
2446
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2447
            $this->assertEquals(
2448
              <<<EOF
2449
Failed asserting that 'foo' ends with "suffix".
2450
2451
EOF
2452
              ,
2453
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2454
            );
2455
2456
            return;
2457
        }
2458
2459
        $this->fail();
2460
    }
2461
2462
    public function testConstraintStringEndsWith2()
2463
    {
2464
        $constraint = PHPUnit_Framework_Assert::stringEndsWith('suffix');
2465
2466
        try {
2467
            $constraint->evaluate('foo', 'custom message');
2468
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2469
            $this->assertEquals(
2470
              <<<EOF
2471
custom message
2472
Failed asserting that 'foo' ends with "suffix".
2473
2474
EOF
2475
              ,
2476
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2477
            );
2478
2479
            return;
2480
        }
2481
2482
        $this->fail();
2483
    }
2484
2485
    public function testConstraintStringEndsNotWith()
2486
    {
2487
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2488
          PHPUnit_Framework_Assert::stringEndsWith('suffix')
2489
        );
2490
2491
        $this->assertTrue($constraint->evaluate('foo', '', true));
2492
        $this->assertFalse($constraint->evaluate('foosuffix', '', true));
2493
        $this->assertEquals('ends not with "suffix"', $constraint->toString());
2494
        $this->assertCount(1, $constraint);
2495
2496
        try {
2497
            $constraint->evaluate('foosuffix');
2498
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2499
            $this->assertEquals(
2500
              <<<EOF
2501
Failed asserting that 'foosuffix' ends not with "suffix".
2502
2503
EOF
2504
              ,
2505
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2506
            );
2507
2508
            return;
2509
        }
2510
2511
        $this->fail();
2512
    }
2513
2514
    public function testConstraintStringEndsNotWith2()
2515
    {
2516
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2517
          PHPUnit_Framework_Assert::stringEndsWith('suffix')
2518
        );
2519
2520
        try {
2521
            $constraint->evaluate('foosuffix', 'custom message');
2522
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2523
            $this->assertEquals(
2524
              <<<EOF
2525
custom message
2526
Failed asserting that 'foosuffix' ends not with "suffix".
2527
2528
EOF
2529
              ,
2530
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2531
            );
2532
2533
            return;
2534
        }
2535
2536
        $this->fail();
2537
    }
2538
2539
    public function testConstraintArrayContainsCheckForObjectIdentity()
2540
    {
2541
        // Check for primitive type.
2542
        $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo', true, true);
2543
2544
        $this->assertFalse($constraint->evaluate([0], '', true));
2545
        $this->assertFalse($constraint->evaluate([true], '', true));
2546
2547
        // Default case.
2548
        $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
2549
2550
        $this->assertTrue($constraint->evaluate([0], '', true));
2551
        $this->assertTrue($constraint->evaluate([true], '', true));
2552
    }
2553
2554
    public function testConstraintArrayContains()
2555
    {
2556
        $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
2557
2558
        $this->assertFalse($constraint->evaluate(['bar'], '', true));
2559
        $this->assertTrue($constraint->evaluate(['foo'], '', true));
2560
        $this->assertEquals("contains 'foo'", $constraint->toString());
2561
        $this->assertCount(1, $constraint);
2562
2563
        try {
2564
            $constraint->evaluate(['bar']);
2565
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2566
            $this->assertEquals(
2567
              <<<EOF
2568
Failed asserting that an array contains 'foo'.
2569
2570
EOF
2571
              ,
2572
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2573
            );
2574
2575
            return;
2576
        }
2577
2578
        $this->fail();
2579
    }
2580
2581
    public function testConstraintArrayContains2()
2582
    {
2583
        $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
2584
2585
        try {
2586
            $constraint->evaluate(['bar'], 'custom message');
2587
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2588
            $this->assertEquals(
2589
              <<<EOF
2590
custom message
2591
Failed asserting that an array contains 'foo'.
2592
2593
EOF
2594
              ,
2595
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2596
            );
2597
2598
            return;
2599
        }
2600
2601
        $this->fail();
2602
    }
2603
2604
    public function testConstraintArrayNotContains()
2605
    {
2606
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2607
          new PHPUnit_Framework_Constraint_TraversableContains('foo')
2608
        );
2609
2610
        $this->assertTrue($constraint->evaluate(['bar'], '', true));
2611
        $this->assertFalse($constraint->evaluate(['foo'], '', true));
2612
        $this->assertEquals("does not contain 'foo'", $constraint->toString());
2613
        $this->assertCount(1, $constraint);
2614
2615
        try {
2616
            $constraint->evaluate(['foo']);
2617
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2618
            $this->assertEquals(
2619
              <<<EOF
2620
Failed asserting that an array does not contain 'foo'.
2621
2622
EOF
2623
              ,
2624
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2625
            );
2626
2627
            return;
2628
        }
2629
2630
        $this->fail();
2631
    }
2632
2633
    public function testConstraintArrayNotContains2()
2634
    {
2635
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2636
          new PHPUnit_Framework_Constraint_TraversableContains('foo')
2637
        );
2638
2639
        try {
2640
            $constraint->evaluate(['foo'], 'custom message');
2641
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2642
            $this->assertEquals(
2643
              <<<EOF
2644
custom message
2645
Failed asserting that an array does not contain 'foo'.
2646
2647
EOF
2648
              ,
2649
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2650
            );
2651
2652
            return;
2653
        }
2654
2655
        $this->fail();
2656
    }
2657
2658
    public function testConstraintSplObjectStorageContains()
2659
    {
2660
        $object     = new StdClass;
2661
        $constraint = new PHPUnit_Framework_Constraint_TraversableContains($object);
2662
        $this->assertStringMatchesFormat('contains stdClass Object &%s ()', $constraint->toString());
2663
2664
        $storage = new SplObjectStorage;
2665
        $this->assertFalse($constraint->evaluate($storage, '', true));
2666
2667
        $storage->attach($object);
2668
        $this->assertTrue($constraint->evaluate($storage, '', true));
2669
2670
        try {
2671
            $constraint->evaluate(new SplObjectStorage);
2672
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2673
            $this->assertStringMatchesFormat(
2674
              <<<EOF
2675
Failed asserting that a traversable contains stdClass Object &%x ().
2676
2677
EOF
2678
              ,
2679
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2680
            );
2681
2682
            return;
2683
        }
2684
2685
        $this->fail();
2686
    }
2687
2688
    public function testConstraintSplObjectStorageContains2()
2689
    {
2690
        $object     = new StdClass;
2691
        $constraint = new PHPUnit_Framework_Constraint_TraversableContains($object);
2692
2693
        try {
2694
            $constraint->evaluate(new SplObjectStorage, 'custom message');
2695
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2696
            $this->assertStringMatchesFormat(
2697
              <<<EOF
2698
custom message
2699
Failed asserting that a traversable contains stdClass Object &%x ().
2700
2701
EOF
2702
              ,
2703
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2704
            );
2705
2706
            return;
2707
        }
2708
2709
        $this->fail();
2710
    }
2711
2712
    public function testAttributeEqualTo()
2713
    {
2714
        $object     = new ClassWithNonPublicAttributes;
2715
        $constraint = PHPUnit_Framework_Assert::attributeEqualTo('foo', 1);
2716
2717
        $this->assertTrue($constraint->evaluate($object, '', true));
2718
        $this->assertEquals('attribute "foo" is equal to 1', $constraint->toString());
2719
        $this->assertCount(1, $constraint);
2720
2721
        $constraint = PHPUnit_Framework_Assert::attributeEqualTo('foo', 2);
2722
2723
        $this->assertFalse($constraint->evaluate($object, '', true));
2724
2725
        try {
2726
            $constraint->evaluate($object);
2727
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2728
            $this->assertEquals(
2729
              <<<EOF
2730
Failed asserting that attribute "foo" is equal to 2.
2731
2732
EOF
2733
              ,
2734
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2735
            );
2736
2737
            return;
2738
        }
2739
2740
        $this->fail();
2741
    }
2742
2743
    public function testAttributeEqualTo2()
2744
    {
2745
        $object     = new ClassWithNonPublicAttributes;
2746
        $constraint = PHPUnit_Framework_Assert::attributeEqualTo('foo', 2);
2747
2748
        try {
2749
            $constraint->evaluate($object, 'custom message');
2750
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2751
            $this->assertEquals(
2752
              <<<EOF
2753
custom message\nFailed asserting that attribute "foo" is equal to 2.
2754
2755
EOF
2756
              ,
2757
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2758
            );
2759
2760
            return;
2761
        }
2762
2763
        $this->fail();
2764
    }
2765
2766
    public function testAttributeNotEqualTo()
2767
    {
2768
        $object     = new ClassWithNonPublicAttributes;
2769
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2770
          PHPUnit_Framework_Assert::attributeEqualTo('foo', 2)
2771
        );
2772
2773
        $this->assertTrue($constraint->evaluate($object, '', true));
2774
        $this->assertEquals('attribute "foo" is not equal to 2', $constraint->toString());
2775
        $this->assertCount(1, $constraint);
2776
2777
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2778
          PHPUnit_Framework_Assert::attributeEqualTo('foo', 1)
2779
        );
2780
2781
        $this->assertFalse($constraint->evaluate($object, '', true));
2782
2783
        try {
2784
            $constraint->evaluate($object);
2785
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2786
            $this->assertEquals(
2787
              <<<EOF
2788
Failed asserting that attribute "foo" is not equal to 1.
2789
2790
EOF
2791
              ,
2792
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2793
            );
2794
2795
            return;
2796
        }
2797
2798
        $this->fail();
2799
    }
2800
2801
    public function testAttributeNotEqualTo2()
2802
    {
2803
        $object     = new ClassWithNonPublicAttributes;
2804
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2805
          PHPUnit_Framework_Assert::attributeEqualTo('foo', 1)
2806
        );
2807
2808
        try {
2809
            $constraint->evaluate($object, 'custom message');
2810
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2811
            $this->assertEquals(
2812
              <<<EOF
2813
custom message\nFailed asserting that attribute "foo" is not equal to 1.
2814
2815
EOF
2816
              ,
2817
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2818
            );
2819
2820
            return;
2821
        }
2822
2823
        $this->fail();
2824
    }
2825
2826
    public function testConstraintIsEmpty()
2827
    {
2828
        $constraint = new PHPUnit_Framework_Constraint_IsEmpty;
2829
2830
        $this->assertFalse($constraint->evaluate(['foo'], '', true));
2831
        $this->assertTrue($constraint->evaluate([], '', true));
2832
        $this->assertFalse($constraint->evaluate(new ArrayObject(['foo']), '', true));
2833
        $this->assertTrue($constraint->evaluate(new ArrayObject([]), '', true));
2834
        $this->assertEquals('is empty', $constraint->toString());
2835
        $this->assertCount(1, $constraint);
2836
2837
        try {
2838
            $constraint->evaluate(['foo']);
2839
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2840
            $this->assertEquals(
2841
              <<<EOF
2842
Failed asserting that an array is empty.
2843
2844
EOF
2845
              ,
2846
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2847
            );
2848
2849
            return;
2850
        }
2851
2852
        $this->fail();
2853
    }
2854
2855
    public function testConstraintIsEmpty2()
2856
    {
2857
        $constraint = new PHPUnit_Framework_Constraint_IsEmpty;
2858
2859
        try {
2860
            $constraint->evaluate(['foo'], 'custom message');
2861
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2862
            $this->assertEquals(
2863
              <<<EOF
2864
custom message\nFailed asserting that an array is empty.
2865
2866
EOF
2867
              ,
2868
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2869
            );
2870
2871
            return;
2872
        }
2873
2874
        $this->fail();
2875
    }
2876
2877
    public function testConstraintCountWithAnArray()
2878
    {
2879
        $constraint = new PHPUnit_Framework_Constraint_Count(5);
2880
2881
        $this->assertTrue($constraint->evaluate([1, 2, 3, 4, 5], '', true));
2882
        $this->assertFalse($constraint->evaluate([1, 2, 3, 4], '', true));
2883
    }
2884
2885
    public function testConstraintCountWithAnIteratorWhichDoesNotImplementCountable()
2886
    {
2887
        $constraint = new PHPUnit_Framework_Constraint_Count(5);
2888
2889
        $this->assertTrue($constraint->evaluate(new TestIterator([1, 2, 3, 4, 5]), '', true));
2890
        $this->assertFalse($constraint->evaluate(new TestIterator([1, 2, 3, 4]), '', true));
2891
    }
2892
2893
    public function testConstraintCountWithAnObjectImplementingCountable()
2894
    {
2895
        $constraint = new PHPUnit_Framework_Constraint_Count(5);
2896
2897
        $this->assertTrue($constraint->evaluate(new ArrayObject([1, 2, 3, 4, 5]), '', true));
2898
        $this->assertFalse($constraint->evaluate(new ArrayObject([1, 2, 3, 4]), '', true));
2899
    }
2900
2901
    public function testConstraintCountFailing()
2902
    {
2903
        $constraint = new PHPUnit_Framework_Constraint_Count(5);
2904
2905
        try {
2906
            $constraint->evaluate([1, 2]);
2907
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2908
            $this->assertEquals(
2909
              <<<EOF
2910
Failed asserting that actual size 2 matches expected size 5.
2911
2912
EOF
2913
              ,
2914
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2915
            );
2916
2917
            return;
2918
        }
2919
2920
        $this->fail();
2921
    }
2922
2923
    public function testConstraintNotCountFailing()
2924
    {
2925
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2926
          new PHPUnit_Framework_Constraint_Count(2)
2927
        );
2928
2929
        try {
2930
            $constraint->evaluate([1, 2]);
2931
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2932
            $this->assertEquals(
2933
              <<<EOF
2934
Failed asserting that actual size 2 does not match expected size 2.
2935
2936
EOF
2937
              ,
2938
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2939
            );
2940
2941
            return;
2942
        }
2943
2944
        $this->fail();
2945
    }
2946
2947
    public function testConstraintSameSizeWithAnArray()
2948
    {
2949
        $constraint = new PHPUnit_Framework_Constraint_SameSize([1, 2, 3, 4, 5]);
2950
2951
        $this->assertTrue($constraint->evaluate([6, 7, 8, 9, 10], '', true));
2952
        $this->assertFalse($constraint->evaluate([1, 2, 3, 4], '', true));
2953
    }
2954
2955
    public function testConstraintSameSizeWithAnIteratorWhichDoesNotImplementCountable()
2956
    {
2957
        $constraint = new PHPUnit_Framework_Constraint_SameSize(new TestIterator([1, 2, 3, 4, 5]));
2958
2959
        $this->assertTrue($constraint->evaluate(new TestIterator([6, 7, 8, 9, 10]), '', true));
2960
        $this->assertFalse($constraint->evaluate(new TestIterator([1, 2, 3, 4]), '', true));
2961
    }
2962
2963
    public function testConstraintSameSizeWithAnObjectImplementingCountable()
2964
    {
2965
        $constraint = new PHPUnit_Framework_Constraint_SameSize(new ArrayObject([1, 2, 3, 4, 5]));
2966
2967
        $this->assertTrue($constraint->evaluate(new ArrayObject([6, 7, 8, 9, 10]), '', true));
2968
        $this->assertFalse($constraint->evaluate(new ArrayObject([1, 2, 3, 4]), '', true));
2969
    }
2970
2971
    public function testConstraintSameSizeFailing()
2972
    {
2973
        $constraint = new PHPUnit_Framework_Constraint_SameSize([1, 2, 3, 4, 5]);
2974
2975
        try {
2976
            $constraint->evaluate([1, 2]);
2977
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2978
            $this->assertEquals(
2979
              <<<EOF
2980
Failed asserting that actual size 2 matches expected size 5.
2981
2982
EOF
2983
              ,
2984
              PHPUnit_Framework_TestFailure::exceptionToString($e)
2985
            );
2986
2987
            return;
2988
        }
2989
2990
        $this->fail();
2991
    }
2992
2993
    public function testConstraintNotSameSizeFailing()
2994
    {
2995
        $constraint = PHPUnit_Framework_Assert::logicalNot(
2996
          new PHPUnit_Framework_Constraint_SameSize([1, 2])
2997
        );
2998
2999
        try {
3000
            $constraint->evaluate([3, 4]);
3001
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3002
            $this->assertEquals(
3003
              <<<EOF
3004
Failed asserting that actual size 2 does not match expected size 2.
3005
3006
EOF
3007
              ,
3008
              PHPUnit_Framework_TestFailure::exceptionToString($e)
3009
            );
3010
3011
            return;
3012
        }
3013
3014
        $this->fail();
3015
    }
3016
3017
    public function testConstraintException()
3018
    {
3019
        $constraint = new PHPUnit_Framework_Constraint_Exception('FoobarException');
3020
        $exception  = new DummyException('Test');
3021
        $stackTrace = PHPUnit_Util_Filter::getFilteredStacktrace($exception);
3022
3023
        try {
3024
            $constraint->evaluate($exception);
3025
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3026
            $this->assertEquals(
3027
              <<<EOF
3028
Failed asserting that exception of type "DummyException" matches expected exception "FoobarException". Message was: "Test" at
3029
$stackTrace.
3030
3031
EOF
3032
                ,
3033
                PHPUnit_Framework_TestFailure::exceptionToString($e)
3034
            );
3035
3036
            return;
3037
        }
3038
3039
        $this->fail();
3040
    }
3041
3042
    /**
3043
     * Removes spaces in front of newlines
3044
     *
3045
     * @param string $string
3046
     *
3047
     * @return string
3048
     */
3049
    private function trimnl($string)
3050
    {
3051
        return preg_replace('/[ ]*\n/', "\n", $string);
3052
    }
3053
}
3054