@@ -15,58 +15,58 @@ |
||
15 | 15 | */ |
16 | 16 | class JsonMatchesErrorMessageProvider |
17 | 17 | { |
18 | - /** |
|
19 | - * Translates JSON error to a human readable string. |
|
20 | - * |
|
21 | - * @param string $error |
|
22 | - * @param string $prefix |
|
23 | - * |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public static function determineJsonError($error, $prefix = '') |
|
27 | - { |
|
28 | - switch ($error) { |
|
29 | - case JSON_ERROR_NONE: |
|
30 | - return; |
|
31 | - case JSON_ERROR_DEPTH: |
|
32 | - return $prefix . 'Maximum stack depth exceeded'; |
|
33 | - case JSON_ERROR_STATE_MISMATCH: |
|
34 | - return $prefix . 'Underflow or the modes mismatch'; |
|
35 | - case JSON_ERROR_CTRL_CHAR: |
|
36 | - return $prefix . 'Unexpected control character found'; |
|
37 | - case JSON_ERROR_SYNTAX: |
|
38 | - return $prefix . 'Syntax error, malformed JSON'; |
|
39 | - case JSON_ERROR_UTF8: |
|
40 | - return $prefix . 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
41 | - default: |
|
42 | - return $prefix . 'Unknown error'; |
|
43 | - } |
|
44 | - } |
|
18 | + /** |
|
19 | + * Translates JSON error to a human readable string. |
|
20 | + * |
|
21 | + * @param string $error |
|
22 | + * @param string $prefix |
|
23 | + * |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public static function determineJsonError($error, $prefix = '') |
|
27 | + { |
|
28 | + switch ($error) { |
|
29 | + case JSON_ERROR_NONE: |
|
30 | + return; |
|
31 | + case JSON_ERROR_DEPTH: |
|
32 | + return $prefix . 'Maximum stack depth exceeded'; |
|
33 | + case JSON_ERROR_STATE_MISMATCH: |
|
34 | + return $prefix . 'Underflow or the modes mismatch'; |
|
35 | + case JSON_ERROR_CTRL_CHAR: |
|
36 | + return $prefix . 'Unexpected control character found'; |
|
37 | + case JSON_ERROR_SYNTAX: |
|
38 | + return $prefix . 'Syntax error, malformed JSON'; |
|
39 | + case JSON_ERROR_UTF8: |
|
40 | + return $prefix . 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
41 | + default: |
|
42 | + return $prefix . 'Unknown error'; |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Translates a given type to a human readable message prefix. |
|
48 | - * |
|
49 | - * @param string $type |
|
50 | - * |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public static function translateTypeToPrefix($type) |
|
54 | - { |
|
55 | - switch (\strtolower($type)) { |
|
56 | - case 'expected': |
|
57 | - $prefix = 'Expected value JSON decode error - '; |
|
46 | + /** |
|
47 | + * Translates a given type to a human readable message prefix. |
|
48 | + * |
|
49 | + * @param string $type |
|
50 | + * |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public static function translateTypeToPrefix($type) |
|
54 | + { |
|
55 | + switch (\strtolower($type)) { |
|
56 | + case 'expected': |
|
57 | + $prefix = 'Expected value JSON decode error - '; |
|
58 | 58 | |
59 | - break; |
|
60 | - case 'actual': |
|
61 | - $prefix = 'Actual value JSON decode error - '; |
|
59 | + break; |
|
60 | + case 'actual': |
|
61 | + $prefix = 'Actual value JSON decode error - '; |
|
62 | 62 | |
63 | - break; |
|
64 | - default: |
|
65 | - $prefix = ''; |
|
63 | + break; |
|
64 | + default: |
|
65 | + $prefix = ''; |
|
66 | 66 | |
67 | - break; |
|
68 | - } |
|
67 | + break; |
|
68 | + } |
|
69 | 69 | |
70 | - return $prefix; |
|
71 | - } |
|
70 | + return $prefix; |
|
71 | + } |
|
72 | 72 | } |
@@ -29,17 +29,17 @@ |
||
29 | 29 | case JSON_ERROR_NONE: |
30 | 30 | return; |
31 | 31 | case JSON_ERROR_DEPTH: |
32 | - return $prefix . 'Maximum stack depth exceeded'; |
|
32 | + return $prefix.'Maximum stack depth exceeded'; |
|
33 | 33 | case JSON_ERROR_STATE_MISMATCH: |
34 | - return $prefix . 'Underflow or the modes mismatch'; |
|
34 | + return $prefix.'Underflow or the modes mismatch'; |
|
35 | 35 | case JSON_ERROR_CTRL_CHAR: |
36 | - return $prefix . 'Unexpected control character found'; |
|
36 | + return $prefix.'Unexpected control character found'; |
|
37 | 37 | case JSON_ERROR_SYNTAX: |
38 | - return $prefix . 'Syntax error, malformed JSON'; |
|
38 | + return $prefix.'Syntax error, malformed JSON'; |
|
39 | 39 | case JSON_ERROR_UTF8: |
40 | - return $prefix . 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
40 | + return $prefix.'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
41 | 41 | default: |
42 | - return $prefix . 'Unknown error'; |
|
42 | + return $prefix.'Unknown error'; |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 |
@@ -14,26 +14,26 @@ |
||
14 | 14 | */ |
15 | 15 | class IsFalse extends Constraint |
16 | 16 | { |
17 | - /** |
|
18 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
19 | - * constraint is met, false otherwise. |
|
20 | - * |
|
21 | - * @param mixed $other Value or object to evaluate. |
|
22 | - * |
|
23 | - * @return bool |
|
24 | - */ |
|
25 | - protected function matches($other) |
|
26 | - { |
|
27 | - return $other === false; |
|
28 | - } |
|
17 | + /** |
|
18 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
19 | + * constraint is met, false otherwise. |
|
20 | + * |
|
21 | + * @param mixed $other Value or object to evaluate. |
|
22 | + * |
|
23 | + * @return bool |
|
24 | + */ |
|
25 | + protected function matches($other) |
|
26 | + { |
|
27 | + return $other === false; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Returns a string representation of the constraint. |
|
32 | - * |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function toString() |
|
36 | - { |
|
37 | - return 'is false'; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Returns a string representation of the constraint. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function toString() |
|
36 | + { |
|
37 | + return 'is false'; |
|
38 | + } |
|
39 | 39 | } |
@@ -16,166 +16,166 @@ |
||
16 | 16 | */ |
17 | 17 | class LogicalNot extends Constraint |
18 | 18 | { |
19 | - /** |
|
20 | - * @var Constraint |
|
21 | - */ |
|
22 | - protected $constraint; |
|
23 | - |
|
24 | - /** |
|
25 | - * @param Constraint $constraint |
|
26 | - */ |
|
27 | - public function __construct($constraint) |
|
28 | - { |
|
29 | - parent::__construct(); |
|
30 | - |
|
31 | - if (!($constraint instanceof Constraint)) { |
|
32 | - $constraint = new IsEqual($constraint); |
|
33 | - } |
|
34 | - |
|
35 | - $this->constraint = $constraint; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @param string $string |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public static function negate($string) |
|
44 | - { |
|
45 | - $positives = [ |
|
46 | - 'contains ', |
|
47 | - 'exists', |
|
48 | - 'has ', |
|
49 | - 'is ', |
|
50 | - 'are ', |
|
51 | - 'matches ', |
|
52 | - 'starts with ', |
|
53 | - 'ends with ', |
|
54 | - 'reference ', |
|
55 | - 'not not ' |
|
56 | - ]; |
|
57 | - |
|
58 | - $negatives = [ |
|
59 | - 'does not contain ', |
|
60 | - 'does not exist', |
|
61 | - 'does not have ', |
|
62 | - 'is not ', |
|
63 | - 'are not ', |
|
64 | - 'does not match ', |
|
65 | - 'starts not with ', |
|
66 | - 'ends not with ', |
|
67 | - 'don\'t reference ', |
|
68 | - 'not ' |
|
69 | - ]; |
|
70 | - |
|
71 | - \preg_match('/(\'[\w\W]*\')([\w\W]*)("[\w\W]*")/i', $string, $matches); |
|
72 | - |
|
73 | - if (\count($matches) > 0) { |
|
74 | - $nonInput = $matches[2]; |
|
75 | - |
|
76 | - $negatedString = \str_replace( |
|
77 | - $nonInput, |
|
78 | - \str_replace( |
|
79 | - $positives, |
|
80 | - $negatives, |
|
81 | - $nonInput |
|
82 | - ), |
|
83 | - $string |
|
84 | - ); |
|
85 | - } else { |
|
86 | - $negatedString = \str_replace( |
|
87 | - $positives, |
|
88 | - $negatives, |
|
89 | - $string |
|
90 | - ); |
|
91 | - } |
|
92 | - |
|
93 | - return $negatedString; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Evaluates the constraint for parameter $other |
|
98 | - * |
|
99 | - * If $returnResult is set to false (the default), an exception is thrown |
|
100 | - * in case of a failure. null is returned otherwise. |
|
101 | - * |
|
102 | - * If $returnResult is true, the result of the evaluation is returned as |
|
103 | - * a boolean value instead: true in case of success, false in case of a |
|
104 | - * failure. |
|
105 | - * |
|
106 | - * @param mixed $other Value or object to evaluate. |
|
107 | - * @param string $description Additional information about the test |
|
108 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
109 | - * |
|
110 | - * @return mixed |
|
111 | - * |
|
112 | - * @throws ExpectationFailedException |
|
113 | - */ |
|
114 | - public function evaluate($other, $description = '', $returnResult = false) |
|
115 | - { |
|
116 | - $success = !$this->constraint->evaluate($other, $description, true); |
|
117 | - |
|
118 | - if ($returnResult) { |
|
119 | - return $success; |
|
120 | - } |
|
121 | - |
|
122 | - if (!$success) { |
|
123 | - $this->fail($other, $description); |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Returns the description of the failure |
|
129 | - * |
|
130 | - * The beginning of failure messages is "Failed asserting that" in most |
|
131 | - * cases. This method should return the second part of that sentence. |
|
132 | - * |
|
133 | - * @param mixed $other Evaluated value or object. |
|
134 | - * |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - protected function failureDescription($other) |
|
138 | - { |
|
139 | - switch (\get_class($this->constraint)) { |
|
140 | - case LogicalAnd::class: |
|
141 | - case self::class: |
|
142 | - case LogicalOr::class: |
|
143 | - return 'not( ' . $this->constraint->failureDescription($other) . ' )'; |
|
144 | - |
|
145 | - default: |
|
146 | - return self::negate( |
|
147 | - $this->constraint->failureDescription($other) |
|
148 | - ); |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Returns a string representation of the constraint. |
|
154 | - * |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function toString() |
|
158 | - { |
|
159 | - switch (\get_class($this->constraint)) { |
|
160 | - case LogicalAnd::class: |
|
161 | - case self::class: |
|
162 | - case LogicalOr::class: |
|
163 | - return 'not( ' . $this->constraint->toString() . ' )'; |
|
164 | - |
|
165 | - default: |
|
166 | - return self::negate( |
|
167 | - $this->constraint->toString() |
|
168 | - ); |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Counts the number of constraint elements. |
|
174 | - * |
|
175 | - * @return int |
|
176 | - */ |
|
177 | - public function count() |
|
178 | - { |
|
179 | - return \count($this->constraint); |
|
180 | - } |
|
19 | + /** |
|
20 | + * @var Constraint |
|
21 | + */ |
|
22 | + protected $constraint; |
|
23 | + |
|
24 | + /** |
|
25 | + * @param Constraint $constraint |
|
26 | + */ |
|
27 | + public function __construct($constraint) |
|
28 | + { |
|
29 | + parent::__construct(); |
|
30 | + |
|
31 | + if (!($constraint instanceof Constraint)) { |
|
32 | + $constraint = new IsEqual($constraint); |
|
33 | + } |
|
34 | + |
|
35 | + $this->constraint = $constraint; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @param string $string |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public static function negate($string) |
|
44 | + { |
|
45 | + $positives = [ |
|
46 | + 'contains ', |
|
47 | + 'exists', |
|
48 | + 'has ', |
|
49 | + 'is ', |
|
50 | + 'are ', |
|
51 | + 'matches ', |
|
52 | + 'starts with ', |
|
53 | + 'ends with ', |
|
54 | + 'reference ', |
|
55 | + 'not not ' |
|
56 | + ]; |
|
57 | + |
|
58 | + $negatives = [ |
|
59 | + 'does not contain ', |
|
60 | + 'does not exist', |
|
61 | + 'does not have ', |
|
62 | + 'is not ', |
|
63 | + 'are not ', |
|
64 | + 'does not match ', |
|
65 | + 'starts not with ', |
|
66 | + 'ends not with ', |
|
67 | + 'don\'t reference ', |
|
68 | + 'not ' |
|
69 | + ]; |
|
70 | + |
|
71 | + \preg_match('/(\'[\w\W]*\')([\w\W]*)("[\w\W]*")/i', $string, $matches); |
|
72 | + |
|
73 | + if (\count($matches) > 0) { |
|
74 | + $nonInput = $matches[2]; |
|
75 | + |
|
76 | + $negatedString = \str_replace( |
|
77 | + $nonInput, |
|
78 | + \str_replace( |
|
79 | + $positives, |
|
80 | + $negatives, |
|
81 | + $nonInput |
|
82 | + ), |
|
83 | + $string |
|
84 | + ); |
|
85 | + } else { |
|
86 | + $negatedString = \str_replace( |
|
87 | + $positives, |
|
88 | + $negatives, |
|
89 | + $string |
|
90 | + ); |
|
91 | + } |
|
92 | + |
|
93 | + return $negatedString; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Evaluates the constraint for parameter $other |
|
98 | + * |
|
99 | + * If $returnResult is set to false (the default), an exception is thrown |
|
100 | + * in case of a failure. null is returned otherwise. |
|
101 | + * |
|
102 | + * If $returnResult is true, the result of the evaluation is returned as |
|
103 | + * a boolean value instead: true in case of success, false in case of a |
|
104 | + * failure. |
|
105 | + * |
|
106 | + * @param mixed $other Value or object to evaluate. |
|
107 | + * @param string $description Additional information about the test |
|
108 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
109 | + * |
|
110 | + * @return mixed |
|
111 | + * |
|
112 | + * @throws ExpectationFailedException |
|
113 | + */ |
|
114 | + public function evaluate($other, $description = '', $returnResult = false) |
|
115 | + { |
|
116 | + $success = !$this->constraint->evaluate($other, $description, true); |
|
117 | + |
|
118 | + if ($returnResult) { |
|
119 | + return $success; |
|
120 | + } |
|
121 | + |
|
122 | + if (!$success) { |
|
123 | + $this->fail($other, $description); |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Returns the description of the failure |
|
129 | + * |
|
130 | + * The beginning of failure messages is "Failed asserting that" in most |
|
131 | + * cases. This method should return the second part of that sentence. |
|
132 | + * |
|
133 | + * @param mixed $other Evaluated value or object. |
|
134 | + * |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + protected function failureDescription($other) |
|
138 | + { |
|
139 | + switch (\get_class($this->constraint)) { |
|
140 | + case LogicalAnd::class: |
|
141 | + case self::class: |
|
142 | + case LogicalOr::class: |
|
143 | + return 'not( ' . $this->constraint->failureDescription($other) . ' )'; |
|
144 | + |
|
145 | + default: |
|
146 | + return self::negate( |
|
147 | + $this->constraint->failureDescription($other) |
|
148 | + ); |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Returns a string representation of the constraint. |
|
154 | + * |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function toString() |
|
158 | + { |
|
159 | + switch (\get_class($this->constraint)) { |
|
160 | + case LogicalAnd::class: |
|
161 | + case self::class: |
|
162 | + case LogicalOr::class: |
|
163 | + return 'not( ' . $this->constraint->toString() . ' )'; |
|
164 | + |
|
165 | + default: |
|
166 | + return self::negate( |
|
167 | + $this->constraint->toString() |
|
168 | + ); |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Counts the number of constraint elements. |
|
174 | + * |
|
175 | + * @return int |
|
176 | + */ |
|
177 | + public function count() |
|
178 | + { |
|
179 | + return \count($this->constraint); |
|
180 | + } |
|
181 | 181 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | case LogicalAnd::class: |
141 | 141 | case self::class: |
142 | 142 | case LogicalOr::class: |
143 | - return 'not( ' . $this->constraint->failureDescription($other) . ' )'; |
|
143 | + return 'not( '.$this->constraint->failureDescription($other).' )'; |
|
144 | 144 | |
145 | 145 | default: |
146 | 146 | return self::negate( |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | case LogicalAnd::class: |
161 | 161 | case self::class: |
162 | 162 | case LogicalOr::class: |
163 | - return 'not( ' . $this->constraint->toString() . ' )'; |
|
163 | + return 'not( '.$this->constraint->toString().' )'; |
|
164 | 164 | |
165 | 165 | default: |
166 | 166 | return self::negate( |
@@ -16,110 +16,110 @@ |
||
16 | 16 | */ |
17 | 17 | class LogicalAnd extends Constraint |
18 | 18 | { |
19 | - /** |
|
20 | - * @var Constraint[] |
|
21 | - */ |
|
22 | - protected $constraints = []; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var Constraint |
|
26 | - */ |
|
27 | - protected $lastConstraint; |
|
28 | - |
|
29 | - /** |
|
30 | - * @param Constraint[] $constraints |
|
31 | - * |
|
32 | - * @throws \PHPUnit\Framework\Exception |
|
33 | - */ |
|
34 | - public function setConstraints(array $constraints) |
|
35 | - { |
|
36 | - $this->constraints = []; |
|
37 | - |
|
38 | - foreach ($constraints as $constraint) { |
|
39 | - if (!($constraint instanceof Constraint)) { |
|
40 | - throw new \PHPUnit\Framework\Exception( |
|
41 | - 'All parameters to ' . __CLASS__ . |
|
42 | - ' must be a constraint object.' |
|
43 | - ); |
|
44 | - } |
|
45 | - |
|
46 | - $this->constraints[] = $constraint; |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Evaluates the constraint for parameter $other |
|
52 | - * |
|
53 | - * If $returnResult is set to false (the default), an exception is thrown |
|
54 | - * in case of a failure. null is returned otherwise. |
|
55 | - * |
|
56 | - * If $returnResult is true, the result of the evaluation is returned as |
|
57 | - * a boolean value instead: true in case of success, false in case of a |
|
58 | - * failure. |
|
59 | - * |
|
60 | - * @param mixed $other Value or object to evaluate. |
|
61 | - * @param string $description Additional information about the test |
|
62 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
63 | - * |
|
64 | - * @return mixed |
|
65 | - * |
|
66 | - * @throws ExpectationFailedException |
|
67 | - */ |
|
68 | - public function evaluate($other, $description = '', $returnResult = false) |
|
69 | - { |
|
70 | - $success = true; |
|
71 | - $constraint = null; |
|
72 | - |
|
73 | - foreach ($this->constraints as $constraint) { |
|
74 | - if (!$constraint->evaluate($other, $description, true)) { |
|
75 | - $success = false; |
|
76 | - |
|
77 | - break; |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - if ($returnResult) { |
|
82 | - return $success; |
|
83 | - } |
|
84 | - |
|
85 | - if (!$success) { |
|
86 | - $this->fail($other, $description); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Returns a string representation of the constraint. |
|
92 | - * |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function toString() |
|
96 | - { |
|
97 | - $text = ''; |
|
98 | - |
|
99 | - foreach ($this->constraints as $key => $constraint) { |
|
100 | - if ($key > 0) { |
|
101 | - $text .= ' and '; |
|
102 | - } |
|
103 | - |
|
104 | - $text .= $constraint->toString(); |
|
105 | - } |
|
106 | - |
|
107 | - return $text; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Counts the number of constraint elements. |
|
112 | - * |
|
113 | - * @return int |
|
114 | - */ |
|
115 | - public function count() |
|
116 | - { |
|
117 | - $count = 0; |
|
118 | - |
|
119 | - foreach ($this->constraints as $constraint) { |
|
120 | - $count += \count($constraint); |
|
121 | - } |
|
122 | - |
|
123 | - return $count; |
|
124 | - } |
|
19 | + /** |
|
20 | + * @var Constraint[] |
|
21 | + */ |
|
22 | + protected $constraints = []; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var Constraint |
|
26 | + */ |
|
27 | + protected $lastConstraint; |
|
28 | + |
|
29 | + /** |
|
30 | + * @param Constraint[] $constraints |
|
31 | + * |
|
32 | + * @throws \PHPUnit\Framework\Exception |
|
33 | + */ |
|
34 | + public function setConstraints(array $constraints) |
|
35 | + { |
|
36 | + $this->constraints = []; |
|
37 | + |
|
38 | + foreach ($constraints as $constraint) { |
|
39 | + if (!($constraint instanceof Constraint)) { |
|
40 | + throw new \PHPUnit\Framework\Exception( |
|
41 | + 'All parameters to ' . __CLASS__ . |
|
42 | + ' must be a constraint object.' |
|
43 | + ); |
|
44 | + } |
|
45 | + |
|
46 | + $this->constraints[] = $constraint; |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Evaluates the constraint for parameter $other |
|
52 | + * |
|
53 | + * If $returnResult is set to false (the default), an exception is thrown |
|
54 | + * in case of a failure. null is returned otherwise. |
|
55 | + * |
|
56 | + * If $returnResult is true, the result of the evaluation is returned as |
|
57 | + * a boolean value instead: true in case of success, false in case of a |
|
58 | + * failure. |
|
59 | + * |
|
60 | + * @param mixed $other Value or object to evaluate. |
|
61 | + * @param string $description Additional information about the test |
|
62 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
63 | + * |
|
64 | + * @return mixed |
|
65 | + * |
|
66 | + * @throws ExpectationFailedException |
|
67 | + */ |
|
68 | + public function evaluate($other, $description = '', $returnResult = false) |
|
69 | + { |
|
70 | + $success = true; |
|
71 | + $constraint = null; |
|
72 | + |
|
73 | + foreach ($this->constraints as $constraint) { |
|
74 | + if (!$constraint->evaluate($other, $description, true)) { |
|
75 | + $success = false; |
|
76 | + |
|
77 | + break; |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + if ($returnResult) { |
|
82 | + return $success; |
|
83 | + } |
|
84 | + |
|
85 | + if (!$success) { |
|
86 | + $this->fail($other, $description); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Returns a string representation of the constraint. |
|
92 | + * |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function toString() |
|
96 | + { |
|
97 | + $text = ''; |
|
98 | + |
|
99 | + foreach ($this->constraints as $key => $constraint) { |
|
100 | + if ($key > 0) { |
|
101 | + $text .= ' and '; |
|
102 | + } |
|
103 | + |
|
104 | + $text .= $constraint->toString(); |
|
105 | + } |
|
106 | + |
|
107 | + return $text; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Counts the number of constraint elements. |
|
112 | + * |
|
113 | + * @return int |
|
114 | + */ |
|
115 | + public function count() |
|
116 | + { |
|
117 | + $count = 0; |
|
118 | + |
|
119 | + foreach ($this->constraints as $constraint) { |
|
120 | + $count += \count($constraint); |
|
121 | + } |
|
122 | + |
|
123 | + return $count; |
|
124 | + } |
|
125 | 125 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | foreach ($constraints as $constraint) { |
39 | 39 | if (!($constraint instanceof Constraint)) { |
40 | 40 | throw new \PHPUnit\Framework\Exception( |
41 | - 'All parameters to ' . __CLASS__ . |
|
41 | + 'All parameters to '.__CLASS__. |
|
42 | 42 | ' must be a constraint object.' |
43 | 43 | ); |
44 | 44 | } |
@@ -24,159 +24,159 @@ |
||
24 | 24 | */ |
25 | 25 | class IsEqual extends Constraint |
26 | 26 | { |
27 | - /** |
|
28 | - * @var mixed |
|
29 | - */ |
|
30 | - protected $value; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var float |
|
34 | - */ |
|
35 | - protected $delta = 0.0; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var int |
|
39 | - */ |
|
40 | - protected $maxDepth = 10; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var bool |
|
44 | - */ |
|
45 | - protected $canonicalize = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var bool |
|
49 | - */ |
|
50 | - protected $ignoreCase = false; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var SebastianBergmann\Comparator\ComparisonFailure |
|
54 | - */ |
|
55 | - protected $lastFailure; |
|
56 | - |
|
57 | - /** |
|
58 | - * @param mixed $value |
|
59 | - * @param float $delta |
|
60 | - * @param int $maxDepth |
|
61 | - * @param bool $canonicalize |
|
62 | - * @param bool $ignoreCase |
|
63 | - * |
|
64 | - * @throws \PHPUnit\Framework\Exception |
|
65 | - */ |
|
66 | - public function __construct($value, $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false) |
|
67 | - { |
|
68 | - parent::__construct(); |
|
69 | - |
|
70 | - if (!\is_numeric($delta)) { |
|
71 | - throw InvalidArgumentHelper::factory(2, 'numeric'); |
|
72 | - } |
|
73 | - |
|
74 | - if (!\is_int($maxDepth)) { |
|
75 | - throw InvalidArgumentHelper::factory(3, 'integer'); |
|
76 | - } |
|
77 | - |
|
78 | - if (!\is_bool($canonicalize)) { |
|
79 | - throw InvalidArgumentHelper::factory(4, 'boolean'); |
|
80 | - } |
|
81 | - |
|
82 | - if (!\is_bool($ignoreCase)) { |
|
83 | - throw InvalidArgumentHelper::factory(5, 'boolean'); |
|
84 | - } |
|
85 | - |
|
86 | - $this->value = $value; |
|
87 | - $this->delta = $delta; |
|
88 | - $this->maxDepth = $maxDepth; |
|
89 | - $this->canonicalize = $canonicalize; |
|
90 | - $this->ignoreCase = $ignoreCase; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Evaluates the constraint for parameter $other |
|
95 | - * |
|
96 | - * If $returnResult is set to false (the default), an exception is thrown |
|
97 | - * in case of a failure. null is returned otherwise. |
|
98 | - * |
|
99 | - * If $returnResult is true, the result of the evaluation is returned as |
|
100 | - * a boolean value instead: true in case of success, false in case of a |
|
101 | - * failure. |
|
102 | - * |
|
103 | - * @param mixed $other Value or object to evaluate. |
|
104 | - * @param string $description Additional information about the test |
|
105 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
106 | - * |
|
107 | - * @return mixed |
|
108 | - * |
|
109 | - * @throws ExpectationFailedException |
|
110 | - */ |
|
111 | - public function evaluate($other, $description = '', $returnResult = false) |
|
112 | - { |
|
113 | - // If $this->value and $other are identical, they are also equal. |
|
114 | - // This is the most common path and will allow us to skip |
|
115 | - // initialization of all the comparators. |
|
116 | - if ($this->value === $other) { |
|
117 | - return true; |
|
118 | - } |
|
119 | - |
|
120 | - $comparatorFactory = SebastianBergmann\Comparator\Factory::getInstance(); |
|
121 | - |
|
122 | - try { |
|
123 | - $comparator = $comparatorFactory->getComparatorFor( |
|
124 | - $this->value, |
|
125 | - $other |
|
126 | - ); |
|
127 | - |
|
128 | - $comparator->assertEquals( |
|
129 | - $this->value, |
|
130 | - $other, |
|
131 | - $this->delta, |
|
132 | - $this->canonicalize, |
|
133 | - $this->ignoreCase |
|
134 | - ); |
|
135 | - } catch (SebastianBergmann\Comparator\ComparisonFailure $f) { |
|
136 | - if ($returnResult) { |
|
137 | - return false; |
|
138 | - } |
|
139 | - |
|
140 | - throw new ExpectationFailedException( |
|
141 | - \trim($description . "\n" . $f->getMessage()), |
|
142 | - $f |
|
143 | - ); |
|
144 | - } |
|
145 | - |
|
146 | - return true; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Returns a string representation of the constraint. |
|
151 | - * |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public function toString() |
|
155 | - { |
|
156 | - $delta = ''; |
|
157 | - |
|
158 | - if (\is_string($this->value)) { |
|
159 | - if (\strpos($this->value, "\n") !== false) { |
|
160 | - return 'is equal to <text>'; |
|
161 | - } |
|
162 | - |
|
163 | - return \sprintf( |
|
164 | - 'is equal to "%s"', |
|
165 | - $this->value |
|
166 | - ); |
|
167 | - } |
|
168 | - |
|
169 | - if ($this->delta != 0) { |
|
170 | - $delta = \sprintf( |
|
171 | - ' with delta <%F>', |
|
172 | - $this->delta |
|
173 | - ); |
|
174 | - } |
|
175 | - |
|
176 | - return \sprintf( |
|
177 | - 'is equal to %s%s', |
|
178 | - $this->exporter->export($this->value), |
|
179 | - $delta |
|
180 | - ); |
|
181 | - } |
|
27 | + /** |
|
28 | + * @var mixed |
|
29 | + */ |
|
30 | + protected $value; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var float |
|
34 | + */ |
|
35 | + protected $delta = 0.0; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var int |
|
39 | + */ |
|
40 | + protected $maxDepth = 10; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var bool |
|
44 | + */ |
|
45 | + protected $canonicalize = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var bool |
|
49 | + */ |
|
50 | + protected $ignoreCase = false; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var SebastianBergmann\Comparator\ComparisonFailure |
|
54 | + */ |
|
55 | + protected $lastFailure; |
|
56 | + |
|
57 | + /** |
|
58 | + * @param mixed $value |
|
59 | + * @param float $delta |
|
60 | + * @param int $maxDepth |
|
61 | + * @param bool $canonicalize |
|
62 | + * @param bool $ignoreCase |
|
63 | + * |
|
64 | + * @throws \PHPUnit\Framework\Exception |
|
65 | + */ |
|
66 | + public function __construct($value, $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false) |
|
67 | + { |
|
68 | + parent::__construct(); |
|
69 | + |
|
70 | + if (!\is_numeric($delta)) { |
|
71 | + throw InvalidArgumentHelper::factory(2, 'numeric'); |
|
72 | + } |
|
73 | + |
|
74 | + if (!\is_int($maxDepth)) { |
|
75 | + throw InvalidArgumentHelper::factory(3, 'integer'); |
|
76 | + } |
|
77 | + |
|
78 | + if (!\is_bool($canonicalize)) { |
|
79 | + throw InvalidArgumentHelper::factory(4, 'boolean'); |
|
80 | + } |
|
81 | + |
|
82 | + if (!\is_bool($ignoreCase)) { |
|
83 | + throw InvalidArgumentHelper::factory(5, 'boolean'); |
|
84 | + } |
|
85 | + |
|
86 | + $this->value = $value; |
|
87 | + $this->delta = $delta; |
|
88 | + $this->maxDepth = $maxDepth; |
|
89 | + $this->canonicalize = $canonicalize; |
|
90 | + $this->ignoreCase = $ignoreCase; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Evaluates the constraint for parameter $other |
|
95 | + * |
|
96 | + * If $returnResult is set to false (the default), an exception is thrown |
|
97 | + * in case of a failure. null is returned otherwise. |
|
98 | + * |
|
99 | + * If $returnResult is true, the result of the evaluation is returned as |
|
100 | + * a boolean value instead: true in case of success, false in case of a |
|
101 | + * failure. |
|
102 | + * |
|
103 | + * @param mixed $other Value or object to evaluate. |
|
104 | + * @param string $description Additional information about the test |
|
105 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
106 | + * |
|
107 | + * @return mixed |
|
108 | + * |
|
109 | + * @throws ExpectationFailedException |
|
110 | + */ |
|
111 | + public function evaluate($other, $description = '', $returnResult = false) |
|
112 | + { |
|
113 | + // If $this->value and $other are identical, they are also equal. |
|
114 | + // This is the most common path and will allow us to skip |
|
115 | + // initialization of all the comparators. |
|
116 | + if ($this->value === $other) { |
|
117 | + return true; |
|
118 | + } |
|
119 | + |
|
120 | + $comparatorFactory = SebastianBergmann\Comparator\Factory::getInstance(); |
|
121 | + |
|
122 | + try { |
|
123 | + $comparator = $comparatorFactory->getComparatorFor( |
|
124 | + $this->value, |
|
125 | + $other |
|
126 | + ); |
|
127 | + |
|
128 | + $comparator->assertEquals( |
|
129 | + $this->value, |
|
130 | + $other, |
|
131 | + $this->delta, |
|
132 | + $this->canonicalize, |
|
133 | + $this->ignoreCase |
|
134 | + ); |
|
135 | + } catch (SebastianBergmann\Comparator\ComparisonFailure $f) { |
|
136 | + if ($returnResult) { |
|
137 | + return false; |
|
138 | + } |
|
139 | + |
|
140 | + throw new ExpectationFailedException( |
|
141 | + \trim($description . "\n" . $f->getMessage()), |
|
142 | + $f |
|
143 | + ); |
|
144 | + } |
|
145 | + |
|
146 | + return true; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Returns a string representation of the constraint. |
|
151 | + * |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public function toString() |
|
155 | + { |
|
156 | + $delta = ''; |
|
157 | + |
|
158 | + if (\is_string($this->value)) { |
|
159 | + if (\strpos($this->value, "\n") !== false) { |
|
160 | + return 'is equal to <text>'; |
|
161 | + } |
|
162 | + |
|
163 | + return \sprintf( |
|
164 | + 'is equal to "%s"', |
|
165 | + $this->value |
|
166 | + ); |
|
167 | + } |
|
168 | + |
|
169 | + if ($this->delta != 0) { |
|
170 | + $delta = \sprintf( |
|
171 | + ' with delta <%F>', |
|
172 | + $this->delta |
|
173 | + ); |
|
174 | + } |
|
175 | + |
|
176 | + return \sprintf( |
|
177 | + 'is equal to %s%s', |
|
178 | + $this->exporter->export($this->value), |
|
179 | + $delta |
|
180 | + ); |
|
181 | + } |
|
182 | 182 | } |
@@ -138,7 +138,7 @@ |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | throw new ExpectationFailedException( |
141 | - \trim($description . "\n" . $f->getMessage()), |
|
141 | + \trim($description."\n".$f->getMessage()), |
|
142 | 142 | $f |
143 | 143 | ); |
144 | 144 | } |
@@ -18,114 +18,114 @@ |
||
18 | 18 | */ |
19 | 19 | class TraversableContains extends Constraint |
20 | 20 | { |
21 | - /** |
|
22 | - * @var bool |
|
23 | - */ |
|
24 | - protected $checkForObjectIdentity; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var bool |
|
28 | - */ |
|
29 | - protected $checkForNonObjectIdentity; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var mixed |
|
33 | - */ |
|
34 | - protected $value; |
|
35 | - |
|
36 | - /** |
|
37 | - * @param mixed $value |
|
38 | - * @param bool $checkForObjectIdentity |
|
39 | - * @param bool $checkForNonObjectIdentity |
|
40 | - * |
|
41 | - * @throws \PHPUnit\Framework\Exception |
|
42 | - */ |
|
43 | - public function __construct($value, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false) |
|
44 | - { |
|
45 | - parent::__construct(); |
|
46 | - |
|
47 | - if (!\is_bool($checkForObjectIdentity)) { |
|
48 | - throw InvalidArgumentHelper::factory(2, 'boolean'); |
|
49 | - } |
|
50 | - |
|
51 | - if (!\is_bool($checkForNonObjectIdentity)) { |
|
52 | - throw InvalidArgumentHelper::factory(3, 'boolean'); |
|
53 | - } |
|
54 | - |
|
55 | - $this->checkForObjectIdentity = $checkForObjectIdentity; |
|
56 | - $this->checkForNonObjectIdentity = $checkForNonObjectIdentity; |
|
57 | - $this->value = $value; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
62 | - * constraint is met, false otherwise. |
|
63 | - * |
|
64 | - * @param mixed $other Value or object to evaluate. |
|
65 | - * |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - protected function matches($other) |
|
69 | - { |
|
70 | - if ($other instanceof SplObjectStorage) { |
|
71 | - return $other->contains($this->value); |
|
72 | - } |
|
73 | - |
|
74 | - if (\is_object($this->value)) { |
|
75 | - foreach ($other as $element) { |
|
76 | - if ($this->checkForObjectIdentity && $element === $this->value) { |
|
77 | - return true; |
|
78 | - } |
|
79 | - |
|
80 | - if (!$this->checkForObjectIdentity && $element == $this->value) { |
|
81 | - return true; |
|
82 | - } |
|
83 | - } |
|
84 | - } else { |
|
85 | - foreach ($other as $element) { |
|
86 | - if ($this->checkForNonObjectIdentity && $element === $this->value) { |
|
87 | - return true; |
|
88 | - } |
|
89 | - |
|
90 | - if (!$this->checkForNonObjectIdentity && $element == $this->value) { |
|
91 | - return true; |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - return false; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns a string representation of the constraint. |
|
101 | - * |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public function toString() |
|
105 | - { |
|
106 | - if (\is_string($this->value) && \strpos($this->value, "\n") !== false) { |
|
107 | - return 'contains "' . $this->value . '"'; |
|
108 | - } |
|
109 | - |
|
110 | - return 'contains ' . $this->exporter->export($this->value); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Returns the description of the failure |
|
115 | - * |
|
116 | - * The beginning of failure messages is "Failed asserting that" in most |
|
117 | - * cases. This method should return the second part of that sentence. |
|
118 | - * |
|
119 | - * @param mixed $other Evaluated value or object. |
|
120 | - * |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - protected function failureDescription($other) |
|
124 | - { |
|
125 | - return \sprintf( |
|
126 | - '%s %s', |
|
127 | - \is_array($other) ? 'an array' : 'a traversable', |
|
128 | - $this->toString() |
|
129 | - ); |
|
130 | - } |
|
21 | + /** |
|
22 | + * @var bool |
|
23 | + */ |
|
24 | + protected $checkForObjectIdentity; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var bool |
|
28 | + */ |
|
29 | + protected $checkForNonObjectIdentity; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var mixed |
|
33 | + */ |
|
34 | + protected $value; |
|
35 | + |
|
36 | + /** |
|
37 | + * @param mixed $value |
|
38 | + * @param bool $checkForObjectIdentity |
|
39 | + * @param bool $checkForNonObjectIdentity |
|
40 | + * |
|
41 | + * @throws \PHPUnit\Framework\Exception |
|
42 | + */ |
|
43 | + public function __construct($value, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false) |
|
44 | + { |
|
45 | + parent::__construct(); |
|
46 | + |
|
47 | + if (!\is_bool($checkForObjectIdentity)) { |
|
48 | + throw InvalidArgumentHelper::factory(2, 'boolean'); |
|
49 | + } |
|
50 | + |
|
51 | + if (!\is_bool($checkForNonObjectIdentity)) { |
|
52 | + throw InvalidArgumentHelper::factory(3, 'boolean'); |
|
53 | + } |
|
54 | + |
|
55 | + $this->checkForObjectIdentity = $checkForObjectIdentity; |
|
56 | + $this->checkForNonObjectIdentity = $checkForNonObjectIdentity; |
|
57 | + $this->value = $value; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
62 | + * constraint is met, false otherwise. |
|
63 | + * |
|
64 | + * @param mixed $other Value or object to evaluate. |
|
65 | + * |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + protected function matches($other) |
|
69 | + { |
|
70 | + if ($other instanceof SplObjectStorage) { |
|
71 | + return $other->contains($this->value); |
|
72 | + } |
|
73 | + |
|
74 | + if (\is_object($this->value)) { |
|
75 | + foreach ($other as $element) { |
|
76 | + if ($this->checkForObjectIdentity && $element === $this->value) { |
|
77 | + return true; |
|
78 | + } |
|
79 | + |
|
80 | + if (!$this->checkForObjectIdentity && $element == $this->value) { |
|
81 | + return true; |
|
82 | + } |
|
83 | + } |
|
84 | + } else { |
|
85 | + foreach ($other as $element) { |
|
86 | + if ($this->checkForNonObjectIdentity && $element === $this->value) { |
|
87 | + return true; |
|
88 | + } |
|
89 | + |
|
90 | + if (!$this->checkForNonObjectIdentity && $element == $this->value) { |
|
91 | + return true; |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + return false; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns a string representation of the constraint. |
|
101 | + * |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public function toString() |
|
105 | + { |
|
106 | + if (\is_string($this->value) && \strpos($this->value, "\n") !== false) { |
|
107 | + return 'contains "' . $this->value . '"'; |
|
108 | + } |
|
109 | + |
|
110 | + return 'contains ' . $this->exporter->export($this->value); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Returns the description of the failure |
|
115 | + * |
|
116 | + * The beginning of failure messages is "Failed asserting that" in most |
|
117 | + * cases. This method should return the second part of that sentence. |
|
118 | + * |
|
119 | + * @param mixed $other Evaluated value or object. |
|
120 | + * |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + protected function failureDescription($other) |
|
124 | + { |
|
125 | + return \sprintf( |
|
126 | + '%s %s', |
|
127 | + \is_array($other) ? 'an array' : 'a traversable', |
|
128 | + $this->toString() |
|
129 | + ); |
|
130 | + } |
|
131 | 131 | } |
@@ -104,10 +104,10 @@ |
||
104 | 104 | public function toString() |
105 | 105 | { |
106 | 106 | if (\is_string($this->value) && \strpos($this->value, "\n") !== false) { |
107 | - return 'contains "' . $this->value . '"'; |
|
107 | + return 'contains "'.$this->value.'"'; |
|
108 | 108 | } |
109 | 109 | |
110 | - return 'contains ' . $this->exporter->export($this->value); |
|
110 | + return 'contains '.$this->exporter->export($this->value); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -14,26 +14,26 @@ |
||
14 | 14 | */ |
15 | 15 | class IsTrue extends Constraint |
16 | 16 | { |
17 | - /** |
|
18 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
19 | - * constraint is met, false otherwise. |
|
20 | - * |
|
21 | - * @param mixed $other Value or object to evaluate. |
|
22 | - * |
|
23 | - * @return bool |
|
24 | - */ |
|
25 | - protected function matches($other) |
|
26 | - { |
|
27 | - return $other === true; |
|
28 | - } |
|
17 | + /** |
|
18 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
19 | + * constraint is met, false otherwise. |
|
20 | + * |
|
21 | + * @param mixed $other Value or object to evaluate. |
|
22 | + * |
|
23 | + * @return bool |
|
24 | + */ |
|
25 | + protected function matches($other) |
|
26 | + { |
|
27 | + return $other === true; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Returns a string representation of the constraint. |
|
32 | - * |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function toString() |
|
36 | - { |
|
37 | - return 'is true'; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Returns a string representation of the constraint. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function toString() |
|
36 | + { |
|
37 | + return 'is true'; |
|
38 | + } |
|
39 | 39 | } |
@@ -16,46 +16,46 @@ |
||
16 | 16 | */ |
17 | 17 | class IsAnything extends Constraint |
18 | 18 | { |
19 | - /** |
|
20 | - * Evaluates the constraint for parameter $other |
|
21 | - * |
|
22 | - * If $returnResult is set to false (the default), an exception is thrown |
|
23 | - * in case of a failure. null is returned otherwise. |
|
24 | - * |
|
25 | - * If $returnResult is true, the result of the evaluation is returned as |
|
26 | - * a boolean value instead: true in case of success, false in case of a |
|
27 | - * failure. |
|
28 | - * |
|
29 | - * @param mixed $other Value or object to evaluate. |
|
30 | - * @param string $description Additional information about the test |
|
31 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
32 | - * |
|
33 | - * @return mixed |
|
34 | - * |
|
35 | - * @throws ExpectationFailedException |
|
36 | - */ |
|
37 | - public function evaluate($other, $description = '', $returnResult = false) |
|
38 | - { |
|
39 | - return $returnResult ? true : null; |
|
40 | - } |
|
19 | + /** |
|
20 | + * Evaluates the constraint for parameter $other |
|
21 | + * |
|
22 | + * If $returnResult is set to false (the default), an exception is thrown |
|
23 | + * in case of a failure. null is returned otherwise. |
|
24 | + * |
|
25 | + * If $returnResult is true, the result of the evaluation is returned as |
|
26 | + * a boolean value instead: true in case of success, false in case of a |
|
27 | + * failure. |
|
28 | + * |
|
29 | + * @param mixed $other Value or object to evaluate. |
|
30 | + * @param string $description Additional information about the test |
|
31 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
32 | + * |
|
33 | + * @return mixed |
|
34 | + * |
|
35 | + * @throws ExpectationFailedException |
|
36 | + */ |
|
37 | + public function evaluate($other, $description = '', $returnResult = false) |
|
38 | + { |
|
39 | + return $returnResult ? true : null; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Returns a string representation of the constraint. |
|
44 | - * |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function toString() |
|
48 | - { |
|
49 | - return 'is anything'; |
|
50 | - } |
|
42 | + /** |
|
43 | + * Returns a string representation of the constraint. |
|
44 | + * |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function toString() |
|
48 | + { |
|
49 | + return 'is anything'; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Counts the number of constraint elements. |
|
54 | - * |
|
55 | - * @return int |
|
56 | - */ |
|
57 | - public function count() |
|
58 | - { |
|
59 | - return 0; |
|
60 | - } |
|
52 | + /** |
|
53 | + * Counts the number of constraint elements. |
|
54 | + * |
|
55 | + * @return int |
|
56 | + */ |
|
57 | + public function count() |
|
58 | + { |
|
59 | + return 0; |
|
60 | + } |
|
61 | 61 | } |
@@ -11,16 +11,16 @@ |
||
11 | 11 | |
12 | 12 | class SameSize extends Count |
13 | 13 | { |
14 | - /** |
|
15 | - * @var int |
|
16 | - */ |
|
17 | - protected $expectedCount; |
|
14 | + /** |
|
15 | + * @var int |
|
16 | + */ |
|
17 | + protected $expectedCount; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param \Countable|\Traversable|array $expected |
|
21 | - */ |
|
22 | - public function __construct($expected) |
|
23 | - { |
|
24 | - parent::__construct($this->getCountOf($expected)); |
|
25 | - } |
|
19 | + /** |
|
20 | + * @param \Countable|\Traversable|array $expected |
|
21 | + */ |
|
22 | + public function __construct($expected) |
|
23 | + { |
|
24 | + parent::__construct($this->getCountOf($expected)); |
|
25 | + } |
|
26 | 26 | } |