@@ -18,272 +18,272 @@ |
||
18 | 18 | */ |
19 | 19 | class PHPUnit_Framework_MockObject_Builder_InvocationMocker implements PHPUnit_Framework_MockObject_Builder_MethodNameMatch |
20 | 20 | { |
21 | - /** |
|
22 | - * @var PHPUnit_Framework_MockObject_Stub_MatcherCollection |
|
23 | - */ |
|
24 | - protected $collection; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var PHPUnit_Framework_MockObject_Matcher |
|
28 | - */ |
|
29 | - protected $matcher; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string[] |
|
33 | - */ |
|
34 | - private $configurableMethods = []; |
|
35 | - |
|
36 | - /** |
|
37 | - * @param PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection |
|
38 | - * @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher |
|
39 | - * @param array $configurableMethods |
|
40 | - */ |
|
41 | - public function __construct(PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection, PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher, array $configurableMethods) |
|
42 | - { |
|
43 | - $this->collection = $collection; |
|
44 | - $this->matcher = new PHPUnit_Framework_MockObject_Matcher( |
|
45 | - $invocationMatcher |
|
46 | - ); |
|
47 | - |
|
48 | - $this->collection->addMatcher($this->matcher); |
|
49 | - |
|
50 | - $this->configurableMethods = $configurableMethods; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @return PHPUnit_Framework_MockObject_Matcher |
|
55 | - */ |
|
56 | - public function getMatcher() |
|
57 | - { |
|
58 | - return $this->matcher; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param mixed $id |
|
63 | - * |
|
64 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
65 | - */ |
|
66 | - public function id($id) |
|
67 | - { |
|
68 | - $this->collection->registerId($id, $this); |
|
69 | - |
|
70 | - return $this; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param PHPUnit_Framework_MockObject_Stub $stub |
|
75 | - * |
|
76 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
77 | - */ |
|
78 | - public function will(PHPUnit_Framework_MockObject_Stub $stub) |
|
79 | - { |
|
80 | - $this->matcher->stub = $stub; |
|
81 | - |
|
82 | - return $this; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param mixed $value |
|
87 | - * @param mixed $nextValues, ... |
|
88 | - * |
|
89 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
90 | - */ |
|
91 | - public function willReturn($value, ...$nextValues) |
|
92 | - { |
|
93 | - $stub = count($nextValues) === 0 ? |
|
94 | - new PHPUnit_Framework_MockObject_Stub_Return($value) : |
|
95 | - new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls( |
|
96 | - array_merge([$value], $nextValues) |
|
97 | - ); |
|
98 | - |
|
99 | - return $this->will($stub); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param mixed $reference |
|
104 | - * |
|
105 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
106 | - */ |
|
107 | - public function willReturnReference(&$reference) |
|
108 | - { |
|
109 | - $stub = new PHPUnit_Framework_MockObject_Stub_ReturnReference($reference); |
|
110 | - |
|
111 | - return $this->will($stub); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param array $valueMap |
|
116 | - * |
|
117 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
118 | - */ |
|
119 | - public function willReturnMap(array $valueMap) |
|
120 | - { |
|
121 | - $stub = new PHPUnit_Framework_MockObject_Stub_ReturnValueMap( |
|
122 | - $valueMap |
|
123 | - ); |
|
124 | - |
|
125 | - return $this->will($stub); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @param mixed $argumentIndex |
|
130 | - * |
|
131 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
132 | - */ |
|
133 | - public function willReturnArgument($argumentIndex) |
|
134 | - { |
|
135 | - $stub = new PHPUnit_Framework_MockObject_Stub_ReturnArgument( |
|
136 | - $argumentIndex |
|
137 | - ); |
|
138 | - |
|
139 | - return $this->will($stub); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @param callable $callback |
|
144 | - * |
|
145 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
146 | - */ |
|
147 | - public function willReturnCallback($callback) |
|
148 | - { |
|
149 | - $stub = new PHPUnit_Framework_MockObject_Stub_ReturnCallback( |
|
150 | - $callback |
|
151 | - ); |
|
152 | - |
|
153 | - return $this->will($stub); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
158 | - */ |
|
159 | - public function willReturnSelf() |
|
160 | - { |
|
161 | - $stub = new PHPUnit_Framework_MockObject_Stub_ReturnSelf; |
|
162 | - |
|
163 | - return $this->will($stub); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param mixed $values, ... |
|
168 | - * |
|
169 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
170 | - */ |
|
171 | - public function willReturnOnConsecutiveCalls(...$values) |
|
172 | - { |
|
173 | - $stub = new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($values); |
|
174 | - |
|
175 | - return $this->will($stub); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @param Exception $exception |
|
180 | - * |
|
181 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
182 | - */ |
|
183 | - public function willThrowException(Exception $exception) |
|
184 | - { |
|
185 | - $stub = new PHPUnit_Framework_MockObject_Stub_Exception($exception); |
|
186 | - |
|
187 | - return $this->will($stub); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @param mixed $id |
|
192 | - * |
|
193 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
194 | - */ |
|
195 | - public function after($id) |
|
196 | - { |
|
197 | - $this->matcher->afterMatchBuilderId = $id; |
|
198 | - |
|
199 | - return $this; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Validate that a parameters matcher can be defined, throw exceptions otherwise. |
|
204 | - * |
|
205 | - * @throws PHPUnit_Framework_MockObject_RuntimeException |
|
206 | - */ |
|
207 | - private function canDefineParameters() |
|
208 | - { |
|
209 | - if ($this->matcher->methodNameMatcher === null) { |
|
210 | - throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
211 | - 'Method name matcher is not defined, cannot define parameter ' . |
|
212 | - 'matcher without one' |
|
213 | - ); |
|
214 | - } |
|
215 | - |
|
216 | - if ($this->matcher->parametersMatcher !== null) { |
|
217 | - throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
218 | - 'Parameter matcher is already defined, cannot redefine' |
|
219 | - ); |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @param array ...$arguments |
|
225 | - * |
|
226 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
227 | - */ |
|
228 | - public function with(...$arguments) |
|
229 | - { |
|
230 | - $this->canDefineParameters(); |
|
231 | - |
|
232 | - $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_Parameters($arguments); |
|
233 | - |
|
234 | - return $this; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @param array ...$arguments |
|
239 | - * |
|
240 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
241 | - */ |
|
242 | - public function withConsecutive(...$arguments) |
|
243 | - { |
|
244 | - $this->canDefineParameters(); |
|
245 | - |
|
246 | - $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters($arguments); |
|
247 | - |
|
248 | - return $this; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
253 | - */ |
|
254 | - public function withAnyParameters() |
|
255 | - { |
|
256 | - $this->canDefineParameters(); |
|
257 | - |
|
258 | - $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters; |
|
259 | - |
|
260 | - return $this; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * @param PHPUnit_Framework_Constraint|string $constraint |
|
265 | - * |
|
266 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
267 | - */ |
|
268 | - public function method($constraint) |
|
269 | - { |
|
270 | - if ($this->matcher->methodNameMatcher !== null) { |
|
271 | - throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
272 | - 'Method name matcher is already defined, cannot redefine' |
|
273 | - ); |
|
274 | - } |
|
275 | - |
|
276 | - if (is_string($constraint) && !in_array(strtolower($constraint), $this->configurableMethods)) { |
|
277 | - throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
278 | - sprintf( |
|
279 | - 'Trying to configure method "%s" which cannot be configured because it does not exist, has not been specified, is final, or is static', |
|
280 | - $constraint |
|
281 | - ) |
|
282 | - ); |
|
283 | - } |
|
284 | - |
|
285 | - $this->matcher->methodNameMatcher = new PHPUnit_Framework_MockObject_Matcher_MethodName($constraint); |
|
286 | - |
|
287 | - return $this; |
|
288 | - } |
|
21 | + /** |
|
22 | + * @var PHPUnit_Framework_MockObject_Stub_MatcherCollection |
|
23 | + */ |
|
24 | + protected $collection; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var PHPUnit_Framework_MockObject_Matcher |
|
28 | + */ |
|
29 | + protected $matcher; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string[] |
|
33 | + */ |
|
34 | + private $configurableMethods = []; |
|
35 | + |
|
36 | + /** |
|
37 | + * @param PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection |
|
38 | + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher |
|
39 | + * @param array $configurableMethods |
|
40 | + */ |
|
41 | + public function __construct(PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection, PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher, array $configurableMethods) |
|
42 | + { |
|
43 | + $this->collection = $collection; |
|
44 | + $this->matcher = new PHPUnit_Framework_MockObject_Matcher( |
|
45 | + $invocationMatcher |
|
46 | + ); |
|
47 | + |
|
48 | + $this->collection->addMatcher($this->matcher); |
|
49 | + |
|
50 | + $this->configurableMethods = $configurableMethods; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @return PHPUnit_Framework_MockObject_Matcher |
|
55 | + */ |
|
56 | + public function getMatcher() |
|
57 | + { |
|
58 | + return $this->matcher; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param mixed $id |
|
63 | + * |
|
64 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
65 | + */ |
|
66 | + public function id($id) |
|
67 | + { |
|
68 | + $this->collection->registerId($id, $this); |
|
69 | + |
|
70 | + return $this; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param PHPUnit_Framework_MockObject_Stub $stub |
|
75 | + * |
|
76 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
77 | + */ |
|
78 | + public function will(PHPUnit_Framework_MockObject_Stub $stub) |
|
79 | + { |
|
80 | + $this->matcher->stub = $stub; |
|
81 | + |
|
82 | + return $this; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param mixed $value |
|
87 | + * @param mixed $nextValues, ... |
|
88 | + * |
|
89 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
90 | + */ |
|
91 | + public function willReturn($value, ...$nextValues) |
|
92 | + { |
|
93 | + $stub = count($nextValues) === 0 ? |
|
94 | + new PHPUnit_Framework_MockObject_Stub_Return($value) : |
|
95 | + new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls( |
|
96 | + array_merge([$value], $nextValues) |
|
97 | + ); |
|
98 | + |
|
99 | + return $this->will($stub); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param mixed $reference |
|
104 | + * |
|
105 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
106 | + */ |
|
107 | + public function willReturnReference(&$reference) |
|
108 | + { |
|
109 | + $stub = new PHPUnit_Framework_MockObject_Stub_ReturnReference($reference); |
|
110 | + |
|
111 | + return $this->will($stub); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param array $valueMap |
|
116 | + * |
|
117 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
118 | + */ |
|
119 | + public function willReturnMap(array $valueMap) |
|
120 | + { |
|
121 | + $stub = new PHPUnit_Framework_MockObject_Stub_ReturnValueMap( |
|
122 | + $valueMap |
|
123 | + ); |
|
124 | + |
|
125 | + return $this->will($stub); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @param mixed $argumentIndex |
|
130 | + * |
|
131 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
132 | + */ |
|
133 | + public function willReturnArgument($argumentIndex) |
|
134 | + { |
|
135 | + $stub = new PHPUnit_Framework_MockObject_Stub_ReturnArgument( |
|
136 | + $argumentIndex |
|
137 | + ); |
|
138 | + |
|
139 | + return $this->will($stub); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @param callable $callback |
|
144 | + * |
|
145 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
146 | + */ |
|
147 | + public function willReturnCallback($callback) |
|
148 | + { |
|
149 | + $stub = new PHPUnit_Framework_MockObject_Stub_ReturnCallback( |
|
150 | + $callback |
|
151 | + ); |
|
152 | + |
|
153 | + return $this->will($stub); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
158 | + */ |
|
159 | + public function willReturnSelf() |
|
160 | + { |
|
161 | + $stub = new PHPUnit_Framework_MockObject_Stub_ReturnSelf; |
|
162 | + |
|
163 | + return $this->will($stub); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param mixed $values, ... |
|
168 | + * |
|
169 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
170 | + */ |
|
171 | + public function willReturnOnConsecutiveCalls(...$values) |
|
172 | + { |
|
173 | + $stub = new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($values); |
|
174 | + |
|
175 | + return $this->will($stub); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @param Exception $exception |
|
180 | + * |
|
181 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
182 | + */ |
|
183 | + public function willThrowException(Exception $exception) |
|
184 | + { |
|
185 | + $stub = new PHPUnit_Framework_MockObject_Stub_Exception($exception); |
|
186 | + |
|
187 | + return $this->will($stub); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @param mixed $id |
|
192 | + * |
|
193 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
194 | + */ |
|
195 | + public function after($id) |
|
196 | + { |
|
197 | + $this->matcher->afterMatchBuilderId = $id; |
|
198 | + |
|
199 | + return $this; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Validate that a parameters matcher can be defined, throw exceptions otherwise. |
|
204 | + * |
|
205 | + * @throws PHPUnit_Framework_MockObject_RuntimeException |
|
206 | + */ |
|
207 | + private function canDefineParameters() |
|
208 | + { |
|
209 | + if ($this->matcher->methodNameMatcher === null) { |
|
210 | + throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
211 | + 'Method name matcher is not defined, cannot define parameter ' . |
|
212 | + 'matcher without one' |
|
213 | + ); |
|
214 | + } |
|
215 | + |
|
216 | + if ($this->matcher->parametersMatcher !== null) { |
|
217 | + throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
218 | + 'Parameter matcher is already defined, cannot redefine' |
|
219 | + ); |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @param array ...$arguments |
|
225 | + * |
|
226 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
227 | + */ |
|
228 | + public function with(...$arguments) |
|
229 | + { |
|
230 | + $this->canDefineParameters(); |
|
231 | + |
|
232 | + $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_Parameters($arguments); |
|
233 | + |
|
234 | + return $this; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @param array ...$arguments |
|
239 | + * |
|
240 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
241 | + */ |
|
242 | + public function withConsecutive(...$arguments) |
|
243 | + { |
|
244 | + $this->canDefineParameters(); |
|
245 | + |
|
246 | + $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters($arguments); |
|
247 | + |
|
248 | + return $this; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
253 | + */ |
|
254 | + public function withAnyParameters() |
|
255 | + { |
|
256 | + $this->canDefineParameters(); |
|
257 | + |
|
258 | + $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters; |
|
259 | + |
|
260 | + return $this; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * @param PHPUnit_Framework_Constraint|string $constraint |
|
265 | + * |
|
266 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
267 | + */ |
|
268 | + public function method($constraint) |
|
269 | + { |
|
270 | + if ($this->matcher->methodNameMatcher !== null) { |
|
271 | + throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
272 | + 'Method name matcher is already defined, cannot redefine' |
|
273 | + ); |
|
274 | + } |
|
275 | + |
|
276 | + if (is_string($constraint) && !in_array(strtolower($constraint), $this->configurableMethods)) { |
|
277 | + throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
278 | + sprintf( |
|
279 | + 'Trying to configure method "%s" which cannot be configured because it does not exist, has not been specified, is final, or is static', |
|
280 | + $constraint |
|
281 | + ) |
|
282 | + ); |
|
283 | + } |
|
284 | + |
|
285 | + $this->matcher->methodNameMatcher = new PHPUnit_Framework_MockObject_Matcher_MethodName($constraint); |
|
286 | + |
|
287 | + return $this; |
|
288 | + } |
|
289 | 289 | } |
@@ -13,35 +13,35 @@ |
||
13 | 13 | */ |
14 | 14 | interface PHPUnit_Framework_MockObject_Builder_ParametersMatch extends PHPUnit_Framework_MockObject_Builder_Match |
15 | 15 | { |
16 | - /** |
|
17 | - * Sets the parameters to match for, each parameter to this function will |
|
18 | - * be part of match. To perform specific matches or constraints create a |
|
19 | - * new PHPUnit_Framework_Constraint and use it for the parameter. |
|
20 | - * If the parameter value is not a constraint it will use the |
|
21 | - * PHPUnit_Framework_Constraint_IsEqual for the value. |
|
22 | - * |
|
23 | - * Some examples: |
|
24 | - * <code> |
|
25 | - * // match first parameter with value 2 |
|
26 | - * $b->with(2); |
|
27 | - * // match first parameter with value 'smock' and second identical to 42 |
|
28 | - * $b->with('smock', new PHPUnit_Framework_Constraint_IsEqual(42)); |
|
29 | - * </code> |
|
30 | - * |
|
31 | - * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch |
|
32 | - */ |
|
33 | - public function with(...$arguments); |
|
16 | + /** |
|
17 | + * Sets the parameters to match for, each parameter to this function will |
|
18 | + * be part of match. To perform specific matches or constraints create a |
|
19 | + * new PHPUnit_Framework_Constraint and use it for the parameter. |
|
20 | + * If the parameter value is not a constraint it will use the |
|
21 | + * PHPUnit_Framework_Constraint_IsEqual for the value. |
|
22 | + * |
|
23 | + * Some examples: |
|
24 | + * <code> |
|
25 | + * // match first parameter with value 2 |
|
26 | + * $b->with(2); |
|
27 | + * // match first parameter with value 'smock' and second identical to 42 |
|
28 | + * $b->with('smock', new PHPUnit_Framework_Constraint_IsEqual(42)); |
|
29 | + * </code> |
|
30 | + * |
|
31 | + * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch |
|
32 | + */ |
|
33 | + public function with(...$arguments); |
|
34 | 34 | |
35 | - /** |
|
36 | - * Sets a matcher which allows any kind of parameters. |
|
37 | - * |
|
38 | - * Some examples: |
|
39 | - * <code> |
|
40 | - * // match any number of parameters |
|
41 | - * $b->withAnyParameters(); |
|
42 | - * </code> |
|
43 | - * |
|
44 | - * @return PHPUnit_Framework_MockObject_Matcher_AnyParameters |
|
45 | - */ |
|
46 | - public function withAnyParameters(); |
|
35 | + /** |
|
36 | + * Sets a matcher which allows any kind of parameters. |
|
37 | + * |
|
38 | + * Some examples: |
|
39 | + * <code> |
|
40 | + * // match any number of parameters |
|
41 | + * $b->withAnyParameters(); |
|
42 | + * </code> |
|
43 | + * |
|
44 | + * @return PHPUnit_Framework_MockObject_Matcher_AnyParameters |
|
45 | + */ |
|
46 | + public function withAnyParameters(); |
|
47 | 47 | } |
@@ -13,13 +13,13 @@ |
||
13 | 13 | */ |
14 | 14 | interface PHPUnit_Framework_MockObject_Builder_MethodNameMatch extends PHPUnit_Framework_MockObject_Builder_ParametersMatch |
15 | 15 | { |
16 | - /** |
|
17 | - * Adds a new method name match and returns the parameter match object for |
|
18 | - * further matching possibilities. |
|
19 | - * |
|
20 | - * @param PHPUnit_Framework_Constraint $name Constraint for matching method, if a string is passed it will use the PHPUnit_Framework_Constraint_IsEqual |
|
21 | - * |
|
22 | - * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch |
|
23 | - */ |
|
24 | - public function method($name); |
|
16 | + /** |
|
17 | + * Adds a new method name match and returns the parameter match object for |
|
18 | + * further matching possibilities. |
|
19 | + * |
|
20 | + * @param PHPUnit_Framework_Constraint $name Constraint for matching method, if a string is passed it will use the PHPUnit_Framework_Constraint_IsEqual |
|
21 | + * |
|
22 | + * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch |
|
23 | + */ |
|
24 | + public function method($name); |
|
25 | 25 | } |
@@ -15,22 +15,22 @@ |
||
15 | 15 | */ |
16 | 16 | interface PHPUnit_Framework_MockObject_Builder_Namespace |
17 | 17 | { |
18 | - /** |
|
19 | - * Looks up the match builder with identification $id and returns it. |
|
20 | - * |
|
21 | - * @param string $id The identification of the match builder |
|
22 | - * |
|
23 | - * @return PHPUnit_Framework_MockObject_Builder_Match |
|
24 | - */ |
|
25 | - public function lookupId($id); |
|
18 | + /** |
|
19 | + * Looks up the match builder with identification $id and returns it. |
|
20 | + * |
|
21 | + * @param string $id The identification of the match builder |
|
22 | + * |
|
23 | + * @return PHPUnit_Framework_MockObject_Builder_Match |
|
24 | + */ |
|
25 | + public function lookupId($id); |
|
26 | 26 | |
27 | - /** |
|
28 | - * Registers the match builder $builder with the identification $id. The |
|
29 | - * builder can later be looked up using lookupId() to figure out if it |
|
30 | - * has been invoked. |
|
31 | - * |
|
32 | - * @param string $id The identification of the match builder |
|
33 | - * @param PHPUnit_Framework_MockObject_Builder_Match $builder The builder which is being registered |
|
34 | - */ |
|
35 | - public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder); |
|
27 | + /** |
|
28 | + * Registers the match builder $builder with the identification $id. The |
|
29 | + * builder can later be looked up using lookupId() to figure out if it |
|
30 | + * has been invoked. |
|
31 | + * |
|
32 | + * @param string $id The identification of the match builder |
|
33 | + * @param PHPUnit_Framework_MockObject_Builder_Match $builder The builder which is being registered |
|
34 | + */ |
|
35 | + public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder); |
|
36 | 36 | } |
@@ -18,12 +18,12 @@ |
||
18 | 18 | */ |
19 | 19 | interface PHPUnit_Framework_MockObject_Builder_Identity |
20 | 20 | { |
21 | - /** |
|
22 | - * Sets the identification of the expectation to $id. |
|
23 | - * |
|
24 | - * @note The identifier is unique per mock object. |
|
25 | - * |
|
26 | - * @param string $id Unique identification of expectation. |
|
27 | - */ |
|
28 | - public function id($id); |
|
21 | + /** |
|
22 | + * Sets the identification of the expectation to $id. |
|
23 | + * |
|
24 | + * @note The identifier is unique per mock object. |
|
25 | + * |
|
26 | + * @param string $id Unique identification of expectation. |
|
27 | + */ |
|
28 | + public function id($id); |
|
29 | 29 | } |
@@ -13,13 +13,13 @@ |
||
13 | 13 | */ |
14 | 14 | interface PHPUnit_Framework_MockObject_Builder_Match extends PHPUnit_Framework_MockObject_Builder_Stub |
15 | 15 | { |
16 | - /** |
|
17 | - * Defines the expectation which must occur before the current is valid. |
|
18 | - * |
|
19 | - * @param string $id The identification of the expectation that should |
|
20 | - * occur before this one. |
|
21 | - * |
|
22 | - * @return PHPUnit_Framework_MockObject_Builder_Stub |
|
23 | - */ |
|
24 | - public function after($id); |
|
16 | + /** |
|
17 | + * Defines the expectation which must occur before the current is valid. |
|
18 | + * |
|
19 | + * @param string $id The identification of the expectation that should |
|
20 | + * occur before this one. |
|
21 | + * |
|
22 | + * @return PHPUnit_Framework_MockObject_Builder_Stub |
|
23 | + */ |
|
24 | + public function after($id); |
|
25 | 25 | } |
@@ -13,8 +13,8 @@ |
||
13 | 13 | */ |
14 | 14 | interface PHPUnit_Framework_MockObject_Invocation |
15 | 15 | { |
16 | - /** |
|
17 | - * @return mixed Mocked return value. |
|
18 | - */ |
|
19 | - public function generateReturnValue(); |
|
16 | + /** |
|
17 | + * @return mixed Mocked return value. |
|
18 | + */ |
|
19 | + public function generateReturnValue(); |
|
20 | 20 | } |
@@ -18,36 +18,36 @@ |
||
18 | 18 | */ |
19 | 19 | interface PHPUnit_Framework_MockObject_MockObject /*extends PHPUnit_Framework_MockObject_Verifiable*/ |
20 | 20 | { |
21 | - /** |
|
22 | - * Registers a new expectation in the mock object and returns the match |
|
23 | - * object which can be infused with further details. |
|
24 | - * |
|
25 | - * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher |
|
26 | - * |
|
27 | - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
28 | - */ |
|
29 | - public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher); |
|
21 | + /** |
|
22 | + * Registers a new expectation in the mock object and returns the match |
|
23 | + * object which can be infused with further details. |
|
24 | + * |
|
25 | + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher |
|
26 | + * |
|
27 | + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker |
|
28 | + */ |
|
29 | + public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher); |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return PHPUnit_Framework_MockObject_InvocationMocker |
|
33 | - */ |
|
34 | - public function __phpunit_setOriginalObject($originalObject); |
|
31 | + /** |
|
32 | + * @return PHPUnit_Framework_MockObject_InvocationMocker |
|
33 | + */ |
|
34 | + public function __phpunit_setOriginalObject($originalObject); |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return PHPUnit_Framework_MockObject_InvocationMocker |
|
38 | - */ |
|
39 | - public function __phpunit_getInvocationMocker(); |
|
36 | + /** |
|
37 | + * @return PHPUnit_Framework_MockObject_InvocationMocker |
|
38 | + */ |
|
39 | + public function __phpunit_getInvocationMocker(); |
|
40 | 40 | |
41 | - /** |
|
42 | - * Verifies that the current expectation is valid. If everything is OK the |
|
43 | - * code should just return, if not it must throw an exception. |
|
44 | - * |
|
45 | - * @throws ExpectationFailedException |
|
46 | - */ |
|
47 | - public function __phpunit_verify(); |
|
41 | + /** |
|
42 | + * Verifies that the current expectation is valid. If everything is OK the |
|
43 | + * code should just return, if not it must throw an exception. |
|
44 | + * |
|
45 | + * @throws ExpectationFailedException |
|
46 | + */ |
|
47 | + public function __phpunit_verify(); |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return bool |
|
51 | - */ |
|
52 | - public function __phpunit_hasMatchers(); |
|
49 | + /** |
|
50 | + * @return bool |
|
51 | + */ |
|
52 | + public function __phpunit_hasMatchers(); |
|
53 | 53 | } |
@@ -19,325 +19,325 @@ |
||
19 | 19 | */ |
20 | 20 | abstract class TestCase extends \PHPUnit\Framework\TestCase |
21 | 21 | { |
22 | - protected static $TEST_TMP_PATH; |
|
23 | - |
|
24 | - public static function setUpBeforeClass() |
|
25 | - { |
|
26 | - self::$TEST_TMP_PATH = TEST_FILES_PATH . 'tmp'; |
|
27 | - } |
|
28 | - |
|
29 | - protected function getXdebugDataForBankAccount() |
|
30 | - { |
|
31 | - return [ |
|
32 | - [ |
|
33 | - TEST_FILES_PATH . 'BankAccount.php' => [ |
|
34 | - 8 => 1, |
|
35 | - 9 => -2, |
|
36 | - 13 => -1, |
|
37 | - 14 => -1, |
|
38 | - 15 => -1, |
|
39 | - 16 => -1, |
|
40 | - 18 => -1, |
|
41 | - 22 => -1, |
|
42 | - 24 => -1, |
|
43 | - 25 => -2, |
|
44 | - 29 => -1, |
|
45 | - 31 => -1, |
|
46 | - 32 => -2 |
|
47 | - ] |
|
48 | - ], |
|
49 | - [ |
|
50 | - TEST_FILES_PATH . 'BankAccount.php' => [ |
|
51 | - 8 => 1, |
|
52 | - 13 => 1, |
|
53 | - 16 => 1, |
|
54 | - 29 => 1, |
|
55 | - ] |
|
56 | - ], |
|
57 | - [ |
|
58 | - TEST_FILES_PATH . 'BankAccount.php' => [ |
|
59 | - 8 => 1, |
|
60 | - 13 => 1, |
|
61 | - 16 => 1, |
|
62 | - 22 => 1, |
|
63 | - ] |
|
64 | - ], |
|
65 | - [ |
|
66 | - TEST_FILES_PATH . 'BankAccount.php' => [ |
|
67 | - 8 => 1, |
|
68 | - 13 => 1, |
|
69 | - 14 => 1, |
|
70 | - 15 => 1, |
|
71 | - 18 => 1, |
|
72 | - 22 => 1, |
|
73 | - 24 => 1, |
|
74 | - 29 => 1, |
|
75 | - 31 => 1, |
|
76 | - ] |
|
77 | - ] |
|
78 | - ]; |
|
79 | - } |
|
80 | - |
|
81 | - protected function getCoverageForBankAccount() |
|
82 | - { |
|
83 | - $data = $this->getXdebugDataForBankAccount(); |
|
84 | - require_once TEST_FILES_PATH . '/BankAccountTest.php'; |
|
85 | - |
|
86 | - $stub = $this->createMock(Xdebug::class); |
|
87 | - |
|
88 | - $stub->expects($this->any()) |
|
89 | - ->method('stop') |
|
90 | - ->will($this->onConsecutiveCalls( |
|
91 | - $data[0], |
|
92 | - $data[1], |
|
93 | - $data[2], |
|
94 | - $data[3] |
|
95 | - )); |
|
96 | - |
|
97 | - $filter = new Filter; |
|
98 | - $filter->addFileToWhitelist(TEST_FILES_PATH . 'BankAccount.php'); |
|
99 | - |
|
100 | - $coverage = new CodeCoverage($stub, $filter); |
|
101 | - |
|
102 | - $coverage->start( |
|
103 | - new \BankAccountTest('testBalanceIsInitiallyZero'), |
|
104 | - true |
|
105 | - ); |
|
106 | - |
|
107 | - $coverage->stop( |
|
108 | - true, |
|
109 | - [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)] |
|
110 | - ); |
|
111 | - |
|
112 | - $coverage->start( |
|
113 | - new \BankAccountTest('testBalanceCannotBecomeNegative') |
|
114 | - ); |
|
115 | - |
|
116 | - $coverage->stop( |
|
117 | - true, |
|
118 | - [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)] |
|
119 | - ); |
|
120 | - |
|
121 | - $coverage->start( |
|
122 | - new \BankAccountTest('testBalanceCannotBecomeNegative2') |
|
123 | - ); |
|
124 | - |
|
125 | - $coverage->stop( |
|
126 | - true, |
|
127 | - [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)] |
|
128 | - ); |
|
129 | - |
|
130 | - $coverage->start( |
|
131 | - new \BankAccountTest('testDepositWithdrawMoney') |
|
132 | - ); |
|
133 | - |
|
134 | - $coverage->stop( |
|
135 | - true, |
|
136 | - [ |
|
137 | - TEST_FILES_PATH . 'BankAccount.php' => array_merge( |
|
138 | - range(6, 9), |
|
139 | - range(20, 25), |
|
140 | - range(27, 32) |
|
141 | - ) |
|
142 | - ] |
|
143 | - ); |
|
144 | - |
|
145 | - return $coverage; |
|
146 | - } |
|
147 | - |
|
148 | - protected function getCoverageForBankAccountForFirstTwoTests() |
|
149 | - { |
|
150 | - $data = $this->getXdebugDataForBankAccount(); |
|
151 | - |
|
152 | - $stub = $this->createMock(Xdebug::class); |
|
153 | - |
|
154 | - $stub->expects($this->any()) |
|
155 | - ->method('stop') |
|
156 | - ->will($this->onConsecutiveCalls( |
|
157 | - $data[0], |
|
158 | - $data[1] |
|
159 | - )); |
|
160 | - |
|
161 | - $filter = new Filter; |
|
162 | - $filter->addFileToWhitelist(TEST_FILES_PATH . 'BankAccount.php'); |
|
163 | - |
|
164 | - $coverage = new CodeCoverage($stub, $filter); |
|
165 | - |
|
166 | - $coverage->start( |
|
167 | - new \BankAccountTest('testBalanceIsInitiallyZero'), |
|
168 | - true |
|
169 | - ); |
|
170 | - |
|
171 | - $coverage->stop( |
|
172 | - true, |
|
173 | - [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)] |
|
174 | - ); |
|
175 | - |
|
176 | - $coverage->start( |
|
177 | - new \BankAccountTest('testBalanceCannotBecomeNegative') |
|
178 | - ); |
|
179 | - |
|
180 | - $coverage->stop( |
|
181 | - true, |
|
182 | - [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)] |
|
183 | - ); |
|
184 | - |
|
185 | - return $coverage; |
|
186 | - } |
|
187 | - |
|
188 | - protected function getCoverageForBankAccountForLastTwoTests() |
|
189 | - { |
|
190 | - $data = $this->getXdebugDataForBankAccount(); |
|
191 | - |
|
192 | - $stub = $this->createMock(Xdebug::class); |
|
193 | - |
|
194 | - $stub->expects($this->any()) |
|
195 | - ->method('stop') |
|
196 | - ->will($this->onConsecutiveCalls( |
|
197 | - $data[2], |
|
198 | - $data[3] |
|
199 | - )); |
|
200 | - |
|
201 | - $filter = new Filter; |
|
202 | - $filter->addFileToWhitelist(TEST_FILES_PATH . 'BankAccount.php'); |
|
203 | - |
|
204 | - $coverage = new CodeCoverage($stub, $filter); |
|
205 | - |
|
206 | - $coverage->start( |
|
207 | - new \BankAccountTest('testBalanceCannotBecomeNegative2') |
|
208 | - ); |
|
209 | - |
|
210 | - $coverage->stop( |
|
211 | - true, |
|
212 | - [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)] |
|
213 | - ); |
|
214 | - |
|
215 | - $coverage->start( |
|
216 | - new \BankAccountTest('testDepositWithdrawMoney') |
|
217 | - ); |
|
218 | - |
|
219 | - $coverage->stop( |
|
220 | - true, |
|
221 | - [ |
|
222 | - TEST_FILES_PATH . 'BankAccount.php' => array_merge( |
|
223 | - range(6, 9), |
|
224 | - range(20, 25), |
|
225 | - range(27, 32) |
|
226 | - ) |
|
227 | - ] |
|
228 | - ); |
|
229 | - |
|
230 | - return $coverage; |
|
231 | - } |
|
232 | - |
|
233 | - protected function getExpectedDataArrayForBankAccount() |
|
234 | - { |
|
235 | - return [ |
|
236 | - TEST_FILES_PATH . 'BankAccount.php' => [ |
|
237 | - 8 => [ |
|
238 | - 0 => 'BankAccountTest::testBalanceIsInitiallyZero', |
|
239 | - 1 => 'BankAccountTest::testDepositWithdrawMoney' |
|
240 | - ], |
|
241 | - 9 => null, |
|
242 | - 13 => [], |
|
243 | - 14 => [], |
|
244 | - 15 => [], |
|
245 | - 16 => [], |
|
246 | - 18 => [], |
|
247 | - 22 => [ |
|
248 | - 0 => 'BankAccountTest::testBalanceCannotBecomeNegative2', |
|
249 | - 1 => 'BankAccountTest::testDepositWithdrawMoney' |
|
250 | - ], |
|
251 | - 24 => [ |
|
252 | - 0 => 'BankAccountTest::testDepositWithdrawMoney', |
|
253 | - ], |
|
254 | - 25 => null, |
|
255 | - 29 => [ |
|
256 | - 0 => 'BankAccountTest::testBalanceCannotBecomeNegative', |
|
257 | - 1 => 'BankAccountTest::testDepositWithdrawMoney' |
|
258 | - ], |
|
259 | - 31 => [ |
|
260 | - 0 => 'BankAccountTest::testDepositWithdrawMoney' |
|
261 | - ], |
|
262 | - 32 => null |
|
263 | - ] |
|
264 | - ]; |
|
265 | - } |
|
266 | - |
|
267 | - protected function getCoverageForFileWithIgnoredLines() |
|
268 | - { |
|
269 | - $filter = new Filter; |
|
270 | - $filter->addFileToWhitelist(TEST_FILES_PATH . 'source_with_ignore.php'); |
|
271 | - |
|
272 | - $coverage = new CodeCoverage( |
|
273 | - $this->setUpXdebugStubForFileWithIgnoredLines(), |
|
274 | - $filter |
|
275 | - ); |
|
276 | - |
|
277 | - $coverage->start('FileWithIgnoredLines', true); |
|
278 | - $coverage->stop(); |
|
279 | - |
|
280 | - return $coverage; |
|
281 | - } |
|
282 | - |
|
283 | - protected function setUpXdebugStubForFileWithIgnoredLines() |
|
284 | - { |
|
285 | - $stub = $this->createMock(Xdebug::class); |
|
286 | - |
|
287 | - $stub->expects($this->any()) |
|
288 | - ->method('stop') |
|
289 | - ->will($this->returnValue( |
|
290 | - [ |
|
291 | - TEST_FILES_PATH . 'source_with_ignore.php' => [ |
|
292 | - 2 => 1, |
|
293 | - 4 => -1, |
|
294 | - 6 => -1, |
|
295 | - 7 => 1 |
|
296 | - ] |
|
297 | - ] |
|
298 | - )); |
|
299 | - |
|
300 | - return $stub; |
|
301 | - } |
|
302 | - |
|
303 | - protected function getCoverageForClassWithAnonymousFunction() |
|
304 | - { |
|
305 | - $filter = new Filter; |
|
306 | - $filter->addFileToWhitelist(TEST_FILES_PATH . 'source_with_class_and_anonymous_function.php'); |
|
307 | - |
|
308 | - $coverage = new CodeCoverage( |
|
309 | - $this->setUpXdebugStubForClassWithAnonymousFunction(), |
|
310 | - $filter |
|
311 | - ); |
|
312 | - |
|
313 | - $coverage->start('ClassWithAnonymousFunction', true); |
|
314 | - $coverage->stop(); |
|
315 | - |
|
316 | - return $coverage; |
|
317 | - } |
|
318 | - |
|
319 | - protected function setUpXdebugStubForClassWithAnonymousFunction() |
|
320 | - { |
|
321 | - $stub = $this->createMock(Xdebug::class); |
|
322 | - |
|
323 | - $stub->expects($this->any()) |
|
324 | - ->method('stop') |
|
325 | - ->will($this->returnValue( |
|
326 | - [ |
|
327 | - TEST_FILES_PATH . 'source_with_class_and_anonymous_function.php' => [ |
|
328 | - 7 => 1, |
|
329 | - 9 => 1, |
|
330 | - 10 => -1, |
|
331 | - 11 => 1, |
|
332 | - 12 => 1, |
|
333 | - 13 => 1, |
|
334 | - 14 => 1, |
|
335 | - 17 => 1, |
|
336 | - 18 => 1 |
|
337 | - ] |
|
338 | - ] |
|
339 | - )); |
|
340 | - |
|
341 | - return $stub; |
|
342 | - } |
|
22 | + protected static $TEST_TMP_PATH; |
|
23 | + |
|
24 | + public static function setUpBeforeClass() |
|
25 | + { |
|
26 | + self::$TEST_TMP_PATH = TEST_FILES_PATH . 'tmp'; |
|
27 | + } |
|
28 | + |
|
29 | + protected function getXdebugDataForBankAccount() |
|
30 | + { |
|
31 | + return [ |
|
32 | + [ |
|
33 | + TEST_FILES_PATH . 'BankAccount.php' => [ |
|
34 | + 8 => 1, |
|
35 | + 9 => -2, |
|
36 | + 13 => -1, |
|
37 | + 14 => -1, |
|
38 | + 15 => -1, |
|
39 | + 16 => -1, |
|
40 | + 18 => -1, |
|
41 | + 22 => -1, |
|
42 | + 24 => -1, |
|
43 | + 25 => -2, |
|
44 | + 29 => -1, |
|
45 | + 31 => -1, |
|
46 | + 32 => -2 |
|
47 | + ] |
|
48 | + ], |
|
49 | + [ |
|
50 | + TEST_FILES_PATH . 'BankAccount.php' => [ |
|
51 | + 8 => 1, |
|
52 | + 13 => 1, |
|
53 | + 16 => 1, |
|
54 | + 29 => 1, |
|
55 | + ] |
|
56 | + ], |
|
57 | + [ |
|
58 | + TEST_FILES_PATH . 'BankAccount.php' => [ |
|
59 | + 8 => 1, |
|
60 | + 13 => 1, |
|
61 | + 16 => 1, |
|
62 | + 22 => 1, |
|
63 | + ] |
|
64 | + ], |
|
65 | + [ |
|
66 | + TEST_FILES_PATH . 'BankAccount.php' => [ |
|
67 | + 8 => 1, |
|
68 | + 13 => 1, |
|
69 | + 14 => 1, |
|
70 | + 15 => 1, |
|
71 | + 18 => 1, |
|
72 | + 22 => 1, |
|
73 | + 24 => 1, |
|
74 | + 29 => 1, |
|
75 | + 31 => 1, |
|
76 | + ] |
|
77 | + ] |
|
78 | + ]; |
|
79 | + } |
|
80 | + |
|
81 | + protected function getCoverageForBankAccount() |
|
82 | + { |
|
83 | + $data = $this->getXdebugDataForBankAccount(); |
|
84 | + require_once TEST_FILES_PATH . '/BankAccountTest.php'; |
|
85 | + |
|
86 | + $stub = $this->createMock(Xdebug::class); |
|
87 | + |
|
88 | + $stub->expects($this->any()) |
|
89 | + ->method('stop') |
|
90 | + ->will($this->onConsecutiveCalls( |
|
91 | + $data[0], |
|
92 | + $data[1], |
|
93 | + $data[2], |
|
94 | + $data[3] |
|
95 | + )); |
|
96 | + |
|
97 | + $filter = new Filter; |
|
98 | + $filter->addFileToWhitelist(TEST_FILES_PATH . 'BankAccount.php'); |
|
99 | + |
|
100 | + $coverage = new CodeCoverage($stub, $filter); |
|
101 | + |
|
102 | + $coverage->start( |
|
103 | + new \BankAccountTest('testBalanceIsInitiallyZero'), |
|
104 | + true |
|
105 | + ); |
|
106 | + |
|
107 | + $coverage->stop( |
|
108 | + true, |
|
109 | + [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)] |
|
110 | + ); |
|
111 | + |
|
112 | + $coverage->start( |
|
113 | + new \BankAccountTest('testBalanceCannotBecomeNegative') |
|
114 | + ); |
|
115 | + |
|
116 | + $coverage->stop( |
|
117 | + true, |
|
118 | + [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)] |
|
119 | + ); |
|
120 | + |
|
121 | + $coverage->start( |
|
122 | + new \BankAccountTest('testBalanceCannotBecomeNegative2') |
|
123 | + ); |
|
124 | + |
|
125 | + $coverage->stop( |
|
126 | + true, |
|
127 | + [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)] |
|
128 | + ); |
|
129 | + |
|
130 | + $coverage->start( |
|
131 | + new \BankAccountTest('testDepositWithdrawMoney') |
|
132 | + ); |
|
133 | + |
|
134 | + $coverage->stop( |
|
135 | + true, |
|
136 | + [ |
|
137 | + TEST_FILES_PATH . 'BankAccount.php' => array_merge( |
|
138 | + range(6, 9), |
|
139 | + range(20, 25), |
|
140 | + range(27, 32) |
|
141 | + ) |
|
142 | + ] |
|
143 | + ); |
|
144 | + |
|
145 | + return $coverage; |
|
146 | + } |
|
147 | + |
|
148 | + protected function getCoverageForBankAccountForFirstTwoTests() |
|
149 | + { |
|
150 | + $data = $this->getXdebugDataForBankAccount(); |
|
151 | + |
|
152 | + $stub = $this->createMock(Xdebug::class); |
|
153 | + |
|
154 | + $stub->expects($this->any()) |
|
155 | + ->method('stop') |
|
156 | + ->will($this->onConsecutiveCalls( |
|
157 | + $data[0], |
|
158 | + $data[1] |
|
159 | + )); |
|
160 | + |
|
161 | + $filter = new Filter; |
|
162 | + $filter->addFileToWhitelist(TEST_FILES_PATH . 'BankAccount.php'); |
|
163 | + |
|
164 | + $coverage = new CodeCoverage($stub, $filter); |
|
165 | + |
|
166 | + $coverage->start( |
|
167 | + new \BankAccountTest('testBalanceIsInitiallyZero'), |
|
168 | + true |
|
169 | + ); |
|
170 | + |
|
171 | + $coverage->stop( |
|
172 | + true, |
|
173 | + [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)] |
|
174 | + ); |
|
175 | + |
|
176 | + $coverage->start( |
|
177 | + new \BankAccountTest('testBalanceCannotBecomeNegative') |
|
178 | + ); |
|
179 | + |
|
180 | + $coverage->stop( |
|
181 | + true, |
|
182 | + [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)] |
|
183 | + ); |
|
184 | + |
|
185 | + return $coverage; |
|
186 | + } |
|
187 | + |
|
188 | + protected function getCoverageForBankAccountForLastTwoTests() |
|
189 | + { |
|
190 | + $data = $this->getXdebugDataForBankAccount(); |
|
191 | + |
|
192 | + $stub = $this->createMock(Xdebug::class); |
|
193 | + |
|
194 | + $stub->expects($this->any()) |
|
195 | + ->method('stop') |
|
196 | + ->will($this->onConsecutiveCalls( |
|
197 | + $data[2], |
|
198 | + $data[3] |
|
199 | + )); |
|
200 | + |
|
201 | + $filter = new Filter; |
|
202 | + $filter->addFileToWhitelist(TEST_FILES_PATH . 'BankAccount.php'); |
|
203 | + |
|
204 | + $coverage = new CodeCoverage($stub, $filter); |
|
205 | + |
|
206 | + $coverage->start( |
|
207 | + new \BankAccountTest('testBalanceCannotBecomeNegative2') |
|
208 | + ); |
|
209 | + |
|
210 | + $coverage->stop( |
|
211 | + true, |
|
212 | + [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)] |
|
213 | + ); |
|
214 | + |
|
215 | + $coverage->start( |
|
216 | + new \BankAccountTest('testDepositWithdrawMoney') |
|
217 | + ); |
|
218 | + |
|
219 | + $coverage->stop( |
|
220 | + true, |
|
221 | + [ |
|
222 | + TEST_FILES_PATH . 'BankAccount.php' => array_merge( |
|
223 | + range(6, 9), |
|
224 | + range(20, 25), |
|
225 | + range(27, 32) |
|
226 | + ) |
|
227 | + ] |
|
228 | + ); |
|
229 | + |
|
230 | + return $coverage; |
|
231 | + } |
|
232 | + |
|
233 | + protected function getExpectedDataArrayForBankAccount() |
|
234 | + { |
|
235 | + return [ |
|
236 | + TEST_FILES_PATH . 'BankAccount.php' => [ |
|
237 | + 8 => [ |
|
238 | + 0 => 'BankAccountTest::testBalanceIsInitiallyZero', |
|
239 | + 1 => 'BankAccountTest::testDepositWithdrawMoney' |
|
240 | + ], |
|
241 | + 9 => null, |
|
242 | + 13 => [], |
|
243 | + 14 => [], |
|
244 | + 15 => [], |
|
245 | + 16 => [], |
|
246 | + 18 => [], |
|
247 | + 22 => [ |
|
248 | + 0 => 'BankAccountTest::testBalanceCannotBecomeNegative2', |
|
249 | + 1 => 'BankAccountTest::testDepositWithdrawMoney' |
|
250 | + ], |
|
251 | + 24 => [ |
|
252 | + 0 => 'BankAccountTest::testDepositWithdrawMoney', |
|
253 | + ], |
|
254 | + 25 => null, |
|
255 | + 29 => [ |
|
256 | + 0 => 'BankAccountTest::testBalanceCannotBecomeNegative', |
|
257 | + 1 => 'BankAccountTest::testDepositWithdrawMoney' |
|
258 | + ], |
|
259 | + 31 => [ |
|
260 | + 0 => 'BankAccountTest::testDepositWithdrawMoney' |
|
261 | + ], |
|
262 | + 32 => null |
|
263 | + ] |
|
264 | + ]; |
|
265 | + } |
|
266 | + |
|
267 | + protected function getCoverageForFileWithIgnoredLines() |
|
268 | + { |
|
269 | + $filter = new Filter; |
|
270 | + $filter->addFileToWhitelist(TEST_FILES_PATH . 'source_with_ignore.php'); |
|
271 | + |
|
272 | + $coverage = new CodeCoverage( |
|
273 | + $this->setUpXdebugStubForFileWithIgnoredLines(), |
|
274 | + $filter |
|
275 | + ); |
|
276 | + |
|
277 | + $coverage->start('FileWithIgnoredLines', true); |
|
278 | + $coverage->stop(); |
|
279 | + |
|
280 | + return $coverage; |
|
281 | + } |
|
282 | + |
|
283 | + protected function setUpXdebugStubForFileWithIgnoredLines() |
|
284 | + { |
|
285 | + $stub = $this->createMock(Xdebug::class); |
|
286 | + |
|
287 | + $stub->expects($this->any()) |
|
288 | + ->method('stop') |
|
289 | + ->will($this->returnValue( |
|
290 | + [ |
|
291 | + TEST_FILES_PATH . 'source_with_ignore.php' => [ |
|
292 | + 2 => 1, |
|
293 | + 4 => -1, |
|
294 | + 6 => -1, |
|
295 | + 7 => 1 |
|
296 | + ] |
|
297 | + ] |
|
298 | + )); |
|
299 | + |
|
300 | + return $stub; |
|
301 | + } |
|
302 | + |
|
303 | + protected function getCoverageForClassWithAnonymousFunction() |
|
304 | + { |
|
305 | + $filter = new Filter; |
|
306 | + $filter->addFileToWhitelist(TEST_FILES_PATH . 'source_with_class_and_anonymous_function.php'); |
|
307 | + |
|
308 | + $coverage = new CodeCoverage( |
|
309 | + $this->setUpXdebugStubForClassWithAnonymousFunction(), |
|
310 | + $filter |
|
311 | + ); |
|
312 | + |
|
313 | + $coverage->start('ClassWithAnonymousFunction', true); |
|
314 | + $coverage->stop(); |
|
315 | + |
|
316 | + return $coverage; |
|
317 | + } |
|
318 | + |
|
319 | + protected function setUpXdebugStubForClassWithAnonymousFunction() |
|
320 | + { |
|
321 | + $stub = $this->createMock(Xdebug::class); |
|
322 | + |
|
323 | + $stub->expects($this->any()) |
|
324 | + ->method('stop') |
|
325 | + ->will($this->returnValue( |
|
326 | + [ |
|
327 | + TEST_FILES_PATH . 'source_with_class_and_anonymous_function.php' => [ |
|
328 | + 7 => 1, |
|
329 | + 9 => 1, |
|
330 | + 10 => -1, |
|
331 | + 11 => 1, |
|
332 | + 12 => 1, |
|
333 | + 13 => 1, |
|
334 | + 14 => 1, |
|
335 | + 17 => 1, |
|
336 | + 18 => 1 |
|
337 | + ] |
|
338 | + ] |
|
339 | + )); |
|
340 | + |
|
341 | + return $stub; |
|
342 | + } |
|
343 | 343 | } |