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_And extends PHPUnit_Framework_Constraint
19 * @var PHPUnit_Framework_Constraint[]
21 protected $constraints = array();
24 * @var PHPUnit_Framework_Constraint
26 protected $lastConstraint = null;
29 * @param PHPUnit_Framework_Constraint[] $constraints
31 * @throws PHPUnit_Framework_Exception
33 public function setConstraints(array $constraints)
35 $this->constraints = array();
37 foreach ($constraints as $constraint) {
38 if (!($constraint instanceof PHPUnit_Framework_Constraint)) {
39 throw new PHPUnit_Framework_Exception(
40 'All parameters to ' . __CLASS__ .
41 ' must be a constraint object.'
45 $this->constraints[] = $constraint;
50 * Evaluates the constraint for parameter $other
52 * If $returnResult is set to false (the default), an exception is thrown
53 * in case of a failure. null is returned otherwise.
55 * If $returnResult is true, the result of the evaluation is returned as
56 * a boolean value instead: true in case of success, false in case of a
59 * @param mixed $other Value or object to evaluate.
60 * @param string $description Additional information about the test
61 * @param bool $returnResult Whether to return a result or throw an exception
65 * @throws PHPUnit_Framework_ExpectationFailedException
67 public function evaluate($other, $description = '', $returnResult = false)
72 foreach ($this->constraints as $constraint) {
73 if (!$constraint->evaluate($other, $description, true)) {
84 $this->fail($other, $description);
89 * Returns a string representation of the constraint.
93 public function toString()
97 foreach ($this->constraints as $key => $constraint) {
102 $text .= $constraint->toString();
109 * Counts the number of constraint elements.
113 * @since Method available since Release 3.4.0
115 public function count()
119 foreach ($this->constraints as $constraint) {
120 $count += count($constraint);