diff --git a/PHPUnit/Framework/Constraint.php b/PHPUnit/Framework/Constraint.php index 99f0252b715..0c59c1b1a01 100644 --- a/PHPUnit/Framework/Constraint.php +++ b/PHPUnit/Framework/Constraint.php @@ -90,14 +90,16 @@ abstract public function evaluate($other); */ public function fail($other, $description, $not = FALSE) { - if (!empty($description)) { - $description .= "\n"; - } + throw new PHPUnit_Framework_ExpectationFailedException( + $this->failureDescription($other, $description, $not) + ); + } + protected function failureDescription($other, $description, $not) + { $failureDescription = sprintf( - '%sFailed asserting that %s %s.', + 'Failed asserting that %s %s.', - $description, PHPUnit_Util_Type::toString($other), $this->toString() ); @@ -106,9 +108,11 @@ public function fail($other, $description, $not = FALSE) $failureDescription = self::negate($failureDescription); } - throw new PHPUnit_Framework_ExpectationFailedException( - $failureDescription - ); + if (!empty($description)) { + $failureDescription = $description . "\n" . $failureDescription; + } + + return $failureDescription; } public static function negate($string) @@ -122,11 +126,11 @@ public static function negate($string) 'matches ' ), array( - 'not contains ', - 'not exists ', - 'has not ', + 'does not contain ', + 'does not exist ', + 'does not have ', 'is not ', - 'not matches ' + 'does not match ' ), $string ); diff --git a/PHPUnit/Framework/Constraint/FileExists.php b/PHPUnit/Framework/Constraint/FileExists.php index 2e3bc88ebaf..67a78ed5483 100644 --- a/PHPUnit/Framework/Constraint/FileExists.php +++ b/PHPUnit/Framework/Constraint/FileExists.php @@ -89,17 +89,22 @@ public function evaluate($other) */ public function fail($other, $description, $not = FALSE) { + $failureDescription = sprintf( + 'Failed asserting that file "%s" exists.', + + $other + ); + + if ($not) { + $failureDescription = self::negate($failureDescription); + } + if (!empty($description)) { - $description .= "\n"; + $failureDescription = $description . "\n" . $failureDescription; } throw new PHPUnit_Framework_ExpectationFailedException( - sprintf( - '%sFailed asserting that file "%s" exists.', - - $description, - $other - ) + $failureDescription ); } diff --git a/PHPUnit/Framework/Constraint/IsEqual.php b/PHPUnit/Framework/Constraint/IsEqual.php index e0763f82831..bbe530a051b 100644 --- a/PHPUnit/Framework/Constraint/IsEqual.php +++ b/PHPUnit/Framework/Constraint/IsEqual.php @@ -106,16 +106,10 @@ public function evaluate($other) */ public function fail($other, $description, $not = FALSE) { - if (!empty($description)) { - $description .= "\n"; - } - - $failureDescription = sprintf( - '%sFailed asserting that %s %s.', - - $description, - PHPUnit_Util_Type::toString($other), - $this->toString() + $failureDescription = $this->failureDescription( + $other, + $description, + $not ); if (!$not) { @@ -124,8 +118,6 @@ public function fail($other, $description, $not = FALSE) PHPUnit_Framework_ComparisonFailure::diffEqual($this->value, $other) ); } else { - $failureDescription = self::negate($failureDescription); - throw new PHPUnit_Framework_ExpectationFailedException( $failureDescription ); diff --git a/PHPUnit/Framework/Constraint/IsIdentical.php b/PHPUnit/Framework/Constraint/IsIdentical.php index 916b831ed1b..9a11dc485cd 100644 --- a/PHPUnit/Framework/Constraint/IsIdentical.php +++ b/PHPUnit/Framework/Constraint/IsIdentical.php @@ -101,16 +101,10 @@ public function evaluate($other) */ public function fail($other, $description, $not = FALSE) { - if (!empty($description)) { - $description .= "\n"; - } - - $failureDescription = sprintf( - '%sFailed asserting that %s %s.', - - $description, - PHPUnit_Util_Type::toString($other), - $this->toString() + $failureDescription = $this->failureDescription( + $other, + $description, + $not ); if (!$not) { @@ -120,7 +114,7 @@ public function fail($other, $description, $not = FALSE) ); } else { throw new PHPUnit_Framework_ExpectationFailedException( - $failureDescription + self::negate($failureDescription) ); } }