Identical check is performed with PHP's === operator, the operator is explained in detail at {@url http://www.php.net/manual/en/types.comparisons.php}. Two values are identical if they have the same value and are of the same type. The expected value is passed in the constructor.
Inheritance: extends PHPUnit_Framework_Constraint
 /**
  * Asserts that one array is identical to another, but the order of keys does not matter.
  *
  * @param $expected
  * @param $actual
  */
 public static function assertSimilar($expected, $actual)
 {
     if (!is_array($expected) || !is_array($actual)) {
         throw new \PHPUnit_Framework_AssertionFailedError('Only arrays can be compared');
     }
     ksort($expected);
     ksort($actual);
     $constraint = new \PHPUnit_Framework_Constraint_IsIdentical($expected);
     $constraint->evaluate($actual);
 }
Example #2
0
 public function testConstraintIsIdentical2()
 {
     $a = new stdClass();
     $b = new stdClass();
     $constraint = new PHPUnit_Framework_Constraint_IsIdentical($a);
     try {
         $constraint->fail($b, 'custom message');
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("custom message\nFailed asserting that \nstdClass Object\n(\n)\n is identical to \nstdClass Object\n(\n)\n.", $e->getDescription());
         return;
     }
     $this->fail();
 }
Example #3
0
 public function testFailureIsIdentical2()
 {
     $a = new stdClass();
     $b = new stdClass();
     $constraint = new PHPUnit_Framework_Constraint_IsIdentical($a);
     try {
         $constraint->fail($b, 'custom message');
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("custom message\nFailed asserting that two variables reference the same object.\n", PHPUnit_Framework_TestFailure::exceptionToString($e));
         return;
     }
     $this->fail();
 }
Example #4
0
 public function testConstraintIsIdentical()
 {
     $a = new stdClass();
     $b = new stdClass();
     $constraint = new PHPUnit_Framework_Constraint_IsIdentical($a);
     $this->assertFalse($constraint->evaluate($b));
     $this->assertTrue($constraint->evaluate($a));
     $this->assertEquals("is identical to \nstdClass Object\n(\n)\n", $constraint->toString());
     try {
         $constraint->fail($b, '');
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("Failed asserting that \nstdClass Object\n(\n)\n is identical to \nstdClass Object\n(\n)\n.", $e->getDescription());
         return;
     }
     $this->fail();
 }