@@ -13,11 +13,11 @@ |
||
13 | 13 | */ |
14 | 14 | interface PHPUnit_Framework_MockObject_Stub_MatcherCollection |
15 | 15 | { |
16 | - /** |
|
17 | - * Adds a new matcher to the collection which can be used as an expectation |
|
18 | - * or a stub. |
|
19 | - * |
|
20 | - * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher Matcher for invocations to mock objects |
|
21 | - */ |
|
22 | - public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher); |
|
16 | + /** |
|
17 | + * Adds a new matcher to the collection which can be used as an expectation |
|
18 | + * or a stub. |
|
19 | + * |
|
20 | + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher Matcher for invocations to mock objects |
|
21 | + */ |
|
22 | + public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher); |
|
23 | 23 | } |
@@ -15,32 +15,32 @@ |
||
15 | 15 | */ |
16 | 16 | class PHPUnit_Framework_MockObject_Stub_Exception implements PHPUnit_Framework_MockObject_Stub |
17 | 17 | { |
18 | - protected $exception; |
|
18 | + protected $exception; |
|
19 | 19 | |
20 | - public function __construct($exception) |
|
21 | - { |
|
22 | - // TODO Replace check with type declaration when support for PHP 5 is dropped |
|
23 | - if (!$exception instanceof Throwable && !$exception instanceof Exception) { |
|
24 | - throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
25 | - 'Exception must be an instance of Throwable (PHP 7) or Exception (PHP 5)' |
|
26 | - ); |
|
27 | - } |
|
20 | + public function __construct($exception) |
|
21 | + { |
|
22 | + // TODO Replace check with type declaration when support for PHP 5 is dropped |
|
23 | + if (!$exception instanceof Throwable && !$exception instanceof Exception) { |
|
24 | + throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
25 | + 'Exception must be an instance of Throwable (PHP 7) or Exception (PHP 5)' |
|
26 | + ); |
|
27 | + } |
|
28 | 28 | |
29 | - $this->exception = $exception; |
|
30 | - } |
|
29 | + $this->exception = $exception; |
|
30 | + } |
|
31 | 31 | |
32 | - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
33 | - { |
|
34 | - throw $this->exception; |
|
35 | - } |
|
32 | + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
33 | + { |
|
34 | + throw $this->exception; |
|
35 | + } |
|
36 | 36 | |
37 | - public function toString() |
|
38 | - { |
|
39 | - $exporter = new Exporter; |
|
37 | + public function toString() |
|
38 | + { |
|
39 | + $exporter = new Exporter; |
|
40 | 40 | |
41 | - return sprintf( |
|
42 | - 'raise user-specified exception %s', |
|
43 | - $exporter->export($this->exception) |
|
44 | - ); |
|
45 | - } |
|
41 | + return sprintf( |
|
42 | + 'raise user-specified exception %s', |
|
43 | + $exporter->export($this->exception) |
|
44 | + ); |
|
45 | + } |
|
46 | 46 | } |
@@ -15,32 +15,32 @@ |
||
15 | 15 | */ |
16 | 16 | class PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls implements PHPUnit_Framework_MockObject_Stub |
17 | 17 | { |
18 | - protected $stack; |
|
19 | - protected $value; |
|
20 | - |
|
21 | - public function __construct($stack) |
|
22 | - { |
|
23 | - $this->stack = $stack; |
|
24 | - } |
|
25 | - |
|
26 | - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
27 | - { |
|
28 | - $this->value = array_shift($this->stack); |
|
29 | - |
|
30 | - if ($this->value instanceof PHPUnit_Framework_MockObject_Stub) { |
|
31 | - $this->value = $this->value->invoke($invocation); |
|
32 | - } |
|
33 | - |
|
34 | - return $this->value; |
|
35 | - } |
|
36 | - |
|
37 | - public function toString() |
|
38 | - { |
|
39 | - $exporter = new Exporter; |
|
40 | - |
|
41 | - return sprintf( |
|
42 | - 'return user-specified value %s', |
|
43 | - $exporter->export($this->value) |
|
44 | - ); |
|
45 | - } |
|
18 | + protected $stack; |
|
19 | + protected $value; |
|
20 | + |
|
21 | + public function __construct($stack) |
|
22 | + { |
|
23 | + $this->stack = $stack; |
|
24 | + } |
|
25 | + |
|
26 | + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
27 | + { |
|
28 | + $this->value = array_shift($this->stack); |
|
29 | + |
|
30 | + if ($this->value instanceof PHPUnit_Framework_MockObject_Stub) { |
|
31 | + $this->value = $this->value->invoke($invocation); |
|
32 | + } |
|
33 | + |
|
34 | + return $this->value; |
|
35 | + } |
|
36 | + |
|
37 | + public function toString() |
|
38 | + { |
|
39 | + $exporter = new Exporter; |
|
40 | + |
|
41 | + return sprintf( |
|
42 | + 'return user-specified value %s', |
|
43 | + $exporter->export($this->value) |
|
44 | + ); |
|
45 | + } |
|
46 | 46 | } |
@@ -13,20 +13,20 @@ |
||
13 | 13 | */ |
14 | 14 | class PHPUnit_Framework_MockObject_Stub_ReturnSelf implements PHPUnit_Framework_MockObject_Stub |
15 | 15 | { |
16 | - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
17 | - { |
|
18 | - if (!$invocation instanceof PHPUnit_Framework_MockObject_Invocation_Object) { |
|
19 | - throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
20 | - 'The current object can only be returned when mocking an ' . |
|
21 | - 'object, not a static class.' |
|
22 | - ); |
|
23 | - } |
|
16 | + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
17 | + { |
|
18 | + if (!$invocation instanceof PHPUnit_Framework_MockObject_Invocation_Object) { |
|
19 | + throw new PHPUnit_Framework_MockObject_RuntimeException( |
|
20 | + 'The current object can only be returned when mocking an ' . |
|
21 | + 'object, not a static class.' |
|
22 | + ); |
|
23 | + } |
|
24 | 24 | |
25 | - return $invocation->object; |
|
26 | - } |
|
25 | + return $invocation->object; |
|
26 | + } |
|
27 | 27 | |
28 | - public function toString() |
|
29 | - { |
|
30 | - return 'return the current object'; |
|
31 | - } |
|
28 | + public function toString() |
|
29 | + { |
|
30 | + return 'return the current object'; |
|
31 | + } |
|
32 | 32 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | { |
18 | 18 | if (!$invocation instanceof PHPUnit_Framework_MockObject_Invocation_Object) { |
19 | 19 | throw new PHPUnit_Framework_MockObject_RuntimeException( |
20 | - 'The current object can only be returned when mocking an ' . |
|
20 | + 'The current object can only be returned when mocking an '. |
|
21 | 21 | 'object, not a static class.' |
22 | 22 | ); |
23 | 23 | } |
@@ -13,8 +13,8 @@ |
||
13 | 13 | */ |
14 | 14 | class PHPUnit_Framework_MockObject_Stub_ReturnReference extends PHPUnit_Framework_MockObject_Stub_Return |
15 | 15 | { |
16 | - public function __construct(&$value) |
|
17 | - { |
|
18 | - $this->value = &$value; |
|
19 | - } |
|
16 | + public function __construct(&$value) |
|
17 | + { |
|
18 | + $this->value = &$value; |
|
19 | + } |
|
20 | 20 | } |
@@ -13,33 +13,33 @@ |
||
13 | 13 | */ |
14 | 14 | class PHPUnit_Framework_MockObject_Stub_ReturnValueMap implements PHPUnit_Framework_MockObject_Stub |
15 | 15 | { |
16 | - protected $valueMap; |
|
16 | + protected $valueMap; |
|
17 | 17 | |
18 | - public function __construct(array $valueMap) |
|
19 | - { |
|
20 | - $this->valueMap = $valueMap; |
|
21 | - } |
|
18 | + public function __construct(array $valueMap) |
|
19 | + { |
|
20 | + $this->valueMap = $valueMap; |
|
21 | + } |
|
22 | 22 | |
23 | - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
24 | - { |
|
25 | - $parameterCount = count($invocation->parameters); |
|
23 | + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
24 | + { |
|
25 | + $parameterCount = count($invocation->parameters); |
|
26 | 26 | |
27 | - foreach ($this->valueMap as $map) { |
|
28 | - if (!is_array($map) || $parameterCount != count($map) - 1) { |
|
29 | - continue; |
|
30 | - } |
|
27 | + foreach ($this->valueMap as $map) { |
|
28 | + if (!is_array($map) || $parameterCount != count($map) - 1) { |
|
29 | + continue; |
|
30 | + } |
|
31 | 31 | |
32 | - $return = array_pop($map); |
|
33 | - if ($invocation->parameters === $map) { |
|
34 | - return $return; |
|
35 | - } |
|
36 | - } |
|
32 | + $return = array_pop($map); |
|
33 | + if ($invocation->parameters === $map) { |
|
34 | + return $return; |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - return; |
|
39 | - } |
|
38 | + return; |
|
39 | + } |
|
40 | 40 | |
41 | - public function toString() |
|
42 | - { |
|
43 | - return 'return value from a map'; |
|
44 | - } |
|
41 | + public function toString() |
|
42 | + { |
|
43 | + return 'return value from a map'; |
|
44 | + } |
|
45 | 45 | } |
@@ -10,39 +10,39 @@ |
||
10 | 10 | |
11 | 11 | class PHPUnit_Framework_MockObject_Stub_ReturnCallback implements PHPUnit_Framework_MockObject_Stub |
12 | 12 | { |
13 | - protected $callback; |
|
13 | + protected $callback; |
|
14 | 14 | |
15 | - public function __construct($callback) |
|
16 | - { |
|
17 | - $this->callback = $callback; |
|
18 | - } |
|
15 | + public function __construct($callback) |
|
16 | + { |
|
17 | + $this->callback = $callback; |
|
18 | + } |
|
19 | 19 | |
20 | - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
21 | - { |
|
22 | - return call_user_func_array($this->callback, $invocation->parameters); |
|
23 | - } |
|
20 | + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
21 | + { |
|
22 | + return call_user_func_array($this->callback, $invocation->parameters); |
|
23 | + } |
|
24 | 24 | |
25 | - public function toString() |
|
26 | - { |
|
27 | - if (is_array($this->callback)) { |
|
28 | - if (is_object($this->callback[0])) { |
|
29 | - $class = get_class($this->callback[0]); |
|
30 | - $type = '->'; |
|
31 | - } else { |
|
32 | - $class = $this->callback[0]; |
|
33 | - $type = '::'; |
|
34 | - } |
|
25 | + public function toString() |
|
26 | + { |
|
27 | + if (is_array($this->callback)) { |
|
28 | + if (is_object($this->callback[0])) { |
|
29 | + $class = get_class($this->callback[0]); |
|
30 | + $type = '->'; |
|
31 | + } else { |
|
32 | + $class = $this->callback[0]; |
|
33 | + $type = '::'; |
|
34 | + } |
|
35 | 35 | |
36 | - return sprintf( |
|
37 | - 'return result of user defined callback %s%s%s() with the ' . |
|
38 | - 'passed arguments', |
|
39 | - $class, |
|
40 | - $type, |
|
41 | - $this->callback[1] |
|
42 | - ); |
|
43 | - } else { |
|
44 | - return 'return result of user defined callback ' . $this->callback . |
|
45 | - ' with the passed arguments'; |
|
46 | - } |
|
47 | - } |
|
36 | + return sprintf( |
|
37 | + 'return result of user defined callback %s%s%s() with the ' . |
|
38 | + 'passed arguments', |
|
39 | + $class, |
|
40 | + $type, |
|
41 | + $this->callback[1] |
|
42 | + ); |
|
43 | + } else { |
|
44 | + return 'return result of user defined callback ' . $this->callback . |
|
45 | + ' with the passed arguments'; |
|
46 | + } |
|
47 | + } |
|
48 | 48 | } |
@@ -34,14 +34,14 @@ |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | return sprintf( |
37 | - 'return result of user defined callback %s%s%s() with the ' . |
|
37 | + 'return result of user defined callback %s%s%s() with the '. |
|
38 | 38 | 'passed arguments', |
39 | 39 | $class, |
40 | 40 | $type, |
41 | 41 | $this->callback[1] |
42 | 42 | ); |
43 | 43 | } else { |
44 | - return 'return result of user defined callback ' . $this->callback . |
|
44 | + return 'return result of user defined callback '.$this->callback. |
|
45 | 45 | ' with the passed arguments'; |
46 | 46 | } |
47 | 47 | } |
@@ -17,35 +17,35 @@ |
||
17 | 17 | */ |
18 | 18 | abstract class PHPUnit_Framework_MockObject_Matcher_StatelessInvocation implements PHPUnit_Framework_MockObject_Matcher_Invocation |
19 | 19 | { |
20 | - /** |
|
21 | - * Registers the invocation $invocation in the object as being invoked. |
|
22 | - * This will only occur after matches() returns true which means the |
|
23 | - * current invocation is the correct one. |
|
24 | - * |
|
25 | - * The matcher can store information from the invocation which can later |
|
26 | - * be checked in verify(), or it can check the values directly and throw |
|
27 | - * and exception if an expectation is not met. |
|
28 | - * |
|
29 | - * If the matcher is a stub it will also have a return value. |
|
30 | - * |
|
31 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation Object containing information on a mocked or stubbed method which was invoked |
|
32 | - * |
|
33 | - * @return mixed |
|
34 | - */ |
|
35 | - public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
36 | - { |
|
37 | - } |
|
20 | + /** |
|
21 | + * Registers the invocation $invocation in the object as being invoked. |
|
22 | + * This will only occur after matches() returns true which means the |
|
23 | + * current invocation is the correct one. |
|
24 | + * |
|
25 | + * The matcher can store information from the invocation which can later |
|
26 | + * be checked in verify(), or it can check the values directly and throw |
|
27 | + * and exception if an expectation is not met. |
|
28 | + * |
|
29 | + * If the matcher is a stub it will also have a return value. |
|
30 | + * |
|
31 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation Object containing information on a mocked or stubbed method which was invoked |
|
32 | + * |
|
33 | + * @return mixed |
|
34 | + */ |
|
35 | + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
36 | + { |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Checks if the invocation $invocation matches the current rules. If it does |
|
41 | - * the matcher will get the invoked() method called which should check if an |
|
42 | - * expectation is met. |
|
43 | - * |
|
44 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation Object containing information on a mocked or stubbed method which was invoked |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public function verify() |
|
49 | - { |
|
50 | - } |
|
39 | + /** |
|
40 | + * Checks if the invocation $invocation matches the current rules. If it does |
|
41 | + * the matcher will get the invoked() method called which should check if an |
|
42 | + * expectation is met. |
|
43 | + * |
|
44 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation Object containing information on a mocked or stubbed method which was invoked |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public function verify() |
|
49 | + { |
|
50 | + } |
|
51 | 51 | } |
@@ -18,28 +18,28 @@ |
||
18 | 18 | */ |
19 | 19 | class PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder |
20 | 20 | { |
21 | - /** |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public function toString() |
|
25 | - { |
|
26 | - return 'invoked at least once'; |
|
27 | - } |
|
21 | + /** |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public function toString() |
|
25 | + { |
|
26 | + return 'invoked at least once'; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Verifies that the current expectation is valid. If everything is OK the |
|
31 | - * code should just return, if not it must throw an exception. |
|
32 | - * |
|
33 | - * @throws ExpectationFailedException |
|
34 | - */ |
|
35 | - public function verify() |
|
36 | - { |
|
37 | - $count = $this->getInvocationCount(); |
|
29 | + /** |
|
30 | + * Verifies that the current expectation is valid. If everything is OK the |
|
31 | + * code should just return, if not it must throw an exception. |
|
32 | + * |
|
33 | + * @throws ExpectationFailedException |
|
34 | + */ |
|
35 | + public function verify() |
|
36 | + { |
|
37 | + $count = $this->getInvocationCount(); |
|
38 | 38 | |
39 | - if ($count < 1) { |
|
40 | - throw new ExpectationFailedException( |
|
41 | - 'Expected invocation at least once but it never occurred.' |
|
42 | - ); |
|
43 | - } |
|
44 | - } |
|
39 | + if ($count < 1) { |
|
40 | + throw new ExpectationFailedException( |
|
41 | + 'Expected invocation at least once but it never occurred.' |
|
42 | + ); |
|
43 | + } |
|
44 | + } |
|
45 | 45 | } |