diff --git a/PHPUnit/Framework/ExpectationFailedException.php b/PHPUnit/Framework/ExpectationFailedException.php index 2173c477655..de275ad08bd 100644 --- a/PHPUnit/Framework/ExpectationFailedException.php +++ b/PHPUnit/Framework/ExpectationFailedException.php @@ -71,11 +71,13 @@ class PHPUnit_Framework_ExpectationFailedException extends PHPUnit_Framework_Ass { protected $comparisonFailure; protected $description; + protected $customMessage; public function __construct($description, PHPUnit_Framework_ComparisonFailure $comparisonFailure = NULL, $message = '') { $this->description = $description; $this->comparisonFailure = $comparisonFailure; + $this->customMessage = $message; if (!empty($message)) { $description .= "\n" . $message; @@ -93,6 +95,11 @@ public function getDescription() { return $this->description; } + + public function getCustomMessage() + { + return $this->customMessage; + } } } diff --git a/PHPUnit/Framework/TestFailure.php b/PHPUnit/Framework/TestFailure.php index 3d2297d2b2e..696b45fbb63 100644 --- a/PHPUnit/Framework/TestFailure.php +++ b/PHPUnit/Framework/TestFailure.php @@ -134,17 +134,25 @@ public static function exceptionToString(Exception $e, $verbose = FALSE) if ($e instanceof PHPUnit_Framework_SelfDescribing) { if ($e instanceof PHPUnit_Framework_ExpectationFailedException) { $comparisonFailure = $e->getComparisonFailure(); + $description = $e->getDescription(); + $message = $e->getCustomMessage(); + + if ($message == '') { + $buffer = ''; + } else { + $buffer = $message . "\n"; + } if ($comparisonFailure !== NULL) { if ($comparisonFailure->identical()) { if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object) { - $buffer = "Failed asserting that two variables reference the same object.\n"; + $buffer .= "Failed asserting that two variables reference the same object.\n"; } else { - $buffer = $comparisonFailure->toString() . "\n"; + $buffer .= $comparisonFailure->toString() . "\n"; } } else { if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Scalar) { - $buffer = sprintf( + $buffer .= sprintf( "Failed asserting that %s matches expected value %s.\n", PHPUnit_Util_Type::toString($comparisonFailure->getActual()), @@ -155,7 +163,7 @@ public static function exceptionToString(Exception $e, $verbose = FALSE) else if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Array || $comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object || $comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_String) { - $buffer = sprintf( + $buffer .= sprintf( "Failed asserting that two %ss are equal.\n%s\n", strtolower(substr(get_class($comparisonFailure), 36)), @@ -167,20 +175,19 @@ public static function exceptionToString(Exception $e, $verbose = FALSE) !$comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Array && !$comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object && !$comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_String) { - $buffer = $comparisonFailure->toString() . "\n"; + $buffer .= $comparisonFailure->toString() . "\n"; } } } else { - $buffer = $e->toString(); - $description = $e->getDescription(); - $equal = $buffer == $description; + $buffer .= $e->toString(); + $equal = $buffer == $description; if (!empty($buffer)) { $buffer .= "\n"; } if (!$equal) { - $buffer .= $e->getDescription() . "\n"; + $buffer .= $description . "\n"; } } }