@@ -13,21 +13,21 @@ |
||
13 | 13 | */ |
14 | 14 | class PHPUnit_Framework_MockObject_Matcher_AnyParameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation |
15 | 15 | { |
16 | - /** |
|
17 | - * @return string |
|
18 | - */ |
|
19 | - public function toString() |
|
20 | - { |
|
21 | - return 'with any parameters'; |
|
22 | - } |
|
16 | + /** |
|
17 | + * @return string |
|
18 | + */ |
|
19 | + public function toString() |
|
20 | + { |
|
21 | + return 'with any parameters'; |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
26 | - * |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
30 | - { |
|
31 | - return true; |
|
32 | - } |
|
24 | + /** |
|
25 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
26 | + * |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
30 | + { |
|
31 | + return true; |
|
32 | + } |
|
33 | 33 | } |
@@ -22,66 +22,66 @@ |
||
22 | 22 | */ |
23 | 23 | class PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex implements PHPUnit_Framework_MockObject_Matcher_Invocation |
24 | 24 | { |
25 | - /** |
|
26 | - * @var int |
|
27 | - */ |
|
28 | - protected $sequenceIndex; |
|
25 | + /** |
|
26 | + * @var int |
|
27 | + */ |
|
28 | + protected $sequenceIndex; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var int |
|
32 | - */ |
|
33 | - protected $currentIndex = -1; |
|
30 | + /** |
|
31 | + * @var int |
|
32 | + */ |
|
33 | + protected $currentIndex = -1; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param int $sequenceIndex |
|
37 | - */ |
|
38 | - public function __construct($sequenceIndex) |
|
39 | - { |
|
40 | - $this->sequenceIndex = $sequenceIndex; |
|
41 | - } |
|
35 | + /** |
|
36 | + * @param int $sequenceIndex |
|
37 | + */ |
|
38 | + public function __construct($sequenceIndex) |
|
39 | + { |
|
40 | + $this->sequenceIndex = $sequenceIndex; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - public function toString() |
|
47 | - { |
|
48 | - return 'invoked at sequence index ' . $this->sequenceIndex; |
|
49 | - } |
|
43 | + /** |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + public function toString() |
|
47 | + { |
|
48 | + return 'invoked at sequence index ' . $this->sequenceIndex; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
53 | - * |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
57 | - { |
|
58 | - $this->currentIndex++; |
|
51 | + /** |
|
52 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
53 | + * |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
57 | + { |
|
58 | + $this->currentIndex++; |
|
59 | 59 | |
60 | - return $this->currentIndex == $this->sequenceIndex; |
|
61 | - } |
|
60 | + return $this->currentIndex == $this->sequenceIndex; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
65 | - */ |
|
66 | - public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
67 | - { |
|
68 | - } |
|
63 | + /** |
|
64 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
65 | + */ |
|
66 | + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
67 | + { |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Verifies that the current expectation is valid. If everything is OK the |
|
72 | - * code should just return, if not it must throw an exception. |
|
73 | - * |
|
74 | - * @throws ExpectationFailedException |
|
75 | - */ |
|
76 | - public function verify() |
|
77 | - { |
|
78 | - if ($this->currentIndex < $this->sequenceIndex) { |
|
79 | - throw new ExpectationFailedException( |
|
80 | - sprintf( |
|
81 | - 'The expected invocation at index %s was never reached.', |
|
82 | - $this->sequenceIndex |
|
83 | - ) |
|
84 | - ); |
|
85 | - } |
|
86 | - } |
|
70 | + /** |
|
71 | + * Verifies that the current expectation is valid. If everything is OK the |
|
72 | + * code should just return, if not it must throw an exception. |
|
73 | + * |
|
74 | + * @throws ExpectationFailedException |
|
75 | + */ |
|
76 | + public function verify() |
|
77 | + { |
|
78 | + if ($this->currentIndex < $this->sequenceIndex) { |
|
79 | + throw new ExpectationFailedException( |
|
80 | + sprintf( |
|
81 | + 'The expected invocation at index %s was never reached.', |
|
82 | + $this->sequenceIndex |
|
83 | + ) |
|
84 | + ); |
|
85 | + } |
|
86 | + } |
|
87 | 87 | } |
@@ -45,7 +45,7 @@ |
||
45 | 45 | */ |
46 | 46 | public function toString() |
47 | 47 | { |
48 | - return 'invoked at sequence index ' . $this->sequenceIndex; |
|
48 | + return 'invoked at sequence index '.$this->sequenceIndex; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -16,42 +16,42 @@ |
||
16 | 16 | */ |
17 | 17 | class PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder |
18 | 18 | { |
19 | - /** |
|
20 | - * @var int |
|
21 | - */ |
|
22 | - private $requiredInvocations; |
|
19 | + /** |
|
20 | + * @var int |
|
21 | + */ |
|
22 | + private $requiredInvocations; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param int $requiredInvocations |
|
26 | - */ |
|
27 | - public function __construct($requiredInvocations) |
|
28 | - { |
|
29 | - $this->requiredInvocations = $requiredInvocations; |
|
30 | - } |
|
24 | + /** |
|
25 | + * @param int $requiredInvocations |
|
26 | + */ |
|
27 | + public function __construct($requiredInvocations) |
|
28 | + { |
|
29 | + $this->requiredInvocations = $requiredInvocations; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function toString() |
|
36 | - { |
|
37 | - return 'invoked at least ' . $this->requiredInvocations . ' times'; |
|
38 | - } |
|
32 | + /** |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function toString() |
|
36 | + { |
|
37 | + return 'invoked at least ' . $this->requiredInvocations . ' times'; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Verifies that the current expectation is valid. If everything is OK the |
|
42 | - * code should just return, if not it must throw an exception. |
|
43 | - * |
|
44 | - * @throws ExpectationFailedException |
|
45 | - */ |
|
46 | - public function verify() |
|
47 | - { |
|
48 | - $count = $this->getInvocationCount(); |
|
40 | + /** |
|
41 | + * Verifies that the current expectation is valid. If everything is OK the |
|
42 | + * code should just return, if not it must throw an exception. |
|
43 | + * |
|
44 | + * @throws ExpectationFailedException |
|
45 | + */ |
|
46 | + public function verify() |
|
47 | + { |
|
48 | + $count = $this->getInvocationCount(); |
|
49 | 49 | |
50 | - if ($count < $this->requiredInvocations) { |
|
51 | - throw new ExpectationFailedException( |
|
52 | - 'Expected invocation at least ' . $this->requiredInvocations . |
|
53 | - ' times but it occurred ' . $count . ' time(s).' |
|
54 | - ); |
|
55 | - } |
|
56 | - } |
|
50 | + if ($count < $this->requiredInvocations) { |
|
51 | + throw new ExpectationFailedException( |
|
52 | + 'Expected invocation at least ' . $this->requiredInvocations . |
|
53 | + ' times but it occurred ' . $count . ' time(s).' |
|
54 | + ); |
|
55 | + } |
|
56 | + } |
|
57 | 57 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function toString() |
36 | 36 | { |
37 | - return 'invoked at least ' . $this->requiredInvocations . ' times'; |
|
37 | + return 'invoked at least '.$this->requiredInvocations.' times'; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | |
50 | 50 | if ($count < $this->requiredInvocations) { |
51 | 51 | throw new ExpectationFailedException( |
52 | - 'Expected invocation at least ' . $this->requiredInvocations . |
|
53 | - ' times but it occurred ' . $count . ' time(s).' |
|
52 | + 'Expected invocation at least '.$this->requiredInvocations. |
|
53 | + ' times but it occurred '.$count.' time(s).' |
|
54 | 54 | ); |
55 | 55 | } |
56 | 56 | } |
@@ -22,140 +22,140 @@ |
||
22 | 22 | */ |
23 | 23 | class PHPUnit_Framework_MockObject_Matcher_Parameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation |
24 | 24 | { |
25 | - /** |
|
26 | - * @var Constraint[] |
|
27 | - */ |
|
28 | - protected $parameters = []; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var PHPUnit_Framework_MockObject_Invocation |
|
32 | - */ |
|
33 | - protected $invocation; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var ExpectationFailedException |
|
37 | - */ |
|
38 | - private $parameterVerificationResult; |
|
39 | - |
|
40 | - /** |
|
41 | - * @param array $parameters |
|
42 | - */ |
|
43 | - public function __construct(array $parameters) |
|
44 | - { |
|
45 | - foreach ($parameters as $parameter) { |
|
46 | - if (!($parameter instanceof Constraint)) { |
|
47 | - $parameter = new IsEqual( |
|
48 | - $parameter |
|
49 | - ); |
|
50 | - } |
|
51 | - |
|
52 | - $this->parameters[] = $parameter; |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function toString() |
|
60 | - { |
|
61 | - $text = 'with parameter'; |
|
62 | - |
|
63 | - foreach ($this->parameters as $index => $parameter) { |
|
64 | - if ($index > 0) { |
|
65 | - $text .= ' and'; |
|
66 | - } |
|
67 | - |
|
68 | - $text .= ' ' . $index . ' ' . $parameter->toString(); |
|
69 | - } |
|
70 | - |
|
71 | - return $text; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
76 | - * |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
80 | - { |
|
81 | - $this->invocation = $invocation; |
|
82 | - $this->parameterVerificationResult = null; |
|
83 | - |
|
84 | - try { |
|
85 | - $this->parameterVerificationResult = $this->verify(); |
|
86 | - |
|
87 | - return $this->parameterVerificationResult; |
|
88 | - } catch (ExpectationFailedException $e) { |
|
89 | - $this->parameterVerificationResult = $e; |
|
90 | - |
|
91 | - throw $this->parameterVerificationResult; |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Checks if the invocation $invocation matches the current rules. If it |
|
97 | - * does the matcher will get the invoked() method called which should check |
|
98 | - * if an expectation is met. |
|
99 | - * |
|
100 | - * @return bool |
|
101 | - * |
|
102 | - * @throws ExpectationFailedException |
|
103 | - */ |
|
104 | - public function verify() |
|
105 | - { |
|
106 | - if (isset($this->parameterVerificationResult)) { |
|
107 | - return $this->guardAgainstDuplicateEvaluationOfParameterConstraints(); |
|
108 | - } |
|
109 | - |
|
110 | - if ($this->invocation === null) { |
|
111 | - throw new ExpectationFailedException( |
|
112 | - 'Mocked method does not exist.' |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - if (count($this->invocation->parameters) < count($this->parameters)) { |
|
117 | - $message = 'Parameter count for invocation %s is too low.'; |
|
118 | - |
|
119 | - // The user called `->with($this->anything())`, but may have meant |
|
120 | - // `->withAnyParameters()`. |
|
121 | - // |
|
122 | - // @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/199 |
|
123 | - if (count($this->parameters) === 1 && |
|
124 | - get_class($this->parameters[0]) === IsAnything::class) { |
|
125 | - $message .= "\nTo allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead."; |
|
126 | - } |
|
127 | - |
|
128 | - throw new ExpectationFailedException( |
|
129 | - sprintf($message, $this->invocation->toString()) |
|
130 | - ); |
|
131 | - } |
|
132 | - |
|
133 | - foreach ($this->parameters as $i => $parameter) { |
|
134 | - $parameter->evaluate( |
|
135 | - $this->invocation->parameters[$i], |
|
136 | - sprintf( |
|
137 | - 'Parameter %s for invocation %s does not match expected ' . |
|
138 | - 'value.', |
|
139 | - $i, |
|
140 | - $this->invocation->toString() |
|
141 | - ) |
|
142 | - ); |
|
143 | - } |
|
144 | - |
|
145 | - return true; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * @return bool |
|
150 | - * |
|
151 | - * @throws ExpectationFailedException |
|
152 | - */ |
|
153 | - private function guardAgainstDuplicateEvaluationOfParameterConstraints() |
|
154 | - { |
|
155 | - if ($this->parameterVerificationResult instanceof Exception) { |
|
156 | - throw $this->parameterVerificationResult; |
|
157 | - } |
|
158 | - |
|
159 | - return (bool) $this->parameterVerificationResult; |
|
160 | - } |
|
25 | + /** |
|
26 | + * @var Constraint[] |
|
27 | + */ |
|
28 | + protected $parameters = []; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var PHPUnit_Framework_MockObject_Invocation |
|
32 | + */ |
|
33 | + protected $invocation; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var ExpectationFailedException |
|
37 | + */ |
|
38 | + private $parameterVerificationResult; |
|
39 | + |
|
40 | + /** |
|
41 | + * @param array $parameters |
|
42 | + */ |
|
43 | + public function __construct(array $parameters) |
|
44 | + { |
|
45 | + foreach ($parameters as $parameter) { |
|
46 | + if (!($parameter instanceof Constraint)) { |
|
47 | + $parameter = new IsEqual( |
|
48 | + $parameter |
|
49 | + ); |
|
50 | + } |
|
51 | + |
|
52 | + $this->parameters[] = $parameter; |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function toString() |
|
60 | + { |
|
61 | + $text = 'with parameter'; |
|
62 | + |
|
63 | + foreach ($this->parameters as $index => $parameter) { |
|
64 | + if ($index > 0) { |
|
65 | + $text .= ' and'; |
|
66 | + } |
|
67 | + |
|
68 | + $text .= ' ' . $index . ' ' . $parameter->toString(); |
|
69 | + } |
|
70 | + |
|
71 | + return $text; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
76 | + * |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
80 | + { |
|
81 | + $this->invocation = $invocation; |
|
82 | + $this->parameterVerificationResult = null; |
|
83 | + |
|
84 | + try { |
|
85 | + $this->parameterVerificationResult = $this->verify(); |
|
86 | + |
|
87 | + return $this->parameterVerificationResult; |
|
88 | + } catch (ExpectationFailedException $e) { |
|
89 | + $this->parameterVerificationResult = $e; |
|
90 | + |
|
91 | + throw $this->parameterVerificationResult; |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Checks if the invocation $invocation matches the current rules. If it |
|
97 | + * does the matcher will get the invoked() method called which should check |
|
98 | + * if an expectation is met. |
|
99 | + * |
|
100 | + * @return bool |
|
101 | + * |
|
102 | + * @throws ExpectationFailedException |
|
103 | + */ |
|
104 | + public function verify() |
|
105 | + { |
|
106 | + if (isset($this->parameterVerificationResult)) { |
|
107 | + return $this->guardAgainstDuplicateEvaluationOfParameterConstraints(); |
|
108 | + } |
|
109 | + |
|
110 | + if ($this->invocation === null) { |
|
111 | + throw new ExpectationFailedException( |
|
112 | + 'Mocked method does not exist.' |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + if (count($this->invocation->parameters) < count($this->parameters)) { |
|
117 | + $message = 'Parameter count for invocation %s is too low.'; |
|
118 | + |
|
119 | + // The user called `->with($this->anything())`, but may have meant |
|
120 | + // `->withAnyParameters()`. |
|
121 | + // |
|
122 | + // @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/199 |
|
123 | + if (count($this->parameters) === 1 && |
|
124 | + get_class($this->parameters[0]) === IsAnything::class) { |
|
125 | + $message .= "\nTo allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead."; |
|
126 | + } |
|
127 | + |
|
128 | + throw new ExpectationFailedException( |
|
129 | + sprintf($message, $this->invocation->toString()) |
|
130 | + ); |
|
131 | + } |
|
132 | + |
|
133 | + foreach ($this->parameters as $i => $parameter) { |
|
134 | + $parameter->evaluate( |
|
135 | + $this->invocation->parameters[$i], |
|
136 | + sprintf( |
|
137 | + 'Parameter %s for invocation %s does not match expected ' . |
|
138 | + 'value.', |
|
139 | + $i, |
|
140 | + $this->invocation->toString() |
|
141 | + ) |
|
142 | + ); |
|
143 | + } |
|
144 | + |
|
145 | + return true; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * @return bool |
|
150 | + * |
|
151 | + * @throws ExpectationFailedException |
|
152 | + */ |
|
153 | + private function guardAgainstDuplicateEvaluationOfParameterConstraints() |
|
154 | + { |
|
155 | + if ($this->parameterVerificationResult instanceof Exception) { |
|
156 | + throw $this->parameterVerificationResult; |
|
157 | + } |
|
158 | + |
|
159 | + return (bool) $this->parameterVerificationResult; |
|
160 | + } |
|
161 | 161 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $text .= ' and'; |
66 | 66 | } |
67 | 67 | |
68 | - $text .= ' ' . $index . ' ' . $parameter->toString(); |
|
68 | + $text .= ' '.$index.' '.$parameter->toString(); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | return $text; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | $parameter->evaluate( |
135 | 135 | $this->invocation->parameters[$i], |
136 | 136 | sprintf( |
137 | - 'Parameter %s for invocation %s does not match expected ' . |
|
137 | + 'Parameter %s for invocation %s does not match expected '. |
|
138 | 138 | 'value.', |
139 | 139 | $i, |
140 | 140 | $this->invocation->toString() |
@@ -16,50 +16,50 @@ |
||
16 | 16 | */ |
17 | 17 | abstract class PHPUnit_Framework_MockObject_Matcher_InvokedRecorder implements PHPUnit_Framework_MockObject_Matcher_Invocation |
18 | 18 | { |
19 | - /** |
|
20 | - * @var PHPUnit_Framework_MockObject_Invocation[] |
|
21 | - */ |
|
22 | - protected $invocations = []; |
|
19 | + /** |
|
20 | + * @var PHPUnit_Framework_MockObject_Invocation[] |
|
21 | + */ |
|
22 | + protected $invocations = []; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @return int |
|
26 | - */ |
|
27 | - public function getInvocationCount() |
|
28 | - { |
|
29 | - return count($this->invocations); |
|
30 | - } |
|
24 | + /** |
|
25 | + * @return int |
|
26 | + */ |
|
27 | + public function getInvocationCount() |
|
28 | + { |
|
29 | + return count($this->invocations); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return PHPUnit_Framework_MockObject_Invocation[] |
|
34 | - */ |
|
35 | - public function getInvocations() |
|
36 | - { |
|
37 | - return $this->invocations; |
|
38 | - } |
|
32 | + /** |
|
33 | + * @return PHPUnit_Framework_MockObject_Invocation[] |
|
34 | + */ |
|
35 | + public function getInvocations() |
|
36 | + { |
|
37 | + return $this->invocations; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public function hasBeenInvoked() |
|
44 | - { |
|
45 | - return count($this->invocations) > 0; |
|
46 | - } |
|
40 | + /** |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public function hasBeenInvoked() |
|
44 | + { |
|
45 | + return count($this->invocations) > 0; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
50 | - */ |
|
51 | - public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
52 | - { |
|
53 | - $this->invocations[] = $invocation; |
|
54 | - } |
|
48 | + /** |
|
49 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
50 | + */ |
|
51 | + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
52 | + { |
|
53 | + $this->invocations[] = $invocation; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
58 | - * |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
62 | - { |
|
63 | - return true; |
|
64 | - } |
|
56 | + /** |
|
57 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
58 | + * |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
62 | + { |
|
63 | + return true; |
|
64 | + } |
|
65 | 65 | } |
@@ -20,91 +20,91 @@ |
||
20 | 20 | */ |
21 | 21 | class PHPUnit_Framework_MockObject_Matcher_InvokedCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder |
22 | 22 | { |
23 | - /** |
|
24 | - * @var int |
|
25 | - */ |
|
26 | - protected $expectedCount; |
|
23 | + /** |
|
24 | + * @var int |
|
25 | + */ |
|
26 | + protected $expectedCount; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param int $expectedCount |
|
30 | - */ |
|
31 | - public function __construct($expectedCount) |
|
32 | - { |
|
33 | - $this->expectedCount = $expectedCount; |
|
34 | - } |
|
28 | + /** |
|
29 | + * @param int $expectedCount |
|
30 | + */ |
|
31 | + public function __construct($expectedCount) |
|
32 | + { |
|
33 | + $this->expectedCount = $expectedCount; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public function isNever() |
|
40 | - { |
|
41 | - return $this->expectedCount == 0; |
|
42 | - } |
|
36 | + /** |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | + public function isNever() |
|
40 | + { |
|
41 | + return $this->expectedCount == 0; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function toString() |
|
48 | - { |
|
49 | - return 'invoked ' . $this->expectedCount . ' time(s)'; |
|
50 | - } |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function toString() |
|
48 | + { |
|
49 | + return 'invoked ' . $this->expectedCount . ' time(s)'; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
54 | - * |
|
55 | - * @throws ExpectationFailedException |
|
56 | - */ |
|
57 | - public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
58 | - { |
|
59 | - parent::invoked($invocation); |
|
52 | + /** |
|
53 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
54 | + * |
|
55 | + * @throws ExpectationFailedException |
|
56 | + */ |
|
57 | + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
58 | + { |
|
59 | + parent::invoked($invocation); |
|
60 | 60 | |
61 | - $count = $this->getInvocationCount(); |
|
61 | + $count = $this->getInvocationCount(); |
|
62 | 62 | |
63 | - if ($count > $this->expectedCount) { |
|
64 | - $message = $invocation->toString() . ' '; |
|
63 | + if ($count > $this->expectedCount) { |
|
64 | + $message = $invocation->toString() . ' '; |
|
65 | 65 | |
66 | - switch ($this->expectedCount) { |
|
67 | - case 0: { |
|
68 | - $message .= 'was not expected to be called.'; |
|
69 | - } |
|
70 | - break; |
|
66 | + switch ($this->expectedCount) { |
|
67 | + case 0: { |
|
68 | + $message .= 'was not expected to be called.'; |
|
69 | + } |
|
70 | + break; |
|
71 | 71 | |
72 | - case 1: { |
|
73 | - $message .= 'was not expected to be called more than once.'; |
|
74 | - } |
|
75 | - break; |
|
72 | + case 1: { |
|
73 | + $message .= 'was not expected to be called more than once.'; |
|
74 | + } |
|
75 | + break; |
|
76 | 76 | |
77 | - default: { |
|
78 | - $message .= sprintf( |
|
79 | - 'was not expected to be called more than %d times.', |
|
80 | - $this->expectedCount |
|
81 | - ); |
|
82 | - } |
|
83 | - } |
|
77 | + default: { |
|
78 | + $message .= sprintf( |
|
79 | + 'was not expected to be called more than %d times.', |
|
80 | + $this->expectedCount |
|
81 | + ); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - throw new ExpectationFailedException($message); |
|
86 | - } |
|
87 | - } |
|
85 | + throw new ExpectationFailedException($message); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Verifies that the current expectation is valid. If everything is OK the |
|
91 | - * code should just return, if not it must throw an exception. |
|
92 | - * |
|
93 | - * @throws ExpectationFailedException |
|
94 | - */ |
|
95 | - public function verify() |
|
96 | - { |
|
97 | - $count = $this->getInvocationCount(); |
|
89 | + /** |
|
90 | + * Verifies that the current expectation is valid. If everything is OK the |
|
91 | + * code should just return, if not it must throw an exception. |
|
92 | + * |
|
93 | + * @throws ExpectationFailedException |
|
94 | + */ |
|
95 | + public function verify() |
|
96 | + { |
|
97 | + $count = $this->getInvocationCount(); |
|
98 | 98 | |
99 | - if ($count !== $this->expectedCount) { |
|
100 | - throw new ExpectationFailedException( |
|
101 | - sprintf( |
|
102 | - 'Method was expected to be called %d times, ' . |
|
103 | - 'actually called %d times.', |
|
104 | - $this->expectedCount, |
|
105 | - $count |
|
106 | - ) |
|
107 | - ); |
|
108 | - } |
|
109 | - } |
|
99 | + if ($count !== $this->expectedCount) { |
|
100 | + throw new ExpectationFailedException( |
|
101 | + sprintf( |
|
102 | + 'Method was expected to be called %d times, ' . |
|
103 | + 'actually called %d times.', |
|
104 | + $this->expectedCount, |
|
105 | + $count |
|
106 | + ) |
|
107 | + ); |
|
108 | + } |
|
109 | + } |
|
110 | 110 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function toString() |
48 | 48 | { |
49 | - return 'invoked ' . $this->expectedCount . ' time(s)'; |
|
49 | + return 'invoked '.$this->expectedCount.' time(s)'; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $count = $this->getInvocationCount(); |
62 | 62 | |
63 | 63 | if ($count > $this->expectedCount) { |
64 | - $message = $invocation->toString() . ' '; |
|
64 | + $message = $invocation->toString().' '; |
|
65 | 65 | |
66 | 66 | switch ($this->expectedCount) { |
67 | 67 | case 0: { |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | if ($count !== $this->expectedCount) { |
100 | 100 | throw new ExpectationFailedException( |
101 | 101 | sprintf( |
102 | - 'Method was expected to be called %d times, ' . |
|
102 | + 'Method was expected to be called %d times, '. |
|
103 | 103 | 'actually called %d times.', |
104 | 104 | $this->expectedCount, |
105 | 105 | $count |
@@ -21,50 +21,50 @@ |
||
21 | 21 | */ |
22 | 22 | class PHPUnit_Framework_MockObject_Matcher_MethodName extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation |
23 | 23 | { |
24 | - /** |
|
25 | - * @var Constraint |
|
26 | - */ |
|
27 | - protected $constraint; |
|
24 | + /** |
|
25 | + * @var Constraint |
|
26 | + */ |
|
27 | + protected $constraint; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param Constraint|string |
|
31 | - * |
|
32 | - * @throws Constraint |
|
33 | - */ |
|
34 | - public function __construct($constraint) |
|
35 | - { |
|
36 | - if (!$constraint instanceof Constraint) { |
|
37 | - if (!is_string($constraint)) { |
|
38 | - throw InvalidArgumentHelper::factory(1, 'string'); |
|
39 | - } |
|
29 | + /** |
|
30 | + * @param Constraint|string |
|
31 | + * |
|
32 | + * @throws Constraint |
|
33 | + */ |
|
34 | + public function __construct($constraint) |
|
35 | + { |
|
36 | + if (!$constraint instanceof Constraint) { |
|
37 | + if (!is_string($constraint)) { |
|
38 | + throw InvalidArgumentHelper::factory(1, 'string'); |
|
39 | + } |
|
40 | 40 | |
41 | - $constraint = new IsEqual( |
|
42 | - $constraint, |
|
43 | - 0, |
|
44 | - 10, |
|
45 | - false, |
|
46 | - true |
|
47 | - ); |
|
48 | - } |
|
41 | + $constraint = new IsEqual( |
|
42 | + $constraint, |
|
43 | + 0, |
|
44 | + 10, |
|
45 | + false, |
|
46 | + true |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | - $this->constraint = $constraint; |
|
51 | - } |
|
50 | + $this->constraint = $constraint; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function toString() |
|
57 | - { |
|
58 | - return 'method name ' . $this->constraint->toString(); |
|
59 | - } |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function toString() |
|
57 | + { |
|
58 | + return 'method name ' . $this->constraint->toString(); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
63 | - * |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
67 | - { |
|
68 | - return $this->constraint->evaluate($invocation->methodName, '', true); |
|
69 | - } |
|
61 | + /** |
|
62 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
63 | + * |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
67 | + { |
|
68 | + return $this->constraint->evaluate($invocation->methodName, '', true); |
|
69 | + } |
|
70 | 70 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | */ |
56 | 56 | public function toString() |
57 | 57 | { |
58 | - return 'method name ' . $this->constraint->toString(); |
|
58 | + return 'method name '.$this->constraint->toString(); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -14,15 +14,15 @@ |
||
14 | 14 | */ |
15 | 15 | class PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder |
16 | 16 | { |
17 | - /** |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function toString() |
|
21 | - { |
|
22 | - return 'invoked zero or more times'; |
|
23 | - } |
|
17 | + /** |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function toString() |
|
21 | + { |
|
22 | + return 'invoked zero or more times'; |
|
23 | + } |
|
24 | 24 | |
25 | - public function verify() |
|
26 | - { |
|
27 | - } |
|
25 | + public function verify() |
|
26 | + { |
|
27 | + } |
|
28 | 28 | } |
@@ -24,107 +24,107 @@ |
||
24 | 24 | */ |
25 | 25 | class PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation |
26 | 26 | { |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - private $parameterGroups = []; |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + private $parameterGroups = []; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - private $invocations = []; |
|
32 | + /** |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + private $invocations = []; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param array $parameterGroups |
|
39 | - */ |
|
40 | - public function __construct(array $parameterGroups) |
|
41 | - { |
|
42 | - foreach ($parameterGroups as $index => $parameters) { |
|
43 | - foreach ($parameters as $parameter) { |
|
44 | - if (!$parameter instanceof Constraint) { |
|
45 | - $parameter = new IsEqual($parameter); |
|
46 | - } |
|
37 | + /** |
|
38 | + * @param array $parameterGroups |
|
39 | + */ |
|
40 | + public function __construct(array $parameterGroups) |
|
41 | + { |
|
42 | + foreach ($parameterGroups as $index => $parameters) { |
|
43 | + foreach ($parameters as $parameter) { |
|
44 | + if (!$parameter instanceof Constraint) { |
|
45 | + $parameter = new IsEqual($parameter); |
|
46 | + } |
|
47 | 47 | |
48 | - $this->parameterGroups[$index][] = $parameter; |
|
49 | - } |
|
50 | - } |
|
51 | - } |
|
48 | + $this->parameterGroups[$index][] = $parameter; |
|
49 | + } |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function toString() |
|
57 | - { |
|
58 | - $text = 'with consecutive parameters'; |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function toString() |
|
57 | + { |
|
58 | + $text = 'with consecutive parameters'; |
|
59 | 59 | |
60 | - return $text; |
|
61 | - } |
|
60 | + return $text; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
65 | - * |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
69 | - { |
|
70 | - $this->invocations[] = $invocation; |
|
71 | - $callIndex = count($this->invocations) - 1; |
|
63 | + /** |
|
64 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
65 | + * |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) |
|
69 | + { |
|
70 | + $this->invocations[] = $invocation; |
|
71 | + $callIndex = count($this->invocations) - 1; |
|
72 | 72 | |
73 | - $this->verifyInvocation($invocation, $callIndex); |
|
73 | + $this->verifyInvocation($invocation, $callIndex); |
|
74 | 74 | |
75 | - return false; |
|
76 | - } |
|
75 | + return false; |
|
76 | + } |
|
77 | 77 | |
78 | - public function verify() |
|
79 | - { |
|
80 | - foreach ($this->invocations as $callIndex => $invocation) { |
|
81 | - $this->verifyInvocation($invocation, $callIndex); |
|
82 | - } |
|
83 | - } |
|
78 | + public function verify() |
|
79 | + { |
|
80 | + foreach ($this->invocations as $callIndex => $invocation) { |
|
81 | + $this->verifyInvocation($invocation, $callIndex); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Verify a single invocation |
|
87 | - * |
|
88 | - * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
89 | - * @param int $callIndex |
|
90 | - * |
|
91 | - * @throws ExpectationFailedException |
|
92 | - */ |
|
93 | - private function verifyInvocation(PHPUnit_Framework_MockObject_Invocation $invocation, $callIndex) |
|
94 | - { |
|
95 | - if (isset($this->parameterGroups[$callIndex])) { |
|
96 | - $parameters = $this->parameterGroups[$callIndex]; |
|
97 | - } else { |
|
98 | - // no parameter assertion for this call index |
|
99 | - return; |
|
100 | - } |
|
85 | + /** |
|
86 | + * Verify a single invocation |
|
87 | + * |
|
88 | + * @param PHPUnit_Framework_MockObject_Invocation $invocation |
|
89 | + * @param int $callIndex |
|
90 | + * |
|
91 | + * @throws ExpectationFailedException |
|
92 | + */ |
|
93 | + private function verifyInvocation(PHPUnit_Framework_MockObject_Invocation $invocation, $callIndex) |
|
94 | + { |
|
95 | + if (isset($this->parameterGroups[$callIndex])) { |
|
96 | + $parameters = $this->parameterGroups[$callIndex]; |
|
97 | + } else { |
|
98 | + // no parameter assertion for this call index |
|
99 | + return; |
|
100 | + } |
|
101 | 101 | |
102 | - if ($invocation === null) { |
|
103 | - throw new ExpectationFailedException( |
|
104 | - 'Mocked method does not exist.' |
|
105 | - ); |
|
106 | - } |
|
102 | + if ($invocation === null) { |
|
103 | + throw new ExpectationFailedException( |
|
104 | + 'Mocked method does not exist.' |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | |
108 | - if (count($invocation->parameters) < count($parameters)) { |
|
109 | - throw new ExpectationFailedException( |
|
110 | - sprintf( |
|
111 | - 'Parameter count for invocation %s is too low.', |
|
112 | - $invocation->toString() |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
108 | + if (count($invocation->parameters) < count($parameters)) { |
|
109 | + throw new ExpectationFailedException( |
|
110 | + sprintf( |
|
111 | + 'Parameter count for invocation %s is too low.', |
|
112 | + $invocation->toString() |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | 116 | |
117 | - foreach ($parameters as $i => $parameter) { |
|
118 | - $parameter->evaluate( |
|
119 | - $invocation->parameters[$i], |
|
120 | - sprintf( |
|
121 | - 'Parameter %s for invocation #%d %s does not match expected ' . |
|
122 | - 'value.', |
|
123 | - $i, |
|
124 | - $callIndex, |
|
125 | - $invocation->toString() |
|
126 | - ) |
|
127 | - ); |
|
128 | - } |
|
129 | - } |
|
117 | + foreach ($parameters as $i => $parameter) { |
|
118 | + $parameter->evaluate( |
|
119 | + $invocation->parameters[$i], |
|
120 | + sprintf( |
|
121 | + 'Parameter %s for invocation #%d %s does not match expected ' . |
|
122 | + 'value.', |
|
123 | + $i, |
|
124 | + $callIndex, |
|
125 | + $invocation->toString() |
|
126 | + ) |
|
127 | + ); |
|
128 | + } |
|
129 | + } |
|
130 | 130 | } |
@@ -118,7 +118,7 @@ |
||
118 | 118 | $parameter->evaluate( |
119 | 119 | $invocation->parameters[$i], |
120 | 120 | sprintf( |
121 | - 'Parameter %s for invocation #%d %s does not match expected ' . |
|
121 | + 'Parameter %s for invocation #%d %s does not match expected '. |
|
122 | 122 | 'value.', |
123 | 123 | $i, |
124 | 124 | $callIndex, |