Permalink
Browse files

- Merge [1062].

  • Loading branch information...
1 parent 7522552 commit 551f02eb9f470d2e7062ca20725dfe625b2069b6 @sebastianbergmann committed Sep 2, 2007
@@ -89,6 +89,31 @@ public function evaluate($other)
}
/**
+ * Creates the appropriate exception for the constraint which can be caught
+ * by the unit test system. This can be called if a call to evaluate() fails.
+ *
+ * @param mixed $other The value passed to evaluate() which failed the
+ * constraint check.
+ * @param string $description A string with extra description of what was
+ * going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
+ * @throws PHPUnit_Framework_ExpectationFailedException
+ */
+ public function fail($other, $description, $not = FALSE)
+ {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ sprintf(
+ 'Failed asserting that %s is %san instance of class "%s".',
+
+ PHPUnit_Util_Type::toString($other, TRUE),
+ $not ? 'not ' : '',
+ $this->className
+ ),
+ NULL
+ );
+ }
+
+ /**
* Returns a string representation of the constraint.
*
* @return string
@@ -347,7 +347,7 @@ public function testConstraintIsInstanceOf()
catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertEquals(
- "Failed asserting that \nstdClass Object\n(\n)\n is instance of class \"Exception\".",
+ 'Failed asserting that <stdClass> is an instance of class "Exception".',
$e->getDescription()
);
@@ -373,7 +373,7 @@ public function testConstraintIsNotInstanceOf()
catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertEquals(
- "Failed asserting that \nstdClass Object\n(\n)\n is not instance of class \"stdClass\".",
+ 'Failed asserting that <stdClass> is not an instance of class "stdClass".',
$e->getDescription()
);
View
@@ -136,10 +136,18 @@ public static function shortenedString($string)
}
}
- public static function toString($value)
+ public static function toString($value, $short = FALSE)
{
if (is_array($value) || is_object($value)) {
- return "\n" . print_r($value, TRUE);
+ if (!$short) {
+ return "\n" . print_r($value, TRUE);
+ } else {
+ if (is_array($value)) {
+ return '<array>';
+ } else {
+ return '<' . get_class($value) . '>';
+ }
+ }
}
if (is_string($value) && strpos($value, "\n") !== FALSE) {

0 comments on commit 551f02e

Please sign in to comment.