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_Xor extends PHPUnit_Framework_Constraint
19 * @var PHPUnit_Framework_Constraint[]
21 protected $constraints = array();
24 * @param PHPUnit_Framework_Constraint[] $constraints
26 public function setConstraints(array $constraints)
28 $this->constraints = array();
30 foreach ($constraints as $constraint) {
31 if (!($constraint instanceof PHPUnit_Framework_Constraint)) {
32 $constraint = new PHPUnit_Framework_Constraint_IsEqual(
37 $this->constraints[] = $constraint;
42 * Evaluates the constraint for parameter $other
44 * If $returnResult is set to false (the default), an exception is thrown
45 * in case of a failure. null is returned otherwise.
47 * If $returnResult is true, the result of the evaluation is returned as
48 * a boolean value instead: true in case of success, false in case of a
51 * @param mixed $other Value or object to evaluate.
52 * @param string $description Additional information about the test
53 * @param bool $returnResult Whether to return a result or throw an exception
57 * @throws PHPUnit_Framework_ExpectationFailedException
59 public function evaluate($other, $description = '', $returnResult = false)
65 foreach ($this->constraints as $constraint) {
66 $result = $constraint->evaluate($other, $description, true);
68 if ($result === $lastResult) {
73 $lastResult = $result;
81 $this->fail($other, $description);
86 * Returns a string representation of the constraint.
90 public function toString()
94 foreach ($this->constraints as $key => $constraint) {
99 $text .= $constraint->toString();
106 * Counts the number of constraint elements.
110 * @since Method available since Release 3.4.0
112 public function count()
116 foreach ($this->constraints as $constraint) {
117 $count += count($constraint);