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_Or 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)
64 foreach ($this->constraints as $constraint) {
65 if ($constraint->evaluate($other, $description, true)) {
76 $this->fail($other, $description);
81 * Returns a string representation of the constraint.
85 public function toString()
89 foreach ($this->constraints as $key => $constraint) {
94 $text .= $constraint->toString();
101 * Counts the number of constraint elements.
105 * @since Method available since Release 3.4.0
107 public function count()
111 foreach ($this->constraints as $constraint) {
112 $count += count($constraint);