Skip to content

Commit

Permalink
Eliminate code duplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 10, 2006
1 parent f20dd09 commit c5aed5a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
39 changes: 22 additions & 17 deletions PHPUnit/Framework/Constraint.php
Expand Up @@ -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
);
}
}

}
Expand Down
16 changes: 1 addition & 15 deletions PHPUnit/Framework/Constraint/Not.php
Expand Up @@ -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()
);
}
Expand Down

0 comments on commit c5aed5a

Please sign in to comment.