/** * @dataProvider isEqualProvider * @covers CIUnit_Framework_Constraint_IsEqual * @covers CIUnit_Framework_Exception_ExpectationFailed::toString */ public function testConstraintIsEqualWithDataProviderAndCustomMessage($expected, $actual, $message) { $constraint = new CIUnit_Framework_Constraint_IsEqual($expected); try { $constraint->evaluate($actual, ''); } catch (CIUnit_Framework_Exception_ExpectationFailed $e) { $this->assertEquals($message, $e->__toString()); return; } $this->fail(); }
/** * @covers CIUnit_Framework_Constraint_IsEqual * @covers CIUnit_Framework_Exception_ExpectationFailed::toString */ public function testConstraintEqualsForComplexObjectsWithCustomMessage() { $objC = new stdClass(); $objC->foo = 'bar'; $objC->int = 1; $objC->array = array(0, array(1), array(2), 3); $objC->related = new stdClass(); $objC->self = $objC; $objC->c = $objC; $objD = new stdClass(); $objD->foo = 'bar'; $objD->int = 2; $objD->array = array(0, array(4), array(2), 3); $objD->related = new stdClass(); $objD->self = $objD; $objD->c = $objC; $expected = $objC; $actual = $objD; $message = <<<EOF Failed asserting that two objects are equal. - Expected + Actual stdClass Object ( 'foo' => 'bar' - 'int' => 1 + 'int' => 2 'array' => Array ( 0 => 0 1 => Array ( - 0 => 1 + 0 => 4 ) 2 => Array ( 0 => 2 ) 3 => 3 ) 'related' => stdClass Object () 'self' => stdClass Object ( 'foo' => 'bar' - 'int' => 1 + 'int' => 2 'array' => Array ( 0 => 0 1 => Array ( - 0 => 1 + 0 => 4 ) 2 => Array ( 0 => 2 ) 3 => 3 ) 'related' => stdClass Object () 'self' => stdClass Object (*RECURSION*) - 'c' => stdClass Object (*RECURSION*) + 'c' => stdClass Object ( + 'foo' => 'bar' + 'int' => 1 + 'array' => Array ( + 0 => 0 + 1 => Array ( + 0 => 1 + ) + 2 => Array ( + 0 => 2 + ) + 3 => 3 + ) + 'related' => stdClass Object () + 'self' => stdClass Object (*RECURSION*) + 'c' => stdClass Object (*RECURSION*) + ) ) 'c' => stdClass Object ( 'foo' => 'bar' 'int' => 1 'array' => Array ( 0 => 0 1 => Array ( 0 => 1 ) 2 => Array ( 0 => 2 ) 3 => 3 ) 'related' => stdClass Object () 'self' => stdClass Object (*RECURSION*) 'c' => stdClass Object (*RECURSION*) ) ) EOF; $constraint = new CIUnit_Framework_Constraint_IsEqual($expected); try { $constraint->evaluate($actual, ''); } catch (CIUnit_Framework_Exception_ExpectationFailed $e) { $this->assertEquals($message, $e->__toString()); return; } $this->fail(); }