3 * This file is part of PHPUnit.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
14 * @since Class available since Release 3.0.0
16 class PHPUnit_Framework_Constraint_Not extends PHPUnit_Framework_Constraint
19 * @var PHPUnit_Framework_Constraint
21 protected $constraint;
24 * @param PHPUnit_Framework_Constraint $constraint
26 public function __construct($constraint)
28 parent::__construct();
30 if (!($constraint instanceof PHPUnit_Framework_Constraint)) {
31 $constraint = new PHPUnit_Framework_Constraint_IsEqual($constraint);
34 $this->constraint = $constraint;
38 * @param string $string
42 public static function negate($string)
74 * Evaluates the constraint for parameter $other
76 * If $returnResult is set to false (the default), an exception is thrown
77 * in case of a failure. null is returned otherwise.
79 * If $returnResult is true, the result of the evaluation is returned as
80 * a boolean value instead: true in case of success, false in case of a
83 * @param mixed $other Value or object to evaluate.
84 * @param string $description Additional information about the test
85 * @param bool $returnResult Whether to return a result or throw an exception
89 * @throws PHPUnit_Framework_ExpectationFailedException
91 public function evaluate($other, $description = '', $returnResult = false)
93 $success = !$this->constraint->evaluate($other, $description, true);
100 $this->fail($other, $description);
105 * Returns the description of the failure
107 * The beginning of failure messages is "Failed asserting that" in most
108 * cases. This method should return the second part of that sentence.
110 * @param mixed $other Evaluated value or object.
114 protected function failureDescription($other)
116 switch (get_class($this->constraint)) {
117 case 'PHPUnit_Framework_Constraint_And':
118 case 'PHPUnit_Framework_Constraint_Not':
119 case 'PHPUnit_Framework_Constraint_Or':
120 return 'not( ' . $this->constraint->failureDescription($other) . ' )';
124 $this->constraint->failureDescription($other)
130 * Returns a string representation of the constraint.
134 public function toString()
136 switch (get_class($this->constraint)) {
137 case 'PHPUnit_Framework_Constraint_And':
138 case 'PHPUnit_Framework_Constraint_Not':
139 case 'PHPUnit_Framework_Constraint_Or':
140 return 'not( ' . $this->constraint->toString() . ' )';
144 $this->constraint->toString()
150 * Counts the number of constraint elements.
154 * @since Method available since Release 3.4.0
156 public function count()
158 return count($this->constraint);