Permalink
Browse files

Eliminate code duplication.

  • Loading branch information...
1 parent f20dd09 commit c5aed5af1961609bb2bd6e1896803bda3d858a8d @sebastianbergmann committed Nov 10, 2006
Showing with 23 additions and 32 deletions.
  1. +22 −17 PHPUnit/Framework/Constraint.php
  2. +1 −15 PHPUnit/Framework/Constraint/Not.php
@@ -103,29 +103,34 @@ public function fail($other, $description, $not = FALSE)
);
if ($not) {
- $failureDescription = str_replace(
- array(
- 'contains ',
- 'exists ',
- 'has ',
- 'is ',
- 'matches '
- ),
- array(
- 'not contains ',
- 'not exists ',
- 'has not ',
- 'is not ',
- 'not matches '
- ),
- $failureDescription
- );
+ $failureDescription = self::negate($failureDescription);
}
throw new PHPUnit_Framework_ExpectationFailedException(
$failureDescription
);
}
+
+ public static function negate($string)
+ {
+ return str_replace(
+ array(
+ 'contains ',
+ 'exists ',
+ 'has ',
+ 'is ',
+ 'matches '
+ ),
+ array(
+ 'not contains ',
+ 'not exists ',
+ 'has not ',
+ 'is not ',
+ 'not matches '
+ ),
+ $string
+ );
+ }
}
}
@@ -124,21 +124,7 @@ public function toString()
break;
default: {
- return str_replace(
- array(
- 'contains ',
- 'exists ',
- 'has ',
- 'is ',
- 'matches '
- ),
- array(
- 'not contains ',
- 'not exists ',
- 'has not ',
- 'is not ',
- 'not matches '
- ),
+ return PHPUnit_Framework_Constraint::negate(
$this->constraint->toString()
);
}

0 comments on commit c5aed5a

Please sign in to comment.