3
* This file is part of PHPUnit.
5
* (c) Sebastian Bergmann <sebastian@phpunit.de>
7
* For the full copyright and license information, please view the LICENSE
8
* file that was distributed with this source code.
15
* @author Sebastian Bergmann <sebastian@phpunit.de>
16
* @author Bernhard Schussek <bschussek@2bepublished.at>
17
* @copyright Sebastian Bergmann <sebastian@phpunit.de>
18
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
19
* @link http://www.phpunit.de/
20
* @since Class available since Release 3.0.0
22
class Framework_ConstraintTest extends PHPUnit_Framework_TestCase
25
* @covers PHPUnit_Framework_Constraint_ArrayHasKey
26
* @covers PHPUnit_Framework_Assert::arrayHasKey
27
* @covers PHPUnit_Framework_Constraint::count
28
* @covers PHPUnit_Framework_TestFailure::exceptionToString
30
public function testConstraintArrayHasKey()
32
$constraint = PHPUnit_Framework_Assert::arrayHasKey(0);
34
$this->assertFalse($constraint->evaluate(array(), '', true));
35
$this->assertEquals('has the key 0', $constraint->toString());
36
$this->assertEquals(1, count($constraint));
39
$constraint->evaluate(array());
42
catch (PHPUnit_Framework_ExpectationFailedException $e) {
43
$this->assertEquals(<<<EOF
44
Failed asserting that an array has the key 0.
48
PHPUnit_Framework_TestFailure::exceptionToString($e)
58
* @covers PHPUnit_Framework_Constraint_ArrayHasKey
59
* @covers PHPUnit_Framework_Assert::arrayHasKey
60
* @covers PHPUnit_Framework_TestFailure::exceptionToString
62
public function testConstraintArrayHasKey2()
64
$constraint = PHPUnit_Framework_Assert::arrayHasKey(0);
67
$constraint->evaluate(array(), 'custom message');
70
catch (PHPUnit_Framework_ExpectationFailedException $e) {
73
custom message\nFailed asserting that an array has the key 0.
77
PHPUnit_Framework_TestFailure::exceptionToString($e)
87
* @covers PHPUnit_Framework_Constraint_ArrayHasKey
88
* @covers PHPUnit_Framework_Constraint_Not
89
* @covers PHPUnit_Framework_Assert::arrayHasKey
90
* @covers PHPUnit_Framework_Assert::logicalNot
91
* @covers PHPUnit_Framework_TestFailure::exceptionToString
93
public function testConstraintArrayNotHasKey()
95
$constraint = PHPUnit_Framework_Assert::logicalNot(
96
PHPUnit_Framework_Assert::arrayHasKey(0)
99
$this->assertFalse($constraint->evaluate(array(0 => 1), '', true));
100
$this->assertEquals('does not have the key 0', $constraint->toString());
101
$this->assertEquals(1, count($constraint));
104
$constraint->evaluate(array(0 => 1));
107
catch (PHPUnit_Framework_ExpectationFailedException $e) {
110
Failed asserting that an array does not have the key 0.
114
PHPUnit_Framework_TestFailure::exceptionToString($e)
124
* @covers PHPUnit_Framework_Constraint_ArrayHasKey
125
* @covers PHPUnit_Framework_Constraint_Not
126
* @covers PHPUnit_Framework_Assert::arrayHasKey
127
* @covers PHPUnit_Framework_Assert::logicalNot
128
* @covers PHPUnit_Framework_TestFailure::exceptionToString
130
public function testConstraintArrayNotHasKey2()
132
$constraint = PHPUnit_Framework_Assert::logicalNot(
133
PHPUnit_Framework_Assert::arrayHasKey(0)
137
$constraint->evaluate(array(0), 'custom message');
140
catch (PHPUnit_Framework_ExpectationFailedException $e) {
144
Failed asserting that an array does not have the key 0.
148
PHPUnit_Framework_TestFailure::exceptionToString($e)
158
* @covers PHPUnit_Framework_Constraint_FileExists
159
* @covers PHPUnit_Framework_Assert::fileExists
160
* @covers PHPUnit_Framework_Constraint::count
161
* @covers PHPUnit_Framework_TestFailure::exceptionToString
163
public function testConstraintFileExists()
165
$constraint = PHPUnit_Framework_Assert::fileExists();
167
$this->assertFalse($constraint->evaluate('foo', '', true));
168
$this->assertEquals('file exists', $constraint->toString());
169
$this->assertEquals(1, count($constraint));
172
$constraint->evaluate('foo');
175
catch (PHPUnit_Framework_ExpectationFailedException $e) {
178
Failed asserting that file "foo" exists.
182
PHPUnit_Framework_TestFailure::exceptionToString($e)
192
* @covers PHPUnit_Framework_Constraint_FileExists
193
* @covers PHPUnit_Framework_Assert::fileExists
194
* @covers PHPUnit_Framework_TestFailure::exceptionToString
196
public function testConstraintFileExists2()
198
$constraint = PHPUnit_Framework_Assert::fileExists();
201
$constraint->evaluate('foo', 'custom message');
204
catch (PHPUnit_Framework_ExpectationFailedException $e) {
205
$this->assertEquals(<<<EOF
207
Failed asserting that file "foo" exists.
211
PHPUnit_Framework_TestFailure::exceptionToString($e)
221
* @covers PHPUnit_Framework_Constraint_FileExists
222
* @covers PHPUnit_Framework_Constraint_Not
223
* @covers PHPUnit_Framework_Assert::logicalNot
224
* @covers PHPUnit_Framework_Assert::fileExists
225
* @covers PHPUnit_Framework_TestFailure::exceptionToString
227
public function testConstraintFileNotExists()
229
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ClassWithNonPublicAttributes.php';
231
$constraint = PHPUnit_Framework_Assert::logicalNot(
232
PHPUnit_Framework_Assert::fileExists()
235
$this->assertFalse($constraint->evaluate($file, '', true));
236
$this->assertEquals('file does not exist', $constraint->toString());
237
$this->assertEquals(1, count($constraint));
240
$constraint->evaluate($file);
243
catch (PHPUnit_Framework_ExpectationFailedException $e) {
246
Failed asserting that file "$file" does not exist.
250
PHPUnit_Framework_TestFailure::exceptionToString($e)
260
* @covers PHPUnit_Framework_Constraint_FileExists
261
* @covers PHPUnit_Framework_Constraint_Not
262
* @covers PHPUnit_Framework_Assert::logicalNot
263
* @covers PHPUnit_Framework_Assert::fileExists
264
* @covers PHPUnit_Framework_TestFailure::exceptionToString
266
public function testConstraintFileNotExists2()
268
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ClassWithNonPublicAttributes.php';
270
$constraint = PHPUnit_Framework_Assert::logicalNot(
271
PHPUnit_Framework_Assert::fileExists()
275
$constraint->evaluate($file, 'custom message');
278
catch (PHPUnit_Framework_ExpectationFailedException $e) {
279
$this->assertEquals(<<<EOF
281
Failed asserting that file "$file" does not exist.
285
PHPUnit_Framework_TestFailure::exceptionToString($e)
295
* @covers PHPUnit_Framework_Constraint_GreaterThan
296
* @covers PHPUnit_Framework_Assert::greaterThan
297
* @covers PHPUnit_Framework_Constraint::count
298
* @covers PHPUnit_Framework_TestFailure::exceptionToString
300
public function testConstraintGreaterThan()
302
$constraint = PHPUnit_Framework_Assert::greaterThan(1);
304
$this->assertFalse($constraint->evaluate(0, '', true));
305
$this->assertTrue($constraint->evaluate(2, '', true));
306
$this->assertEquals('is greater than 1', $constraint->toString());
307
$this->assertEquals(1, count($constraint));
310
$constraint->evaluate(0);
313
catch (PHPUnit_Framework_ExpectationFailedException $e) {
316
Failed asserting that 0 is greater than 1.
320
PHPUnit_Framework_TestFailure::exceptionToString($e)
330
* @covers PHPUnit_Framework_Constraint_GreaterThan
331
* @covers PHPUnit_Framework_Assert::greaterThan
332
* @covers PHPUnit_Framework_TestFailure::exceptionToString
334
public function testConstraintGreaterThan2()
336
$constraint = PHPUnit_Framework_Assert::greaterThan(1);
339
$constraint->evaluate(0, 'custom message');
342
catch (PHPUnit_Framework_ExpectationFailedException $e) {
346
Failed asserting that 0 is greater than 1.
350
PHPUnit_Framework_TestFailure::exceptionToString($e)
360
* @covers PHPUnit_Framework_Constraint_GreaterThan
361
* @covers PHPUnit_Framework_Constraint_Not
362
* @covers PHPUnit_Framework_Assert::greaterThan
363
* @covers PHPUnit_Framework_Assert::logicalNot
364
* @covers PHPUnit_Framework_TestFailure::exceptionToString
366
public function testConstraintNotGreaterThan()
368
$constraint = PHPUnit_Framework_Assert::logicalNot(
369
PHPUnit_Framework_Assert::greaterThan(1)
372
$this->assertTrue($constraint->evaluate(1, '', true));
373
$this->assertEquals('is not greater than 1', $constraint->toString());
374
$this->assertEquals(1, count($constraint));
377
$constraint->evaluate(2);
380
catch (PHPUnit_Framework_ExpectationFailedException $e) {
383
Failed asserting that 2 is not greater than 1.
387
PHPUnit_Framework_TestFailure::exceptionToString($e)
397
* @covers PHPUnit_Framework_Constraint_GreaterThan
398
* @covers PHPUnit_Framework_Constraint_Not
399
* @covers PHPUnit_Framework_Assert::greaterThan
400
* @covers PHPUnit_Framework_Assert::logicalNot
401
* @covers PHPUnit_Framework_TestFailure::exceptionToString
403
public function testConstraintNotGreaterThan2()
405
$constraint = PHPUnit_Framework_Assert::logicalNot(
406
PHPUnit_Framework_Assert::greaterThan(1)
410
$constraint->evaluate(2, 'custom message');
413
catch (PHPUnit_Framework_ExpectationFailedException $e) {
417
Failed asserting that 2 is not greater than 1.
421
PHPUnit_Framework_TestFailure::exceptionToString($e)
431
* @covers PHPUnit_Framework_Constraint_IsEqual
432
* @covers PHPUnit_Framework_Constraint_GreaterThan
433
* @covers PHPUnit_Framework_Constraint_Or
434
* @covers PHPUnit_Framework_Assert::greaterThanOrEqual
435
* @covers PHPUnit_Framework_TestFailure::exceptionToString
437
public function testConstraintGreaterThanOrEqual()
439
$constraint = PHPUnit_Framework_Assert::greaterThanOrEqual(1);
441
$this->assertTrue($constraint->evaluate(1, '', true));
442
$this->assertFalse($constraint->evaluate(0, '', true));
443
$this->assertEquals('is equal to 1 or is greater than 1', $constraint->toString());
444
$this->assertEquals(2, count($constraint));
447
$constraint->evaluate(0);
450
catch (PHPUnit_Framework_ExpectationFailedException $e) {
453
Failed asserting that 0 is equal to 1 or is greater than 1.
457
PHPUnit_Framework_TestFailure::exceptionToString($e)
467
* @covers PHPUnit_Framework_Constraint_IsEqual
468
* @covers PHPUnit_Framework_Constraint_GreaterThan
469
* @covers PHPUnit_Framework_Constraint_Or
470
* @covers PHPUnit_Framework_Assert::greaterThanOrEqual
471
* @covers PHPUnit_Framework_TestFailure::exceptionToString
473
public function testConstraintGreaterThanOrEqual2()
475
$constraint = PHPUnit_Framework_Assert::greaterThanOrEqual(1);
478
$constraint->evaluate(0, 'custom message');
481
catch (PHPUnit_Framework_ExpectationFailedException $e) {
485
Failed asserting that 0 is equal to 1 or is greater than 1.
489
PHPUnit_Framework_TestFailure::exceptionToString($e)
499
* @covers PHPUnit_Framework_Constraint_IsEqual
500
* @covers PHPUnit_Framework_Constraint_GreaterThan
501
* @covers PHPUnit_Framework_Constraint_Or
502
* @covers PHPUnit_Framework_Constraint_Not
503
* @covers PHPUnit_Framework_Assert::greaterThanOrEqual
504
* @covers PHPUnit_Framework_Assert::logicalNot
505
* @covers PHPUnit_Framework_TestFailure::exceptionToString
507
public function testConstraintNotGreaterThanOrEqual()
509
$constraint = PHPUnit_Framework_Assert::logicalNot(
510
PHPUnit_Framework_Assert::greaterThanOrEqual(1)
513
$this->assertFalse($constraint->evaluate(1, '', true));
514
$this->assertEquals('not( is equal to 1 or is greater than 1 )', $constraint->toString());
515
$this->assertEquals(2, count($constraint));
518
$constraint->evaluate(1);
521
catch (PHPUnit_Framework_ExpectationFailedException $e) {
524
Failed asserting that not( 1 is equal to 1 or is greater than 1 ).
528
PHPUnit_Framework_TestFailure::exceptionToString($e)
538
* @covers PHPUnit_Framework_Constraint_IsEqual
539
* @covers PHPUnit_Framework_Constraint_GreaterThan
540
* @covers PHPUnit_Framework_Constraint_Or
541
* @covers PHPUnit_Framework_Constraint_Not
542
* @covers PHPUnit_Framework_Assert::greaterThanOrEqual
543
* @covers PHPUnit_Framework_Assert::logicalNot
544
* @covers PHPUnit_Framework_TestFailure::exceptionToString
546
public function testConstraintNotGreaterThanOrEqual2()
548
$constraint = PHPUnit_Framework_Assert::logicalNot(
549
PHPUnit_Framework_Assert::greaterThanOrEqual(1)
553
$constraint->evaluate(1, 'custom message');
556
catch (PHPUnit_Framework_ExpectationFailedException $e) {
560
Failed asserting that not( 1 is equal to 1 or is greater than 1 ).
564
PHPUnit_Framework_TestFailure::exceptionToString($e)
574
* @covers PHPUnit_Framework_Constraint_IsAnything
575
* @covers PHPUnit_Framework_Assert::anything
576
* @covers PHPUnit_Framework_Constraint::count
577
* @covers PHPUnit_Framework_TestFailure::exceptionToString
579
public function testConstraintIsAnything()
581
$constraint = PHPUnit_Framework_Assert::anything();
583
$this->assertTrue($constraint->evaluate(null, '', true));
584
$this->assertNull($constraint->evaluate(null));
585
$this->assertEquals('is anything', $constraint->toString());
586
$this->assertEquals(0, count($constraint));
590
* @covers PHPUnit_Framework_Constraint_IsAnything
591
* @covers PHPUnit_Framework_Constraint_Not
592
* @covers PHPUnit_Framework_Assert::anything
593
* @covers PHPUnit_Framework_Assert::logicalNot
594
* @covers PHPUnit_Framework_TestFailure::exceptionToString
596
public function testConstraintNotIsAnything()
598
$constraint = PHPUnit_Framework_Assert::logicalNot(
599
PHPUnit_Framework_Assert::anything()
602
$this->assertFalse($constraint->evaluate(null, '', true));
603
$this->assertEquals('is not anything', $constraint->toString());
604
$this->assertEquals(0, count($constraint));
607
$constraint->evaluate(null);
610
catch (PHPUnit_Framework_ExpectationFailedException $e) {
613
Failed asserting that null is not anything.
617
PHPUnit_Framework_TestFailure::exceptionToString($e)
627
* @covers PHPUnit_Framework_Constraint_IsEqual
628
* @covers PHPUnit_Framework_Assert::equalTo
629
* @covers PHPUnit_Framework_Constraint::count
630
* @covers PHPUnit_Framework_TestFailure::exceptionToString
632
public function testConstraintIsEqual()
634
$constraint = PHPUnit_Framework_Assert::equalTo(1);
636
$this->assertTrue($constraint->evaluate(1, '', true));
637
$this->assertFalse($constraint->evaluate(0, '', true));
638
$this->assertEquals('is equal to 1', $constraint->toString());
639
$this->assertEquals(1, count($constraint));
642
$constraint->evaluate(0);
645
catch (PHPUnit_Framework_ExpectationFailedException $e) {
648
Failed asserting that 0 matches expected 1.
652
PHPUnit_Framework_TestFailure::exceptionToString($e)
661
public function isEqualProvider()
666
$ahash = spl_object_hash($a);
667
$bhash = spl_object_hash($b);
672
$c->array = array(0, array(1), array(2), 3);
673
$c->related = new stdClass;
674
$c->related->foo = "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk";
680
$d->array = array(0, array(4), array(2), 3);
681
$d->related = new stdClass;
682
$d->related->foo = "a\np\nc\nd\ne\nf\ng\nh\ni\nw\nk";
686
$storage1 = new SplObjectStorage;
687
$storage1->attach($a);
688
$storage1->attach($b);
689
$storage2 = new SplObjectStorage;
690
$storage2->attach($b);
691
$storage1hash = spl_object_hash($storage1);
692
$storage2hash = spl_object_hash($storage2);
694
$dom1 = new DOMDocument;
695
$dom1->preserveWhiteSpace = false;
696
$dom1->loadXML('<root></root>');
697
$dom2 = new DOMDocument;
698
$dom2->preserveWhiteSpace = false;
699
$dom2->loadXML('<root><foo/></root>');
703
Failed asserting that 0 matches expected 1.
708
Failed asserting that 0 matches expected 1.1.
712
array('a', 'b', <<<EOF
713
Failed asserting that two strings are equal.
722
array("a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk", "a\np\nc\nd\ne\nf\ng\nh\ni\nw\nk", <<<EOF
723
Failed asserting that two strings are equal.
739
array(1, array(0), <<<EOF
740
Array (...) does not match expected type "integer".
744
array(array(0), 1, <<<EOF
745
1 does not match expected type "array".
749
array(array(0), array(1), <<<EOF
750
Failed asserting that two arrays are equal.
761
array(array(true), array('true'), <<<EOF
762
Failed asserting that two arrays are equal.
773
array(array(0, array(1), array(2), 3), array(0, array(4), array(2), 3), <<<EOF
774
Failed asserting that two arrays are equal.
790
array($a, array(0), <<<EOF
791
Array (...) does not match expected type "object".
795
array(array(0), $a, <<<EOF
796
stdClass Object (...) does not match expected type "array".
801
Failed asserting that two objects are equal.
812
Failed asserting that two objects are equal.
837
'self' => stdClass Object (...)
838
'c' => stdClass Object (...)
843
array($storage1, $storage2, <<<EOF
844
Failed asserting that two objects are equal.
848
-SplObjectStorage Object &$storage1hash (
849
- '$ahash' => Array &0 (
850
- 'obj' => stdClass Object &$ahash (
853
+SplObjectStorage Object &$storage2hash (
854
+ '$bhash' => Array &0 (
855
+ 'obj' => stdClass Object &$bhash ()
858
- '$bhash' => Array &0
863
array($dom1, $dom2, <<<EOF
864
Failed asserting that two DOM documents are equal.
868
<?xml version="1.0"?>
877
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
878
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/Chicago')),
880
Failed asserting that two DateTime objects are equal.
884
-2013-03-29T04:13:35-0400
885
+2013-03-29T04:13:35-0500
893
* @dataProvider isEqualProvider
894
* @covers PHPUnit_Framework_Constraint_IsEqual
895
* @covers PHPUnit_Framework_Assert::equalTo
896
* @covers PHPUnit_Framework_TestFailure::exceptionToString
898
public function testConstraintIsEqual2($expected, $actual, $message)
900
$constraint = PHPUnit_Framework_Assert::equalTo($expected);
903
$constraint->evaluate($actual, 'custom message');
906
catch (PHPUnit_Framework_ExpectationFailedException $e) {
908
"custom message\n$message",
909
$this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
919
* @covers PHPUnit_Framework_Constraint_IsEqual
920
* @covers PHPUnit_Framework_Constraint_Not
921
* @covers PHPUnit_Framework_Assert::equalTo
922
* @covers PHPUnit_Framework_Assert::logicalNot
923
* @covers PHPUnit_Framework_TestFailure::exceptionToString
925
public function testConstraintIsNotEqual()
927
$constraint = PHPUnit_Framework_Assert::logicalNot(
928
PHPUnit_Framework_Assert::equalTo(1)
931
$this->assertTrue($constraint->evaluate(0, '', true));
932
$this->assertFalse($constraint->evaluate(1, '', true));
933
$this->assertEquals('is not equal to 1', $constraint->toString());
934
$this->assertEquals(1, count($constraint));
937
$constraint->evaluate(1);
940
catch (PHPUnit_Framework_ExpectationFailedException $e) {
943
Failed asserting that 1 is not equal to 1.
947
PHPUnit_Framework_TestFailure::exceptionToString($e)
957
* @covers PHPUnit_Framework_Constraint_IsEqual
958
* @covers PHPUnit_Framework_Constraint_Not
959
* @covers PHPUnit_Framework_Assert::equalTo
960
* @covers PHPUnit_Framework_Assert::logicalNot
961
* @covers PHPUnit_Framework_TestFailure::exceptionToString
963
public function testConstraintIsNotEqual2()
965
$constraint = PHPUnit_Framework_Assert::logicalNot(
966
PHPUnit_Framework_Assert::equalTo(1)
970
$constraint->evaluate(1, 'custom message');
973
catch (PHPUnit_Framework_ExpectationFailedException $e) {
977
Failed asserting that 1 is not equal to 1.
981
PHPUnit_Framework_TestFailure::exceptionToString($e)
991
* @covers PHPUnit_Framework_Constraint_IsIdentical
992
* @covers PHPUnit_Framework_Assert::identicalTo
993
* @covers PHPUnit_Framework_Constraint::count
994
* @covers PHPUnit_Framework_TestFailure::exceptionToString
996
public function testConstraintIsIdentical()
1001
$constraint = PHPUnit_Framework_Assert::identicalTo($a);
1003
$this->assertFalse($constraint->evaluate($b, '', true));
1004
$this->assertTrue($constraint->evaluate($a, '', true));
1005
$this->assertEquals('is identical to an object of class "stdClass"', $constraint->toString());
1006
$this->assertEquals(1, count($constraint));
1009
$constraint->evaluate($b);
1012
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1013
$this->assertEquals(<<<EOF
1014
Failed asserting that two variables reference the same object.
1018
PHPUnit_Framework_TestFailure::exceptionToString($e)
1028
* @covers PHPUnit_Framework_Constraint_IsIdentical
1029
* @covers PHPUnit_Framework_Assert::identicalTo
1030
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1032
public function testConstraintIsIdentical2()
1037
$constraint = PHPUnit_Framework_Assert::identicalTo($a);
1040
$constraint->evaluate($b, 'custom message');
1043
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1044
$this->assertEquals(<<<EOF
1046
Failed asserting that two variables reference the same object.
1050
PHPUnit_Framework_TestFailure::exceptionToString($e)
1060
* @covers PHPUnit_Framework_Constraint_IsIdentical
1061
* @covers PHPUnit_Framework_Assert::identicalTo
1062
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1064
public function testConstraintIsIdentical3()
1066
$constraint = PHPUnit_Framework_Assert::identicalTo('a');
1069
$constraint->evaluate('b', 'custom message');
1072
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1073
$this->assertEquals(<<<EOF
1075
Failed asserting that two strings are identical.
1084
PHPUnit_Framework_TestFailure::exceptionToString($e)
1094
* @covers PHPUnit_Framework_Constraint_IsIdentical
1095
* @covers PHPUnit_Framework_Constraint_Not
1096
* @covers PHPUnit_Framework_Assert::identicalTo
1097
* @covers PHPUnit_Framework_Assert::logicalNot
1098
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1100
public function testConstraintIsNotIdentical()
1105
$constraint = PHPUnit_Framework_Assert::logicalNot(
1106
PHPUnit_Framework_Assert::identicalTo($a)
1109
$this->assertTrue($constraint->evaluate($b, '', true));
1110
$this->assertFalse($constraint->evaluate($a, '', true));
1111
$this->assertEquals('is not identical to an object of class "stdClass"', $constraint->toString());
1112
$this->assertEquals(1, count($constraint));
1115
$constraint->evaluate($a);
1118
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1119
$this->assertEquals(<<<EOF
1120
Failed asserting that two variables don't reference the same object.
1124
$this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1134
* @covers PHPUnit_Framework_Constraint_IsIdentical
1135
* @covers PHPUnit_Framework_Constraint_Not
1136
* @covers PHPUnit_Framework_Assert::identicalTo
1137
* @covers PHPUnit_Framework_Assert::logicalNot
1138
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1140
public function testConstraintIsNotIdentical2()
1144
$constraint = PHPUnit_Framework_Assert::logicalNot(
1145
PHPUnit_Framework_Assert::identicalTo($a)
1149
$constraint->evaluate($a, 'custom message');
1152
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1153
$this->assertEquals(<<<EOF
1155
Failed asserting that two variables don't reference the same object.
1159
PHPUnit_Framework_TestFailure::exceptionToString($e)
1169
* @covers PHPUnit_Framework_Constraint_IsIdentical
1170
* @covers PHPUnit_Framework_Constraint_Not
1171
* @covers PHPUnit_Framework_Assert::identicalTo
1172
* @covers PHPUnit_Framework_Assert::logicalNot
1173
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1175
public function testConstraintIsNotIdentical3()
1177
$constraint = PHPUnit_Framework_Assert::logicalNot(
1178
PHPUnit_Framework_Assert::identicalTo('a')
1182
$constraint->evaluate('a', 'custom message');
1185
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1186
$this->assertEquals(<<<EOF
1188
Failed asserting that two strings are not identical.
1192
$this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1202
* @covers PHPUnit_Framework_Constraint_IsInstanceOf
1203
* @covers PHPUnit_Framework_Assert::isInstanceOf
1204
* @covers PHPUnit_Framework_Constraint::count
1205
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1207
public function testConstraintIsInstanceOf()
1209
$constraint = PHPUnit_Framework_Assert::isInstanceOf('Exception');
1211
$this->assertFalse($constraint->evaluate(new stdClass, '', true));
1212
$this->assertTrue($constraint->evaluate(new Exception, '', true));
1213
$this->assertEquals('is instance of class "Exception"', $constraint->toString());
1214
$this->assertEquals(1, count($constraint));
1216
$interfaceConstraint = PHPUnit_Framework_Assert::isInstanceOf('Countable');
1217
$this->assertFalse($interfaceConstraint->evaluate(new stdClass, '', true));
1218
$this->assertTrue($interfaceConstraint->evaluate(new ArrayObject, '', true));
1219
$this->assertEquals('is instance of interface "Countable"', $interfaceConstraint->toString());
1222
$constraint->evaluate(new stdClass);
1225
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1226
$this->assertEquals(
1228
Failed asserting that stdClass Object () is an instance of class "Exception".
1232
PHPUnit_Framework_TestFailure::exceptionToString($e)
1242
* @covers PHPUnit_Framework_Constraint_IsInstanceOf
1243
* @covers PHPUnit_Framework_Assert::isInstanceOf
1244
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1246
public function testConstraintIsInstanceOf2()
1248
$constraint = PHPUnit_Framework_Assert::isInstanceOf('Exception');
1251
$constraint->evaluate(new stdClass, 'custom message');
1254
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1255
$this->assertEquals(<<<EOF
1257
Failed asserting that stdClass Object () is an instance of class "Exception".
1261
PHPUnit_Framework_TestFailure::exceptionToString($e)
1271
* @covers PHPUnit_Framework_Constraint_IsInstanceOf
1272
* @covers PHPUnit_Framework_Constraint_Not
1273
* @covers PHPUnit_Framework_Assert::isInstanceOf
1274
* @covers PHPUnit_Framework_Assert::logicalNot
1275
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1277
public function testConstraintIsNotInstanceOf()
1279
$constraint = PHPUnit_Framework_Assert::logicalNot(
1280
PHPUnit_Framework_Assert::isInstanceOf('stdClass')
1283
$this->assertFalse($constraint->evaluate(new stdClass, '', true));
1284
$this->assertTrue($constraint->evaluate(new Exception, '', true));
1285
$this->assertEquals('is not instance of class "stdClass"', $constraint->toString());
1286
$this->assertEquals(1, count($constraint));
1289
$constraint->evaluate(new stdClass);
1292
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1293
$this->assertEquals(
1295
Failed asserting that stdClass Object () is not an instance of class "stdClass".
1299
PHPUnit_Framework_TestFailure::exceptionToString($e)
1309
* @covers PHPUnit_Framework_Constraint_IsInstanceOf
1310
* @covers PHPUnit_Framework_Constraint_Not
1311
* @covers PHPUnit_Framework_Assert::isInstanceOf
1312
* @covers PHPUnit_Framework_Assert::logicalNot
1313
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1315
public function testConstraintIsNotInstanceOf2()
1317
$constraint = PHPUnit_Framework_Assert::logicalNot(
1318
PHPUnit_Framework_Assert::isInstanceOf('stdClass')
1322
$constraint->evaluate(new stdClass, 'custom message');
1325
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1326
$this->assertEquals(<<<EOF
1328
Failed asserting that stdClass Object () is not an instance of class "stdClass".
1332
PHPUnit_Framework_TestFailure::exceptionToString($e)
1342
* @covers PHPUnit_Framework_Constraint_IsType
1343
* @covers PHPUnit_Framework_Assert::isType
1344
* @covers PHPUnit_Framework_Constraint::count
1345
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1347
public function testConstraintIsType()
1349
$constraint = PHPUnit_Framework_Assert::isType('string');
1351
$this->assertFalse($constraint->evaluate(0, '', true));
1352
$this->assertTrue($constraint->evaluate('', '', true));
1353
$this->assertEquals('is of type "string"', $constraint->toString());
1354
$this->assertEquals(1, count($constraint));
1357
$constraint->evaluate(new stdClass);
1360
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1361
$this->assertStringMatchesFormat(<<<EOF
1362
Failed asserting that stdClass Object &%x () is of type "string".
1366
$this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1376
* @covers PHPUnit_Framework_Constraint_IsType
1377
* @covers PHPUnit_Framework_Assert::isType
1378
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1380
public function testConstraintIsType2()
1382
$constraint = PHPUnit_Framework_Assert::isType('string');
1385
$constraint->evaluate(new stdClass, 'custom message');
1388
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1389
$this->assertStringMatchesFormat(<<<EOF
1391
Failed asserting that stdClass Object &%x () is of type "string".
1395
$this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1405
* @covers PHPUnit_Framework_Constraint_IsType
1406
* @covers PHPUnit_Framework_Constraint_Not
1407
* @covers PHPUnit_Framework_Assert::isType
1408
* @covers PHPUnit_Framework_Assert::logicalNot
1409
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1411
public function testConstraintIsNotType()
1413
$constraint = PHPUnit_Framework_Assert::logicalNot(
1414
PHPUnit_Framework_Assert::isType('string')
1417
$this->assertTrue($constraint->evaluate(0, '', true));
1418
$this->assertFalse($constraint->evaluate('', '', true));
1419
$this->assertEquals('is not of type "string"', $constraint->toString());
1420
$this->assertEquals(1, count($constraint));
1423
$constraint->evaluate('');
1426
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1427
$this->assertEquals(
1429
Failed asserting that '' is not of type "string".
1433
PHPUnit_Framework_TestFailure::exceptionToString($e)
1443
* @covers PHPUnit_Framework_Constraint_IsType
1444
* @covers PHPUnit_Framework_Constraint_Not
1445
* @covers PHPUnit_Framework_Assert::isType
1446
* @covers PHPUnit_Framework_Assert::logicalNot
1447
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1449
public function testConstraintIsNotType2()
1451
$constraint = PHPUnit_Framework_Assert::logicalNot(
1452
PHPUnit_Framework_Assert::isType('string')
1456
$constraint->evaluate('', 'custom message');
1459
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1460
$this->assertEquals(<<<EOF
1462
Failed asserting that '' is not of type "string".
1466
PHPUnit_Framework_TestFailure::exceptionToString($e)
1476
* @covers PHPUnit_Framework_Constraint_IsNull
1477
* @covers PHPUnit_Framework_Assert::isNull
1478
* @covers PHPUnit_Framework_Constraint::count
1479
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1481
public function testConstraintIsNull()
1483
$constraint = PHPUnit_Framework_Assert::isNull();
1485
$this->assertFalse($constraint->evaluate(0, '', true));
1486
$this->assertTrue($constraint->evaluate(null, '', true));
1487
$this->assertEquals('is null', $constraint->toString());
1488
$this->assertEquals(1, count($constraint));
1491
$constraint->evaluate(0);
1494
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1495
$this->assertEquals(<<<EOF
1496
Failed asserting that 0 is null.
1500
PHPUnit_Framework_TestFailure::exceptionToString($e)
1510
* @covers PHPUnit_Framework_Constraint_IsNull
1511
* @covers PHPUnit_Framework_Assert::isNull
1512
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1514
public function testConstraintIsNull2()
1516
$constraint = PHPUnit_Framework_Assert::isNull();
1519
$constraint->evaluate(0, 'custom message');
1522
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1523
$this->assertEquals(<<<EOF
1525
Failed asserting that 0 is null.
1529
PHPUnit_Framework_TestFailure::exceptionToString($e)
1539
* @covers PHPUnit_Framework_Constraint_IsNull
1540
* @covers PHPUnit_Framework_Constraint_Not
1541
* @covers PHPUnit_Framework_Assert::isNull
1542
* @covers PHPUnit_Framework_Assert::logicalNot
1543
* @covers PHPUnit_Framework_Constraint::count
1544
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1546
public function testConstraintIsNotNull()
1548
$constraint = PHPUnit_Framework_Assert::logicalNot(
1549
PHPUnit_Framework_Assert::isNull()
1552
$this->assertFalse($constraint->evaluate(null, '', true));
1553
$this->assertTrue($constraint->evaluate(0, '', true));
1554
$this->assertEquals('is not null', $constraint->toString());
1555
$this->assertEquals(1, count($constraint));
1558
$constraint->evaluate(null);
1561
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1562
$this->assertEquals(<<<EOF
1563
Failed asserting that null is not null.
1567
PHPUnit_Framework_TestFailure::exceptionToString($e)
1577
* @covers PHPUnit_Framework_Constraint_IsNull
1578
* @covers PHPUnit_Framework_Constraint_Not
1579
* @covers PHPUnit_Framework_Assert::isNull
1580
* @covers PHPUnit_Framework_Assert::logicalNot
1581
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1583
public function testConstraintIsNotNull2()
1585
$constraint = PHPUnit_Framework_Assert::logicalNot(
1586
PHPUnit_Framework_Assert::isNull()
1590
$constraint->evaluate(null, 'custom message');
1593
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1594
$this->assertEquals(<<<EOF
1596
Failed asserting that null is not null.
1600
PHPUnit_Framework_TestFailure::exceptionToString($e)
1610
* @covers PHPUnit_Framework_Constraint_LessThan
1611
* @covers PHPUnit_Framework_Assert::lessThan
1612
* @covers PHPUnit_Framework_Constraint::count
1613
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1615
public function testConstraintLessThan()
1617
$constraint = PHPUnit_Framework_Assert::lessThan(1);
1619
$this->assertTrue($constraint->evaluate(0, '', true));
1620
$this->assertFalse($constraint->evaluate(1, '', true));
1621
$this->assertEquals('is less than 1', $constraint->toString());
1622
$this->assertEquals(1, count($constraint));
1625
$constraint->evaluate(1);
1628
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1629
$this->assertEquals(
1631
Failed asserting that 1 is less than 1.
1635
PHPUnit_Framework_TestFailure::exceptionToString($e)
1645
* @covers PHPUnit_Framework_Constraint_LessThan
1646
* @covers PHPUnit_Framework_Assert::lessThan
1647
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1649
public function testConstraintLessThan2()
1651
$constraint = PHPUnit_Framework_Assert::lessThan(1);
1654
$constraint->evaluate(1, 'custom message');
1657
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1658
$this->assertEquals(
1661
Failed asserting that 1 is less than 1.
1665
PHPUnit_Framework_TestFailure::exceptionToString($e)
1675
* @covers PHPUnit_Framework_Constraint_LessThan
1676
* @covers PHPUnit_Framework_Constraint_Not
1677
* @covers PHPUnit_Framework_Assert::lessThan
1678
* @covers PHPUnit_Framework_Assert::logicalNot
1679
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1681
public function testConstraintNotLessThan()
1683
$constraint = PHPUnit_Framework_Assert::logicalNot(
1684
PHPUnit_Framework_Assert::lessThan(1)
1687
$this->assertTrue($constraint->evaluate(1, '', true));
1688
$this->assertFalse($constraint->evaluate(0, '', true));
1689
$this->assertEquals('is not less than 1', $constraint->toString());
1690
$this->assertEquals(1, count($constraint));
1693
$constraint->evaluate(0);
1696
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1697
$this->assertEquals(
1699
Failed asserting that 0 is not less than 1.
1703
PHPUnit_Framework_TestFailure::exceptionToString($e)
1713
* @covers PHPUnit_Framework_Constraint_LessThan
1714
* @covers PHPUnit_Framework_Constraint_Not
1715
* @covers PHPUnit_Framework_Assert::lessThan
1716
* @covers PHPUnit_Framework_Assert::logicalNot
1717
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1719
public function testConstraintNotLessThan2()
1721
$constraint = PHPUnit_Framework_Assert::logicalNot(
1722
PHPUnit_Framework_Assert::lessThan(1)
1726
$constraint->evaluate(0, 'custom message');
1729
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1730
$this->assertEquals(
1733
Failed asserting that 0 is not less than 1.
1737
PHPUnit_Framework_TestFailure::exceptionToString($e)
1747
* @covers PHPUnit_Framework_Constraint_IsEqual
1748
* @covers PHPUnit_Framework_Constraint_LessThan
1749
* @covers PHPUnit_Framework_Constraint_Or
1750
* @covers PHPUnit_Framework_Assert::lessThanOrEqual
1751
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1753
public function testConstraintLessThanOrEqual()
1755
$constraint = PHPUnit_Framework_Assert::lessThanOrEqual(1);
1757
$this->assertTrue($constraint->evaluate(1, '', true));
1758
$this->assertFalse($constraint->evaluate(2, '', true));
1759
$this->assertEquals('is equal to 1 or is less than 1', $constraint->toString());
1760
$this->assertEquals(2, count($constraint));
1763
$constraint->evaluate(2);
1766
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1767
$this->assertEquals(
1769
Failed asserting that 2 is equal to 1 or is less than 1.
1773
PHPUnit_Framework_TestFailure::exceptionToString($e)
1783
* @covers PHPUnit_Framework_Constraint_Callback
1785
public function testConstraintCallback()
1787
$closureReflect = function($parameter) {
1791
$closureWithoutParameter = function() {
1795
$constraint = PHPUnit_Framework_Assert::callback($closureWithoutParameter);
1796
$this->assertTrue($constraint->evaluate('', '', true));
1798
$constraint = PHPUnit_Framework_Assert::callback($closureReflect);
1799
$this->assertTrue($constraint->evaluate(true, '', true));
1800
$this->assertFalse($constraint->evaluate(false, '', true));
1802
$callback = array($this, 'callbackReturningTrue');
1803
$constraint = PHPUnit_Framework_Assert::callback($callback);
1804
$this->assertTrue($constraint->evaluate(false, '', true));
1806
$callback = array('Framework_ConstraintTest', 'staticCallbackReturningTrue');
1807
$constraint = PHPUnit_Framework_Assert::callback($callback);
1808
$this->assertTrue($constraint->evaluate(null, '', true));
1810
$this->assertEquals('is accepted by specified callback', $constraint->toString());
1814
* @covers PHPUnit_Framework_Constraint_Callback
1815
* @expectedException PHPUnit_Framework_ExpectationFailedException
1816
* @expectedExceptionMessage Failed asserting that 'This fails' is accepted by specified callback.
1818
public function testConstraintCallbackFailure()
1820
$constraint = PHPUnit_Framework_Assert::callback(function() {
1823
$constraint->evaluate('This fails');
1826
public function callbackReturningTrue()
1831
public static function staticCallbackReturningTrue()
1837
* @covers PHPUnit_Framework_Constraint_IsEqual
1838
* @covers PHPUnit_Framework_Constraint_LessThan
1839
* @covers PHPUnit_Framework_Constraint_Or
1840
* @covers PHPUnit_Framework_Assert::lessThanOrEqual
1841
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1843
public function testConstraintLessThanOrEqual2()
1845
$constraint = PHPUnit_Framework_Assert::lessThanOrEqual(1);
1848
$constraint->evaluate(2, 'custom message');
1851
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1852
$this->assertEquals(
1855
Failed asserting that 2 is equal to 1 or is less than 1.
1859
PHPUnit_Framework_TestFailure::exceptionToString($e)
1869
* @covers PHPUnit_Framework_Constraint_IsEqual
1870
* @covers PHPUnit_Framework_Constraint_LessThan
1871
* @covers PHPUnit_Framework_Constraint_Or
1872
* @covers PHPUnit_Framework_Constraint_Not
1873
* @covers PHPUnit_Framework_Assert::lessThanOrEqual
1874
* @covers PHPUnit_Framework_Assert::logicalNot
1875
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1877
public function testConstraintNotLessThanOrEqual()
1879
$constraint = PHPUnit_Framework_Assert::logicalNot(
1880
PHPUnit_Framework_Assert::lessThanOrEqual(1)
1883
$this->assertTrue($constraint->evaluate(2, '', true));
1884
$this->assertFalse($constraint->evaluate(1, '', true));
1885
$this->assertEquals('not( is equal to 1 or is less than 1 )', $constraint->toString());
1886
$this->assertEquals(2, count($constraint));
1889
$constraint->evaluate(1);
1892
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1893
$this->assertEquals(
1895
Failed asserting that not( 1 is equal to 1 or is less than 1 ).
1899
PHPUnit_Framework_TestFailure::exceptionToString($e)
1909
* @covers PHPUnit_Framework_Constraint_IsEqual
1910
* @covers PHPUnit_Framework_Constraint_LessThan
1911
* @covers PHPUnit_Framework_Constraint_Or
1912
* @covers PHPUnit_Framework_Constraint_Not
1913
* @covers PHPUnit_Framework_Assert::lessThanOrEqual
1914
* @covers PHPUnit_Framework_Assert::logicalNot
1915
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1917
public function testConstraintNotLessThanOrEqual2()
1919
$constraint = PHPUnit_Framework_Assert::logicalNot(
1920
PHPUnit_Framework_Assert::lessThanOrEqual(1)
1924
$constraint->evaluate(1, 'custom message');
1927
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1928
$this->assertEquals(
1931
Failed asserting that not( 1 is equal to 1 or is less than 1 ).
1935
PHPUnit_Framework_TestFailure::exceptionToString($e)
1945
* @covers PHPUnit_Framework_Constraint_ClassHasAttribute
1946
* @covers PHPUnit_Framework_Assert::classHasAttribute
1947
* @covers PHPUnit_Framework_Constraint::count
1948
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1950
public function testConstraintClassHasAttribute()
1952
$constraint = PHPUnit_Framework_Assert::classHasAttribute('privateAttribute');
1954
$this->assertTrue($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
1955
$this->assertFalse($constraint->evaluate('stdClass', '', true));
1956
$this->assertEquals('has attribute "privateAttribute"', $constraint->toString());
1957
$this->assertEquals(1, count($constraint));
1960
$constraint->evaluate('stdClass');
1963
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1964
$this->assertEquals(
1966
Failed asserting that class "stdClass" has attribute "privateAttribute".
1970
PHPUnit_Framework_TestFailure::exceptionToString($e)
1980
* @covers PHPUnit_Framework_Constraint_ClassHasAttribute
1981
* @covers PHPUnit_Framework_Assert::classHasAttribute
1982
* @covers PHPUnit_Framework_TestFailure::exceptionToString
1984
public function testConstraintClassHasAttribute2()
1986
$constraint = PHPUnit_Framework_Assert::classHasAttribute('privateAttribute');
1989
$constraint->evaluate('stdClass', 'custom message');
1992
catch (PHPUnit_Framework_ExpectationFailedException $e) {
1993
$this->assertEquals(<<<EOF
1995
Failed asserting that class "stdClass" has attribute "privateAttribute".
1999
PHPUnit_Framework_TestFailure::exceptionToString($e)
2009
* @covers PHPUnit_Framework_Constraint_ClassHasAttribute
2010
* @covers PHPUnit_Framework_Constraint_Not
2011
* @covers PHPUnit_Framework_Assert::classHasAttribute
2012
* @covers PHPUnit_Framework_Assert::logicalNot
2013
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2015
public function testConstraintClassNotHasAttribute()
2017
$constraint = PHPUnit_Framework_Assert::logicalNot(
2018
PHPUnit_Framework_Assert::classHasAttribute('privateAttribute')
2021
$this->assertTrue($constraint->evaluate('stdClass', '', true));
2022
$this->assertFalse($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
2023
$this->assertEquals('does not have attribute "privateAttribute"', $constraint->toString());
2024
$this->assertEquals(1, count($constraint));
2027
$constraint->evaluate('ClassWithNonPublicAttributes');
2030
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2031
$this->assertEquals(
2033
Failed asserting that class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
2037
PHPUnit_Framework_TestFailure::exceptionToString($e)
2047
* @covers PHPUnit_Framework_Constraint_ClassHasAttribute
2048
* @covers PHPUnit_Framework_Constraint_Not
2049
* @covers PHPUnit_Framework_Assert::classHasAttribute
2050
* @covers PHPUnit_Framework_Assert::logicalNot
2051
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2053
public function testConstraintClassNotHasAttribute2()
2055
$constraint = PHPUnit_Framework_Assert::logicalNot(
2056
PHPUnit_Framework_Assert::classHasAttribute('privateAttribute')
2060
$constraint->evaluate('ClassWithNonPublicAttributes', 'custom message');
2063
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2064
$this->assertEquals(<<<EOF
2066
Failed asserting that class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
2070
PHPUnit_Framework_TestFailure::exceptionToString($e)
2080
* @covers PHPUnit_Framework_Constraint_ClassHasStaticAttribute
2081
* @covers PHPUnit_Framework_Assert::classHasStaticAttribute
2082
* @covers PHPUnit_Framework_Constraint::count
2083
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2085
public function testConstraintClassHasStaticAttribute()
2087
$constraint = PHPUnit_Framework_Assert::classHasStaticAttribute('privateStaticAttribute');
2089
$this->assertTrue($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
2090
$this->assertFalse($constraint->evaluate('stdClass', '', true));
2091
$this->assertEquals('has static attribute "privateStaticAttribute"', $constraint->toString());
2092
$this->assertEquals(1, count($constraint));
2095
$constraint->evaluate('stdClass');
2098
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2099
$this->assertEquals(
2101
Failed asserting that class "stdClass" has static attribute "privateStaticAttribute".
2105
PHPUnit_Framework_TestFailure::exceptionToString($e)
2115
* @covers PHPUnit_Framework_Constraint_ClassHasStaticAttribute
2116
* @covers PHPUnit_Framework_Assert::classHasStaticAttribute
2117
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2119
public function testConstraintClassHasStaticAttribute2()
2121
$constraint = PHPUnit_Framework_Assert::classHasStaticAttribute('foo');
2124
$constraint->evaluate('stdClass', 'custom message');
2127
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2128
$this->assertEquals(<<<EOF
2130
Failed asserting that class "stdClass" has static attribute "foo".
2134
PHPUnit_Framework_TestFailure::exceptionToString($e)
2144
* @covers PHPUnit_Framework_Constraint_ClassHasStaticAttribute
2145
* @covers PHPUnit_Framework_Constraint_Not
2146
* @covers PHPUnit_Framework_Assert::classHasStaticAttribute
2147
* @covers PHPUnit_Framework_Assert::logicalNot
2148
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2150
public function testConstraintClassNotHasStaticAttribute()
2152
$constraint = PHPUnit_Framework_Assert::logicalNot(
2153
PHPUnit_Framework_Assert::classHasStaticAttribute('privateStaticAttribute')
2156
$this->assertTrue($constraint->evaluate('stdClass', '', true));
2157
$this->assertFalse($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
2158
$this->assertEquals('does not have static attribute "privateStaticAttribute"', $constraint->toString());
2159
$this->assertEquals(1, count($constraint));
2162
$constraint->evaluate('ClassWithNonPublicAttributes');
2165
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2166
$this->assertEquals(
2168
Failed asserting that class "ClassWithNonPublicAttributes" does not have static attribute "privateStaticAttribute".
2172
PHPUnit_Framework_TestFailure::exceptionToString($e)
2182
* @covers PHPUnit_Framework_Constraint_ClassHasStaticAttribute
2183
* @covers PHPUnit_Framework_Constraint_Not
2184
* @covers PHPUnit_Framework_Assert::classHasStaticAttribute
2185
* @covers PHPUnit_Framework_Assert::logicalNot
2186
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2188
public function testConstraintClassNotHasStaticAttribute2()
2190
$constraint = PHPUnit_Framework_Assert::logicalNot(
2191
PHPUnit_Framework_Assert::classHasStaticAttribute('privateStaticAttribute')
2195
$constraint->evaluate('ClassWithNonPublicAttributes', 'custom message');
2198
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2199
$this->assertEquals(<<<EOF
2201
Failed asserting that class "ClassWithNonPublicAttributes" does not have static attribute "privateStaticAttribute".
2205
PHPUnit_Framework_TestFailure::exceptionToString($e)
2215
* @covers PHPUnit_Framework_Constraint_ObjectHasAttribute
2216
* @covers PHPUnit_Framework_Assert::objectHasAttribute
2217
* @covers PHPUnit_Framework_Constraint::count
2218
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2220
public function testConstraintObjectHasAttribute()
2222
$constraint = PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute');
2224
$this->assertTrue($constraint->evaluate(new ClassWithNonPublicAttributes, '', true));
2225
$this->assertFalse($constraint->evaluate(new stdClass, '', true));
2226
$this->assertEquals('has attribute "privateAttribute"', $constraint->toString());
2227
$this->assertEquals(1, count($constraint));
2230
$constraint->evaluate(new stdClass);
2233
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2234
$this->assertEquals(
2236
Failed asserting that object of class "stdClass" has attribute "privateAttribute".
2240
PHPUnit_Framework_TestFailure::exceptionToString($e)
2250
* @covers PHPUnit_Framework_Constraint_ObjectHasAttribute
2251
* @covers PHPUnit_Framework_Assert::objectHasAttribute
2252
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2254
public function testConstraintObjectHasAttribute2()
2256
$constraint = PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute');
2259
$constraint->evaluate(new stdClass, 'custom message');
2262
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2263
$this->assertEquals(<<<EOF
2265
Failed asserting that object of class "stdClass" has attribute "privateAttribute".
2269
PHPUnit_Framework_TestFailure::exceptionToString($e)
2279
* @covers PHPUnit_Framework_Constraint_ObjectHasAttribute
2280
* @covers PHPUnit_Framework_Constraint_Not
2281
* @covers PHPUnit_Framework_Assert::objectHasAttribute
2282
* @covers PHPUnit_Framework_Assert::logicalNot
2283
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2285
public function testConstraintObjectNotHasAttribute()
2287
$constraint = PHPUnit_Framework_Assert::logicalNot(
2288
PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute')
2291
$this->assertTrue($constraint->evaluate(new stdClass, '', true));
2292
$this->assertFalse($constraint->evaluate(new ClassWithNonPublicAttributes, '', true));
2293
$this->assertEquals('does not have attribute "privateAttribute"', $constraint->toString());
2294
$this->assertEquals(1, count($constraint));
2297
$constraint->evaluate(new ClassWithNonPublicAttributes);
2300
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2301
$this->assertEquals(
2303
Failed asserting that object of class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
2307
PHPUnit_Framework_TestFailure::exceptionToString($e)
2317
* @covers PHPUnit_Framework_Constraint_ObjectHasAttribute
2318
* @covers PHPUnit_Framework_Constraint_Not
2319
* @covers PHPUnit_Framework_Assert::objectHasAttribute
2320
* @covers PHPUnit_Framework_Assert::logicalNot
2321
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2323
public function testConstraintObjectNotHasAttribute2()
2325
$constraint = PHPUnit_Framework_Assert::logicalNot(
2326
PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute')
2330
$constraint->evaluate(new ClassWithNonPublicAttributes, 'custom message');
2333
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2334
$this->assertEquals(<<<EOF
2336
Failed asserting that object of class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
2340
PHPUnit_Framework_TestFailure::exceptionToString($e)
2350
* @covers PHPUnit_Framework_Constraint_PCREMatch
2351
* @covers PHPUnit_Framework_Assert::matchesRegularExpression
2352
* @covers PHPUnit_Framework_Constraint::count
2353
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2355
public function testConstraintPCREMatch()
2357
$constraint = PHPUnit_Framework_Assert::matchesRegularExpression('/foo/');
2359
$this->assertFalse($constraint->evaluate('barbazbar', '', true));
2360
$this->assertTrue($constraint->evaluate('barfoobar', '', true));
2361
$this->assertEquals('matches PCRE pattern "/foo/"', $constraint->toString());
2362
$this->assertEquals(1, count($constraint));
2365
$constraint->evaluate('barbazbar');
2368
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2369
$this->assertEquals(
2371
Failed asserting that 'barbazbar' matches PCRE pattern "/foo/".
2375
PHPUnit_Framework_TestFailure::exceptionToString($e)
2385
* @covers PHPUnit_Framework_Constraint_PCREMatch
2386
* @covers PHPUnit_Framework_Assert::matchesRegularExpression
2387
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2389
public function testConstraintPCREMatch2()
2391
$constraint = PHPUnit_Framework_Assert::matchesRegularExpression('/foo/');
2394
$constraint->evaluate('barbazbar', 'custom message');
2397
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2398
$this->assertEquals(<<<EOF
2400
Failed asserting that 'barbazbar' matches PCRE pattern "/foo/".
2404
PHPUnit_Framework_TestFailure::exceptionToString($e)
2414
* @covers PHPUnit_Framework_Constraint_PCREMatch
2415
* @covers PHPUnit_Framework_Constraint_Not
2416
* @covers PHPUnit_Framework_Assert::matchesRegularExpression
2417
* @covers PHPUnit_Framework_Assert::logicalNot
2418
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2420
public function testConstraintPCRENotMatch()
2422
$constraint = PHPUnit_Framework_Assert::logicalNot(
2423
PHPUnit_Framework_Assert::matchesRegularExpression('/foo/')
2426
$this->assertTrue($constraint->evaluate('barbazbar', '', true));
2427
$this->assertFalse($constraint->evaluate('barfoobar', '', true));
2428
$this->assertEquals('does not match PCRE pattern "/foo/"', $constraint->toString());
2429
$this->assertEquals(1, count($constraint));
2432
$constraint->evaluate('barfoobar');
2435
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2436
$this->assertEquals(
2438
Failed asserting that 'barfoobar' does not match PCRE pattern "/foo/".
2442
PHPUnit_Framework_TestFailure::exceptionToString($e)
2452
* @covers PHPUnit_Framework_Constraint_PCREMatch
2453
* @covers PHPUnit_Framework_Constraint_Not
2454
* @covers PHPUnit_Framework_Assert::matchesRegularExpression
2455
* @covers PHPUnit_Framework_Assert::logicalNot
2456
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2458
public function testConstraintPCRENotMatch2()
2460
$constraint = PHPUnit_Framework_Assert::logicalNot(
2461
PHPUnit_Framework_Assert::matchesRegularExpression('/foo/')
2465
$constraint->evaluate('barfoobar', 'custom message');
2468
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2469
$this->assertEquals(<<<EOF
2471
Failed asserting that 'barfoobar' does not match PCRE pattern "/foo/".
2475
PHPUnit_Framework_TestFailure::exceptionToString($e)
2485
* @covers PHPUnit_Framework_Constraint_StringMatches
2486
* @covers PHPUnit_Framework_Assert::matches
2487
* @covers PHPUnit_Framework_Constraint::count
2489
public function testConstraintStringMatches()
2491
$constraint = PHPUnit_Framework_Assert::matches('*%c*');
2492
$this->assertFalse($constraint->evaluate('**', '', true));
2493
$this->assertTrue($constraint->evaluate('***', '', true));
2494
$this->assertEquals('matches PCRE pattern "/^\*.\*$/s"', $constraint->toString());
2495
$this->assertEquals(1, count($constraint));
2499
* @covers PHPUnit_Framework_Constraint_StringMatches
2500
* @covers PHPUnit_Framework_Assert::matches
2501
* @covers PHPUnit_Framework_Constraint::count
2503
public function testConstraintStringMatches2()
2505
$constraint = PHPUnit_Framework_Assert::matches('*%s*');
2506
$this->assertFalse($constraint->evaluate('**', '', true));
2507
$this->assertTrue($constraint->evaluate('***', '', true));
2508
$this->assertEquals('matches PCRE pattern "/^\*[^\r\n]+\*$/s"', $constraint->toString());
2509
$this->assertEquals(1, count($constraint));
2513
* @covers PHPUnit_Framework_Constraint_StringMatches
2514
* @covers PHPUnit_Framework_Assert::matches
2515
* @covers PHPUnit_Framework_Constraint::count
2517
public function testConstraintStringMatches3()
2519
$constraint = PHPUnit_Framework_Assert::matches('*%i*');
2520
$this->assertFalse($constraint->evaluate('**', '', true));
2521
$this->assertTrue($constraint->evaluate('*0*', '', true));
2522
$this->assertEquals('matches PCRE pattern "/^\*[+-]?\d+\*$/s"', $constraint->toString());
2523
$this->assertEquals(1, count($constraint));
2527
* @covers PHPUnit_Framework_Constraint_StringMatches
2528
* @covers PHPUnit_Framework_Assert::matches
2529
* @covers PHPUnit_Framework_Constraint::count
2531
public function testConstraintStringMatches4()
2533
$constraint = PHPUnit_Framework_Assert::matches('*%d*');
2534
$this->assertFalse($constraint->evaluate('**', '', true));
2535
$this->assertTrue($constraint->evaluate('*0*', '', true));
2536
$this->assertEquals('matches PCRE pattern "/^\*\d+\*$/s"', $constraint->toString());
2537
$this->assertEquals(1, count($constraint));
2541
* @covers PHPUnit_Framework_Constraint_StringMatches
2542
* @covers PHPUnit_Framework_Assert::matches
2543
* @covers PHPUnit_Framework_Constraint::count
2545
public function testConstraintStringMatches5()
2547
$constraint = PHPUnit_Framework_Assert::matches('*%x*');
2548
$this->assertFalse($constraint->evaluate('**', '', true));
2549
$this->assertTrue($constraint->evaluate('*0f0f0f*', '', true));
2550
$this->assertEquals('matches PCRE pattern "/^\*[0-9a-fA-F]+\*$/s"', $constraint->toString());
2551
$this->assertEquals(1, count($constraint));
2555
* @covers PHPUnit_Framework_Constraint_StringMatches
2556
* @covers PHPUnit_Framework_Assert::matches
2557
* @covers PHPUnit_Framework_Constraint::count
2559
public function testConstraintStringMatches6()
2561
$constraint = PHPUnit_Framework_Assert::matches('*%f*');
2562
$this->assertFalse($constraint->evaluate('**', '', true));
2563
$this->assertTrue($constraint->evaluate('*1.0*', '', true));
2564
$this->assertEquals('matches PCRE pattern "/^\*[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?\*$/s"', $constraint->toString());
2565
$this->assertEquals(1, count($constraint));
2569
* @covers PHPUnit_Framework_Constraint_StringStartsWith
2570
* @covers PHPUnit_Framework_Assert::stringStartsWith
2571
* @covers PHPUnit_Framework_Constraint::count
2572
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2574
public function testConstraintStringStartsWith()
2576
$constraint = PHPUnit_Framework_Assert::stringStartsWith('prefix');
2578
$this->assertFalse($constraint->evaluate('foo', '', true));
2579
$this->assertTrue($constraint->evaluate('prefixfoo', '', true));
2580
$this->assertEquals('starts with "prefix"', $constraint->toString());
2581
$this->assertEquals(1, count($constraint));
2584
$constraint->evaluate('foo');
2587
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2588
$this->assertEquals(
2590
Failed asserting that 'foo' starts with "prefix".
2594
PHPUnit_Framework_TestFailure::exceptionToString($e)
2604
* @covers PHPUnit_Framework_Constraint_StringStartsWith
2605
* @covers PHPUnit_Framework_Assert::stringStartsWith
2606
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2608
public function testConstraintStringStartsWith2()
2610
$constraint = PHPUnit_Framework_Assert::stringStartsWith('prefix');
2613
$constraint->evaluate('foo', 'custom message');
2616
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2617
$this->assertEquals(
2619
custom message\nFailed asserting that 'foo' starts with "prefix".
2623
PHPUnit_Framework_TestFailure::exceptionToString($e)
2633
* @covers PHPUnit_Framework_Constraint_StringStartsWith
2634
* @covers PHPUnit_Framework_Constraint_Not
2635
* @covers PHPUnit_Framework_Assert::stringStartsWith
2636
* @covers PHPUnit_Framework_Assert::logicalNot
2637
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2639
public function testConstraintStringStartsNotWith()
2641
$constraint = PHPUnit_Framework_Assert::logicalNot(
2642
PHPUnit_Framework_Assert::stringStartsWith('prefix')
2645
$this->assertTrue($constraint->evaluate('foo', '', true));
2646
$this->assertFalse($constraint->evaluate('prefixfoo', '', true));
2647
$this->assertEquals('starts not with "prefix"', $constraint->toString());
2648
$this->assertEquals(1, count($constraint));
2651
$constraint->evaluate('prefixfoo');
2654
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2655
$this->assertEquals(
2657
Failed asserting that 'prefixfoo' starts not with "prefix".
2661
PHPUnit_Framework_TestFailure::exceptionToString($e)
2671
* @covers PHPUnit_Framework_Constraint_StringStartsWith
2672
* @covers PHPUnit_Framework_Assert::stringStartsWith
2673
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2675
public function testConstraintStringStartsNotWith2()
2677
$constraint = PHPUnit_Framework_Assert::logicalNot(
2678
PHPUnit_Framework_Assert::stringStartsWith('prefix')
2682
$constraint->evaluate('prefixfoo', 'custom message');
2685
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2686
$this->assertEquals(
2689
Failed asserting that 'prefixfoo' starts not with "prefix".
2693
PHPUnit_Framework_TestFailure::exceptionToString($e)
2703
* @covers PHPUnit_Framework_Constraint_StringContains
2704
* @covers PHPUnit_Framework_Assert::stringContains
2705
* @covers PHPUnit_Framework_Constraint::count
2706
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2708
public function testConstraintStringContains()
2710
$constraint = PHPUnit_Framework_Assert::stringContains('foo');
2712
$this->assertFalse($constraint->evaluate('barbazbar', '', true));
2713
$this->assertTrue($constraint->evaluate('barfoobar', '', true));
2714
$this->assertEquals('contains "foo"', $constraint->toString());
2715
$this->assertEquals(1, count($constraint));
2718
$constraint->evaluate('barbazbar');
2721
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2722
$this->assertEquals(
2724
Failed asserting that 'barbazbar' contains "foo".
2728
PHPUnit_Framework_TestFailure::exceptionToString($e)
2738
* @covers PHPUnit_Framework_Constraint_StringContains
2739
* @covers PHPUnit_Framework_Assert::stringContains
2740
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2742
public function testConstraintStringContains2()
2744
$constraint = PHPUnit_Framework_Assert::stringContains('foo');
2747
$constraint->evaluate('barbazbar', 'custom message');
2750
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2751
$this->assertEquals(
2754
Failed asserting that 'barbazbar' contains "foo".
2758
PHPUnit_Framework_TestFailure::exceptionToString($e)
2768
* @covers PHPUnit_Framework_Constraint_StringContains
2769
* @covers PHPUnit_Framework_Constraint_Not
2770
* @covers PHPUnit_Framework_Assert::stringContains
2771
* @covers PHPUnit_Framework_Assert::logicalNot
2772
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2774
public function testConstraintStringNotContains()
2776
$constraint = PHPUnit_Framework_Assert::logicalNot(
2777
PHPUnit_Framework_Assert::stringContains('foo')
2780
$this->assertTrue($constraint->evaluate('barbazbar', '', true));
2781
$this->assertFalse($constraint->evaluate('barfoobar', '', true));
2782
$this->assertEquals('does not contain "foo"', $constraint->toString());
2783
$this->assertEquals(1, count($constraint));
2786
$constraint->evaluate('barfoobar');
2789
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2790
$this->assertEquals(
2792
Failed asserting that 'barfoobar' does not contain "foo".
2796
PHPUnit_Framework_TestFailure::exceptionToString($e)
2806
* @covers PHPUnit_Framework_Constraint_StringContains
2807
* @covers PHPUnit_Framework_Constraint_Not
2808
* @covers PHPUnit_Framework_Assert::stringContains
2809
* @covers PHPUnit_Framework_Assert::logicalNot
2810
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2812
public function testConstraintStringNotContains2()
2814
$constraint = PHPUnit_Framework_Assert::logicalNot(
2815
PHPUnit_Framework_Assert::stringContains('foo')
2819
$constraint->evaluate('barfoobar', 'custom message');
2822
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2823
$this->assertEquals(
2826
Failed asserting that 'barfoobar' does not contain "foo".
2830
PHPUnit_Framework_TestFailure::exceptionToString($e)
2840
* @covers PHPUnit_Framework_Constraint_StringEndsWith
2841
* @covers PHPUnit_Framework_Assert::stringEndsWith
2842
* @covers PHPUnit_Framework_Constraint::count
2843
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2845
public function testConstraintStringEndsWith()
2847
$constraint = PHPUnit_Framework_Assert::stringEndsWith('suffix');
2849
$this->assertFalse($constraint->evaluate('foo', '', true));
2850
$this->assertTrue($constraint->evaluate('foosuffix', '', true));
2851
$this->assertEquals('ends with "suffix"', $constraint->toString());
2852
$this->assertEquals(1, count($constraint));
2855
$constraint->evaluate('foo');
2858
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2859
$this->assertEquals(
2861
Failed asserting that 'foo' ends with "suffix".
2865
PHPUnit_Framework_TestFailure::exceptionToString($e)
2875
* @covers PHPUnit_Framework_Constraint_StringEndsWith
2876
* @covers PHPUnit_Framework_Assert::stringEndsWith
2877
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2879
public function testConstraintStringEndsWith2()
2881
$constraint = PHPUnit_Framework_Assert::stringEndsWith('suffix');
2884
$constraint->evaluate('foo', 'custom message');
2887
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2888
$this->assertEquals(
2891
Failed asserting that 'foo' ends with "suffix".
2895
PHPUnit_Framework_TestFailure::exceptionToString($e)
2905
* @covers PHPUnit_Framework_Constraint_StringEndsWith
2906
* @covers PHPUnit_Framework_Constraint_Not
2907
* @covers PHPUnit_Framework_Assert::stringEndsWith
2908
* @covers PHPUnit_Framework_Assert::logicalNot
2909
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2911
public function testConstraintStringEndsNotWith()
2913
$constraint = PHPUnit_Framework_Assert::logicalNot(
2914
PHPUnit_Framework_Assert::stringEndsWith('suffix')
2917
$this->assertTrue($constraint->evaluate('foo', '', true));
2918
$this->assertFalse($constraint->evaluate('foosuffix', '', true));
2919
$this->assertEquals('ends not with "suffix"', $constraint->toString());
2920
$this->assertEquals(1, count($constraint));
2923
$constraint->evaluate('foosuffix');
2926
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2927
$this->assertEquals(
2929
Failed asserting that 'foosuffix' ends not with "suffix".
2933
PHPUnit_Framework_TestFailure::exceptionToString($e)
2943
* @covers PHPUnit_Framework_Constraint_StringEndsWith
2944
* @covers PHPUnit_Framework_Assert::stringEndsWith
2945
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2947
public function testConstraintStringEndsNotWith2()
2949
$constraint = PHPUnit_Framework_Assert::logicalNot(
2950
PHPUnit_Framework_Assert::stringEndsWith('suffix')
2954
$constraint->evaluate('foosuffix', 'custom message');
2957
catch (PHPUnit_Framework_ExpectationFailedException $e) {
2958
$this->assertEquals(
2961
Failed asserting that 'foosuffix' ends not with "suffix".
2965
PHPUnit_Framework_TestFailure::exceptionToString($e)
2975
* @covers PHPUnit_Framework_Constraint_TraversableContains
2977
public function testConstraintArrayContainsCheckForObjectIdentity()
2979
// Check for primitive type.
2980
$constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo', true, true);
2982
$this->assertFalse($constraint->evaluate(array(0), '', true));
2983
$this->assertFalse($constraint->evaluate(array(true), '', true));
2986
$constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
2988
$this->assertTrue($constraint->evaluate(array(0), '', true));
2989
$this->assertTrue($constraint->evaluate(array(true), '', true));
2993
* @covers PHPUnit_Framework_Constraint_TraversableContains
2994
* @covers PHPUnit_Framework_Constraint::count
2995
* @covers PHPUnit_Framework_TestFailure::exceptionToString
2997
public function testConstraintArrayContains()
2999
$constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
3001
$this->assertFalse($constraint->evaluate(array('bar'), '', true));
3002
$this->assertTrue($constraint->evaluate(array('foo'), '', true));
3003
$this->assertEquals("contains 'foo'", $constraint->toString());
3004
$this->assertEquals(1, count($constraint));
3007
$constraint->evaluate(array('bar'));
3010
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3011
$this->assertEquals(
3013
Failed asserting that an array contains 'foo'.
3017
PHPUnit_Framework_TestFailure::exceptionToString($e)
3027
* @covers PHPUnit_Framework_Constraint_TraversableContains
3028
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3030
public function testConstraintArrayContains2()
3032
$constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
3035
$constraint->evaluate(array('bar'), 'custom message');
3038
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3039
$this->assertEquals(
3042
Failed asserting that an array contains 'foo'.
3046
PHPUnit_Framework_TestFailure::exceptionToString($e)
3056
* @covers PHPUnit_Framework_Constraint_TraversableContains
3057
* @covers PHPUnit_Framework_Constraint_Not
3058
* @covers PHPUnit_Framework_Assert::logicalNot
3059
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3061
public function testConstraintArrayNotContains()
3063
$constraint = PHPUnit_Framework_Assert::logicalNot(
3064
new PHPUnit_Framework_Constraint_TraversableContains('foo')
3067
$this->assertTrue($constraint->evaluate(array('bar'), '', true));
3068
$this->assertFalse($constraint->evaluate(array('foo'), '', true));
3069
$this->assertEquals("does not contain 'foo'", $constraint->toString());
3070
$this->assertEquals(1, count($constraint));
3073
$constraint->evaluate(array('foo'));
3076
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3077
$this->assertEquals(
3079
Failed asserting that an array does not contain 'foo'.
3083
PHPUnit_Framework_TestFailure::exceptionToString($e)
3093
* @covers PHPUnit_Framework_Constraint_TraversableContains
3094
* @covers PHPUnit_Framework_Constraint_Not
3095
* @covers PHPUnit_Framework_Assert::logicalNot
3096
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3098
public function testConstraintArrayNotContains2()
3100
$constraint = PHPUnit_Framework_Assert::logicalNot(
3101
new PHPUnit_Framework_Constraint_TraversableContains('foo')
3105
$constraint->evaluate(array('foo'), 'custom message');
3108
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3109
$this->assertEquals(
3112
Failed asserting that an array does not contain 'foo'.
3116
PHPUnit_Framework_TestFailure::exceptionToString($e)
3126
* @covers PHPUnit_Framework_Constraint_TraversableContains
3127
* @covers PHPUnit_Framework_Constraint::count
3128
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3130
public function testConstraintSplObjectStorageContains()
3132
$object = new StdClass;
3133
$constraint = new PHPUnit_Framework_Constraint_TraversableContains($object);
3134
$this->assertStringMatchesFormat("contains stdClass Object &%s ()", $constraint->toString());
3136
$storage = new SplObjectStorage;
3137
$this->assertFalse($constraint->evaluate($storage, '', true));
3139
$storage->attach($object);
3140
$this->assertTrue($constraint->evaluate($storage, '', true));
3143
$constraint->evaluate(new SplObjectStorage);
3146
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3147
$this->assertStringMatchesFormat(
3149
Failed asserting that a traversable contains stdClass Object &%x ().
3153
PHPUnit_Framework_TestFailure::exceptionToString($e)
3163
* @covers PHPUnit_Framework_Constraint_TraversableContains
3164
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3166
public function testConstraintSplObjectStorageContains2()
3168
$object = new StdClass;
3169
$constraint = new PHPUnit_Framework_Constraint_TraversableContains($object);
3172
$constraint->evaluate(new SplObjectStorage, 'custom message');
3175
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3176
$this->assertStringMatchesFormat(
3179
Failed asserting that a traversable contains stdClass Object &%x ().
3183
PHPUnit_Framework_TestFailure::exceptionToString($e)
3193
* @covers PHPUnit_Framework_Assert::attributeEqualTo
3194
* @covers PHPUnit_Framework_Constraint_Attribute
3195
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3197
public function testAttributeEqualTo()
3199
$object = new ClassWithNonPublicAttributes;
3200
$constraint = PHPUnit_Framework_Assert::attributeEqualTo('foo', 1);
3202
$this->assertTrue($constraint->evaluate($object, '', true));
3203
$this->assertEquals('attribute "foo" is equal to 1', $constraint->toString());
3204
$this->assertEquals(1, count($constraint));
3206
$constraint = PHPUnit_Framework_Assert::attributeEqualTo('foo', 2);
3208
$this->assertFalse($constraint->evaluate($object, '', true));
3211
$constraint->evaluate($object);
3214
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3215
$this->assertEquals(
3217
Failed asserting that attribute "foo" is equal to 2.
3221
PHPUnit_Framework_TestFailure::exceptionToString($e)
3231
* @covers PHPUnit_Framework_Assert::attributeEqualTo
3232
* @covers PHPUnit_Framework_Constraint_Attribute
3233
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3235
public function testAttributeEqualTo2()
3237
$object = new ClassWithNonPublicAttributes;
3238
$constraint = PHPUnit_Framework_Assert::attributeEqualTo('foo', 2);
3241
$constraint->evaluate($object, 'custom message');
3244
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3245
$this->assertEquals(
3247
custom message\nFailed asserting that attribute "foo" is equal to 2.
3251
PHPUnit_Framework_TestFailure::exceptionToString($e)
3261
* @covers PHPUnit_Framework_Assert::attributeEqualTo
3262
* @covers PHPUnit_Framework_Assert::logicalNot
3263
* @covers PHPUnit_Framework_Constraint_Attribute
3264
* @covers PHPUnit_Framework_Constraint_Not
3265
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3267
public function testAttributeNotEqualTo()
3269
$object = new ClassWithNonPublicAttributes;
3270
$constraint = PHPUnit_Framework_Assert::logicalNot(
3271
PHPUnit_Framework_Assert::attributeEqualTo('foo', 2)
3274
$this->assertTrue($constraint->evaluate($object, '', true));
3275
$this->assertEquals('attribute "foo" is not equal to 2', $constraint->toString());
3276
$this->assertEquals(1, count($constraint));
3278
$constraint = PHPUnit_Framework_Assert::logicalNot(
3279
PHPUnit_Framework_Assert::attributeEqualTo('foo', 1)
3282
$this->assertFalse($constraint->evaluate($object, '', true));
3285
$constraint->evaluate($object);
3288
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3289
$this->assertEquals(
3291
Failed asserting that attribute "foo" is not equal to 1.
3295
PHPUnit_Framework_TestFailure::exceptionToString($e)
3305
* @covers PHPUnit_Framework_Assert::attributeEqualTo
3306
* @covers PHPUnit_Framework_Assert::logicalNot
3307
* @covers PHPUnit_Framework_Constraint_Attribute
3308
* @covers PHPUnit_Framework_Constraint_Not
3309
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3311
public function testAttributeNotEqualTo2()
3313
$object = new ClassWithNonPublicAttributes;
3314
$constraint = PHPUnit_Framework_Assert::logicalNot(
3315
PHPUnit_Framework_Assert::attributeEqualTo('foo', 1)
3319
$constraint->evaluate($object, 'custom message');
3322
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3323
$this->assertEquals(
3325
custom message\nFailed asserting that attribute "foo" is not equal to 1.
3329
PHPUnit_Framework_TestFailure::exceptionToString($e)
3339
* @covers PHPUnit_Framework_Constraint_IsEmpty
3340
* @covers PHPUnit_Framework_Constraint::count
3341
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3343
public function testConstraintIsEmpty()
3345
$constraint = new PHPUnit_Framework_Constraint_IsEmpty;
3347
$this->assertFalse($constraint->evaluate(array('foo'), '', true));
3348
$this->assertTrue($constraint->evaluate(array(), '', true));
3349
$this->assertFalse($constraint->evaluate(new ArrayObject(array('foo')), '', true));
3350
$this->assertTrue($constraint->evaluate(new ArrayObject(array()), '', true));
3351
$this->assertEquals('is empty', $constraint->toString());
3352
$this->assertEquals(1, count($constraint));
3355
$constraint->evaluate(array('foo'));
3358
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3359
$this->assertEquals(
3361
Failed asserting that an array is empty.
3365
PHPUnit_Framework_TestFailure::exceptionToString($e)
3375
* @covers PHPUnit_Framework_Constraint_IsEmpty
3376
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3378
public function testConstraintIsEmpty2()
3380
$constraint = new PHPUnit_Framework_Constraint_IsEmpty;
3383
$constraint->evaluate(array('foo'), 'custom message');
3386
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3387
$this->assertEquals(
3389
custom message\nFailed asserting that an array is empty.
3393
PHPUnit_Framework_TestFailure::exceptionToString($e)
3403
* @covers PHPUnit_Framework_Constraint_Count
3405
public function testConstraintCountWithAnArray()
3407
$constraint = new PHPUnit_Framework_Constraint_Count(5);
3409
$this->assertTrue($constraint->evaluate(array(1,2,3,4,5), '', true));
3410
$this->assertFalse($constraint->evaluate(array(1,2,3,4), '', true));
3414
* @covers PHPUnit_Framework_Constraint_Count
3416
public function testConstraintCountWithAnIteratorWhichDoesNotImplementCountable()
3418
$constraint = new PHPUnit_Framework_Constraint_Count(5);
3420
$this->assertTrue($constraint->evaluate(new TestIterator(array(1,2,3,4,5)), '', true));
3421
$this->assertFalse($constraint->evaluate(new TestIterator(array(1,2,3,4)), '', true));
3425
* @covers PHPUnit_Framework_Constraint_Count
3427
public function testConstraintCountWithAnObjectImplementingCountable()
3429
$constraint = new PHPUnit_Framework_Constraint_Count(5);
3431
$this->assertTrue($constraint->evaluate(new ArrayObject(array(1,2,3,4,5)), '', true));
3432
$this->assertFalse($constraint->evaluate(new ArrayObject(array(1,2,3,4)), '', true));
3436
* @covers PHPUnit_Framework_Constraint_Count
3437
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3439
public function testConstraintCountFailing()
3441
$constraint = new PHPUnit_Framework_Constraint_Count(5);
3444
$constraint->evaluate(array(1,2));
3447
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3448
$this->assertEquals(
3450
Failed asserting that actual size 2 matches expected size 5.
3454
PHPUnit_Framework_TestFailure::exceptionToString($e)
3464
* @covers PHPUnit_Framework_Constraint_Count
3465
* @covers PHPUnit_Framework_Constraint_Not
3466
* @covers PHPUnit_Framework_Assert::logicalNot
3467
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3469
public function testConstraintNotCountFailing()
3471
$constraint = PHPUnit_Framework_Assert::logicalNot(
3472
new PHPUnit_Framework_Constraint_Count(2)
3476
$constraint->evaluate(array(1,2));
3479
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3480
$this->assertEquals(
3482
Failed asserting that actual size 2 does not match expected size 2.
3486
PHPUnit_Framework_TestFailure::exceptionToString($e)
3496
* @covers PHPUnit_Framework_Constraint_SameSize
3498
public function testConstraintSameSizeWithAnArray()
3500
$constraint = new PHPUnit_Framework_Constraint_SameSize(array(1,2,3,4,5));
3502
$this->assertTrue($constraint->evaluate(array(6,7,8,9,10), '', true));
3503
$this->assertFalse($constraint->evaluate(array(1,2,3,4), '', true));
3507
* @covers PHPUnit_Framework_Constraint_SameSize
3509
public function testConstraintSameSizeWithAnIteratorWhichDoesNotImplementCountable()
3511
$constraint = new PHPUnit_Framework_Constraint_SameSize(new TestIterator(array(1,2,3,4,5)));
3513
$this->assertTrue($constraint->evaluate(new TestIterator(array(6,7,8,9,10)), '', true));
3514
$this->assertFalse($constraint->evaluate(new TestIterator(array(1,2,3,4)), '', true));
3518
* @covers PHPUnit_Framework_Constraint_SameSize
3520
public function testConstraintSameSizeWithAnObjectImplementingCountable()
3522
$constraint = new PHPUnit_Framework_Constraint_SameSize(new ArrayObject(array(1,2,3,4,5)));
3524
$this->assertTrue($constraint->evaluate(new ArrayObject(array(6,7,8,9,10)), '', true));
3525
$this->assertFalse($constraint->evaluate(new ArrayObject(array(1,2,3,4)), '', true));
3529
* @covers PHPUnit_Framework_Constraint_SameSize
3530
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3532
public function testConstraintSameSizeFailing()
3534
$constraint = new PHPUnit_Framework_Constraint_SameSize(array(1,2,3,4,5));
3537
$constraint->evaluate(array(1,2));
3540
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3541
$this->assertEquals(
3543
Failed asserting that actual size 2 matches expected size 5.
3547
PHPUnit_Framework_TestFailure::exceptionToString($e)
3557
* @covers PHPUnit_Framework_Constraint_SameSize
3558
* @covers PHPUnit_Framework_Constraint_Not
3559
* @covers PHPUnit_Framework_Assert::logicalNot
3560
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3562
public function testConstraintNotSameSizeFailing()
3564
$constraint = PHPUnit_Framework_Assert::logicalNot(
3565
new PHPUnit_Framework_Constraint_SameSize(array(1,2))
3569
$constraint->evaluate(array(3,4));
3572
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3573
$this->assertEquals(
3575
Failed asserting that actual size 2 does not match expected size 2.
3579
PHPUnit_Framework_TestFailure::exceptionToString($e)
3589
* @covers PHPUnit_Framework_Constraint_Exception
3590
* @covers PHPUnit_Framework_TestFailure::exceptionToString
3592
public function testConstraintException()
3594
$constraint = new PHPUnit_Framework_Constraint_Exception('FoobarException');
3595
$exception = new DummyException('Test');
3596
$stackTrace = $exception->getTraceAsString();
3599
$constraint->evaluate($exception);
3602
catch (PHPUnit_Framework_ExpectationFailedException $e) {
3603
$this->assertEquals(
3605
Failed asserting that exception of type "DummyException" matches expected exception "FoobarException". Message was: "Test" at
3610
PHPUnit_Framework_TestFailure::exceptionToString($e)
3620
* Removes spaces in front of newlines
3622
* @param string $string
3625
private function trimnl($string)
3627
return preg_replace('/[ ]*\n/', "\n", $string);