Skip to content
Browse files

Cleanup PHPUnit_Framework_Constraint*.

  • Loading branch information...
1 parent ae92d1f commit 30d7511328cbea28632b3f065142d5176d4d46b8 @sebastianbergmann committed Nov 9, 2006
View
19 PHPUnit/Framework/Assert.php
@@ -692,16 +692,7 @@ public static function assertRegExp($pattern, $string, $message = '')
$constraint = new PHPUnit_Framework_Constraint_PCREMatch($pattern);
if (!$constraint->evaluate($string)) {
- $constraint->fail(
- $string,
- sprintf(
- '%sfailed asserting that string <%s> %s',
-
- $message,
- print_r($string, TRUE),
- $constraint->toString()
- )
- );
+ self::failConstraint($constraint, $string, $message);
}
}
@@ -1007,12 +998,16 @@ public static function fail($message = '')
*/
public static function failConstraint(PHPUnit_Framework_Constraint $constraint, $value, $message)
{
+ if (!empty($message)) {
+ $message .= "\n";
+ }
+
$constraint->fail(
$value,
sprintf(
- '%sfailed asserting that %s %s',
+ '%sFailed asserting that %s %s.',
- !empty($message) ? $message . ' ' : '',
+ $message,
PHPUnit_Util_Type::toString($value),
$constraint->toString()
)
View
3 PHPUnit/Framework/Constraint.php
@@ -92,9 +92,10 @@ public function evaluate($other);
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description);
+ public function fail($other, $description, $not = FALSE);
}
}
View
27 PHPUnit/Framework/Constraint/And.php
@@ -47,6 +47,7 @@
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/Type.php';
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
@@ -112,25 +113,31 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
+ if (!empty($description)) {
+ $description .= "\n";
+ }
+
+ $description = sprintf(
+ "%sExpected that %s %s",
+
+ $description,
+ PHPUnit_Util_Type::toString($other),
+ $this->toString()
+ );
+
if ($this->failedConstraint !== NULL) {
$this->failedConstraint->fail(
$other,
- $description . "\n" .
- 'Expected that <' . $other . '> ' . $this->toString()
+ $description
);
} else {
throw new PHPUnit_Framework_ExpectationFailedException(
- sprintf(
- "%s\nExpected that <%s> %s",
-
- $description,
- print_r($other, 1),
- $this->toString()
- )
+ $description
);
}
}
View
20 PHPUnit/Framework/Constraint/ArrayHasKey.php
@@ -47,6 +47,7 @@
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/Type.php';
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
@@ -94,18 +95,22 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
+ if (!empty($description)) {
+ $description .= "\n";
+ }
+
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
- "%s\nexpected array key <%s:%s> not found in array <%s>",
+ '%sExpected array key %s not found in %s.',
$description,
- gettype($this->key),
- print_r($this->key, TRUE),
- print_r($other, TRUE)
+ PHPUnit_Util_Type::toString($this->key),
+ PHPUnit_Util_Type::toString($other)
)
);
}
@@ -119,10 +124,9 @@ public function fail($other, $description)
public function toString()
{
return sprintf(
- 'has key <%s:%s>',
+ 'array has key %s',
- gettype($this->key),
- print_r($this->key, TRUE)
+ PHPUnit_Util_Type::toString($this->key)
);
}
}
View
9 PHPUnit/Framework/Constraint/FileExists.php
@@ -84,13 +84,18 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
+ if (!empty($description)) {
+ $description .= "\n";
+ }
+
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
- "%s\nfile <%s> does not exist",
+ '%sFile "%s" does not exist.',
$description,
$other
View
17 PHPUnit/Framework/Constraint/GreaterThan.php
@@ -91,14 +91,21 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
- throw new PHPUnit_Framework_ExpectationFailedException(
- $description,
- PHPUnit_Framework_ComparisonFailure::diffIdentical($this->value, $other)
- );
+ if (!$not) {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ $description,
+ PHPUnit_Framework_ComparisonFailure::diffIdentical($this->value, $other)
+ );
+ } else {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ $description
+ );
+ }
}
/**
View
3 PHPUnit/Framework/Constraint/IsAnything.php
@@ -82,8 +82,9 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
}
View
17 PHPUnit/Framework/Constraint/IsEqual.php
@@ -101,14 +101,21 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
- throw new PHPUnit_Framework_ExpectationFailedException(
- $description,
- PHPUnit_Framework_ComparisonFailure::diffIdentical($this->value, $other)
- );
+ if (!$not) {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ $description,
+ PHPUnit_Framework_ComparisonFailure::diffIdentical($this->value, $other)
+ );
+ } else {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ $description
+ );
+ }
}
/**
View
17 PHPUnit/Framework/Constraint/IsIdentical.php
@@ -96,14 +96,21 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
- throw new PHPUnit_Framework_ExpectationFailedException(
- $description,
- PHPUnit_Framework_ComparisonFailure::diffIdentical($this->value, $other)
- );
+ if (!$not) {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ $description,
+ PHPUnit_Framework_ComparisonFailure::diffIdentical($this->value, $other)
+ );
+ } else {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ $description
+ );
+ }
}
/**
View
15 PHPUnit/Framework/Constraint/IsInstanceOf.php
@@ -47,6 +47,7 @@
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/Type.php';
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
@@ -91,25 +92,29 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
+ if (!empty($description)) {
+ $description .= "\n";
+ }
+
if (!is_object($other)) {
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
- "%s\nexpected object instance of class <%s>, got %s <%s>",
+ '%sExpected object of class "%s", got %s.',
$description,
$this->className,
- gettype($other),
- print_r($other, TRUE)
+ PHPUnit_Util_Type::toString($other)
)
);
} else {
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
- "%s\nexpected object instance of class <%s>, got class <%s>",
+ '%sExpected object of class "%s", got object of class "%s".',
$description,
$this->className,
View
45 PHPUnit/Framework/Constraint/IsType.php
@@ -145,52 +145,13 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
- switch ($this->type) {
- case 'integer':
- case 'int': {
- $expected = 1;
- }
- break;
-
- case 'float': {
- $expected = 1.1;
- }
- break;
-
- case 'string': {
- $expected = 'str';
- }
- break;
-
- case 'boolean':
- case 'bool': {
- $expected = TRUE;
- }
- break;
-
- case 'null': {
- $expected = NULL;
- }
- break;
-
- case 'array': {
- $expected = array(1);
- }
- break;
-
- case 'object': {
- $expected = new Exception();
- }
- break;
- }
-
throw new PHPUnit_Framework_ExpectationFailedException(
- $description,
- new PHPUnit_Framework_ComparisonFailure_Type($expected, $other)
+ $description
);
}
View
17 PHPUnit/Framework/Constraint/LessThan.php
@@ -91,14 +91,21 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
- throw new PHPUnit_Framework_ExpectationFailedException(
- $description,
- PHPUnit_Framework_ComparisonFailure::diffIdentical($this->value, $other)
- );
+ if (!$not) {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ $description,
+ PHPUnit_Framework_ComparisonFailure::diffIdentical($this->value, $other)
+ );
+ } else {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ $description
+ );
+ }
}
/**
View
5 PHPUnit/Framework/Constraint/Not.php
@@ -99,11 +99,12 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
- $this->constraint->fail($other, $description);
+ $this->constraint->fail($other, $description, TRUE);
}
/**
View
20 PHPUnit/Framework/Constraint/ObjectHasAttribute.php
@@ -47,6 +47,7 @@
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/Type.php';
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
@@ -92,18 +93,22 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
+ if (!empty($description)) {
+ $description .= "\n";
+ }
+
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
- "%s\nexpected attribute <%s:%s> not found in object <%s>",
+ '%sExpected attribute "%s" not found in %s.',
$description,
- gettype($this->attributeName),
- print_r($this->attributeName, TRUE),
- print_r($other, TRUE)
+ $this->attributeName,
+ PHPUnit_Util_Type::toString($other)
)
);
}
@@ -117,10 +122,9 @@ public function fail($other, $description)
public function toString()
{
return sprintf(
- 'has attribute <%s:%s>',
+ 'object has attribute "%s"',
- gettype($this->attributeName),
- print_r($this->attributeName, TRUE)
+ $this->attributeName
);
}
}
View
12 PHPUnit/Framework/Constraint/Or.php
@@ -47,6 +47,7 @@
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/Type.php';
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
@@ -106,16 +107,21 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
+ if (!empty($description)) {
+ $description .= "\n";
+ }
+
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
- "%s\nexpected <%s> %s",
+ "%sExpected that %s %s",
$description,
- print_r($other, TRUE),
+ PHPUnit_Util_Type::toString($other),
$this->toString()
)
);
View
31 PHPUnit/Framework/Constraint/PCREMatch.php
@@ -47,6 +47,7 @@
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/Type.php';
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
@@ -94,20 +95,26 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
- throw new PHPUnit_Framework_ExpectationFailedException(
- sprintf(
- "%s\nPCRE pattern <%s> did not find a match in value <%s:%s>",
+ if (empty($description)) {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ sprintf(
+ '%sPCRE pattern "%s" did not find a match in %s',
- $description,
- print_r($this->pattern, TRUE),
- gettype($other),
- print_r($other, TRUE)
- )
- );
+ $description,
+ $this->pattern,
+ PHPUnit_Util_Type::toString($other)
+ )
+ );
+ } else {
+ throw new PHPUnit_Framework_ExpectationFailedException(
+ $description
+ );
+ }
}
/**
@@ -119,9 +126,9 @@ public function fail($other, $description)
public function toString()
{
return sprintf(
- 'matches PCRE pattern <%s>',
+ 'string matches PCRE pattern "%s"',
- print_r($this->pattern, TRUE)
+ $this->pattern
);
}
}
View
30 PHPUnit/Framework/Constraint/StringContains.php
@@ -47,6 +47,7 @@
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/Type.php';
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
@@ -101,25 +102,30 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
if ($this->case) {
- $string = print_r($this->string, TRUE);
- $otherString = print_r($other, TRUE);
+ $string = $this->string;
+ $otherString = $other;
} else {
- $string = print_r(strtolower($this->string), TRUE);
- $otherString = print_r(strtolower($other), TRUE);
+ $string = strtolower($this->string);
+ $otherString = strtolower($other);
+ }
+
+ if (!empty($description)) {
+ $description .= "\n";
}
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
- "%s\nexpected string <%s> not found in string <%s>",
+ '%sExpected %s not found in %s.',
$description,
- $string,
- $otherString
+ PHPUnit_Util_Type::toString($string),
+ PHPUnit_Util_Type::toString($otherString)
)
);
}
@@ -133,15 +139,15 @@ public function fail($other, $description)
public function toString()
{
if ($this->case) {
- $string = print_r($this->string, TRUE);
+ $string = $this->string;
} else {
- $string = print_r(strtolower($this->string), TRUE);
+ $string = strtolower($this->string);
}
return sprintf(
- 'contains string <%s>',
+ 'contains %s',
- $string
+ PHPUnit_Util_Type::toString($string)
);
}
}
View
3 PHPUnit/Framework/Constraint/TraversableContains.php
@@ -96,9 +96,10 @@ public function evaluate($other)
* constraint check.
* @param string $description A string with extra description of what was
* going on while the evaluation failed.
+ * @param boolean $not Flag to indicate negation.
* @throws PHPUnit_Framework_ExpectationFailedException
*/
- public function fail($other, $description)
+ public function fail($other, $description, $not = FALSE)
{
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(

0 comments on commit 30d7511

Please sign in to comment.
Something went wrong with that request. Please try again.