Skip to content

Commit

Permalink
- Merge [2398].
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 10, 2008
1 parent 76483c5 commit 2d866f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
7 changes: 7 additions & 0 deletions PHPUnit/Framework/ExpectationFailedException.php
Expand Up @@ -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;
Expand All @@ -93,6 +95,11 @@ public function getDescription()
{
return $this->description;
}

public function getCustomMessage()
{
return $this->customMessage;
}
}

}
Expand Down
25 changes: 16 additions & 9 deletions PHPUnit/Framework/TestFailure.php
Expand Up @@ -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()),
Expand All @@ -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)),
Expand All @@ -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";
}
}
}
Expand Down

0 comments on commit 2d866f0

Please sign in to comment.