Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / phpunit / phpunit / src / Framework / Constraint / Xor.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  * Logical XOR.
13  *
14  * @since Class available since Release 3.0.0
15  */
16 class PHPUnit_Framework_Constraint_Xor extends PHPUnit_Framework_Constraint
17 {
18     /**
19      * @var PHPUnit_Framework_Constraint[]
20      */
21     protected $constraints = array();
22
23     /**
24      * @param PHPUnit_Framework_Constraint[] $constraints
25      */
26     public function setConstraints(array $constraints)
27     {
28         $this->constraints = array();
29
30         foreach ($constraints as $constraint) {
31             if (!($constraint instanceof PHPUnit_Framework_Constraint)) {
32                 $constraint = new PHPUnit_Framework_Constraint_IsEqual(
33                     $constraint
34                 );
35             }
36
37             $this->constraints[] = $constraint;
38         }
39     }
40
41     /**
42      * Evaluates the constraint for parameter $other
43      *
44      * If $returnResult is set to false (the default), an exception is thrown
45      * in case of a failure. null is returned otherwise.
46      *
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
49      * failure.
50      *
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
54      *
55      * @return mixed
56      *
57      * @throws PHPUnit_Framework_ExpectationFailedException
58      */
59     public function evaluate($other, $description = '', $returnResult = false)
60     {
61         $success    = true;
62         $lastResult = null;
63         $constraint = null;
64
65         foreach ($this->constraints as $constraint) {
66             $result = $constraint->evaluate($other, $description, true);
67
68             if ($result === $lastResult) {
69                 $success = false;
70                 break;
71             }
72
73             $lastResult = $result;
74         }
75
76         if ($returnResult) {
77             return $success;
78         }
79
80         if (!$success) {
81             $this->fail($other, $description);
82         }
83     }
84
85     /**
86      * Returns a string representation of the constraint.
87      *
88      * @return string
89      */
90     public function toString()
91     {
92         $text = '';
93
94         foreach ($this->constraints as $key => $constraint) {
95             if ($key > 0) {
96                 $text .= ' xor ';
97             }
98
99             $text .= $constraint->toString();
100         }
101
102         return $text;
103     }
104
105     /**
106      * Counts the number of constraint elements.
107      *
108      * @return int
109      *
110      * @since  Method available since Release 3.4.0
111      */
112     public function count()
113     {
114         $count = 0;
115
116         foreach ($this->constraints as $constraint) {
117             $count += count($constraint);
118         }
119
120         return $count;
121     }
122 }