680b832a7da71c2c9de808e7b65bec87f7b9ead7
[yaffs-website] / vendor / phpunit / phpunit / src / Framework / Constraint / Composite.php
1 <?php
2 /*
3  * This file is part of PHPUnit.
4  *
5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * @since Class available since Release 3.1.0
13  */
14 abstract class PHPUnit_Framework_Constraint_Composite extends PHPUnit_Framework_Constraint
15 {
16     /**
17      * @var PHPUnit_Framework_Constraint
18      */
19     protected $innerConstraint;
20
21     /**
22      * @param PHPUnit_Framework_Constraint $innerConstraint
23      */
24     public function __construct(PHPUnit_Framework_Constraint $innerConstraint)
25     {
26         parent::__construct();
27         $this->innerConstraint = $innerConstraint;
28     }
29
30     /**
31      * Evaluates the constraint for parameter $other
32      *
33      * If $returnResult is set to false (the default), an exception is thrown
34      * in case of a failure. null is returned otherwise.
35      *
36      * If $returnResult is true, the result of the evaluation is returned as
37      * a boolean value instead: true in case of success, false in case of a
38      * failure.
39      *
40      * @param mixed  $other        Value or object to evaluate.
41      * @param string $description  Additional information about the test
42      * @param bool   $returnResult Whether to return a result or throw an exception
43      *
44      * @return mixed
45      *
46      * @throws PHPUnit_Framework_ExpectationFailedException
47      */
48     public function evaluate($other, $description = '', $returnResult = false)
49     {
50         try {
51             return $this->innerConstraint->evaluate(
52                 $other,
53                 $description,
54                 $returnResult
55             );
56         } catch (PHPUnit_Framework_ExpectationFailedException $e) {
57             $this->fail($other, $description);
58         }
59     }
60
61     /**
62      * Counts the number of constraint elements.
63      *
64      * @return int
65      */
66     public function count()
67     {
68         return count($this->innerConstraint);
69     }
70 }