|
75 | 75 | }
|
76 | 76 |
|
77 | 77 | $buffer .= "\n";
|
78 |
| -$buffer .= "if (!\defined('__PHPUNIT_GLOBAL_ASSERT_WRAPPERS__')) {\n"; |
79 | 78 |
|
80 | 79 | foreach ($class->getMethods() as $method) {
|
81 | 80 | if (\strpos($method->getName(), 'assert') !== 0) {
|
|
90 | 89 |
|
91 | 90 | $signature = \str_replace('public static ', '', \trim($lines[$method->getStartLine() - 1]));
|
92 | 91 | $body = "{\n Assert::" . $method->getName() . "(...\\func_get_args());\n}";
|
93 |
| - $buffer .= "$docComment\n$signature\n$body\n\n"; |
| 92 | + |
| 93 | + $buffer .= "if (!function_exists('PHPUnit\Framework\\" . $method->getName() . "')) {\n"; |
| 94 | + $buffer .= "$docComment\n$signature\n$body\n"; |
| 95 | + $buffer .= "}\n\n"; |
94 | 96 | }
|
95 | 97 |
|
96 | 98 | $buffer .= $constraintMethods;
|
97 | 99 |
|
98 |
| -$buffer .= '/** |
99 |
| - * Returns a matcher that matches when the method is executed |
100 |
| - * zero or more times. |
101 |
| - */ |
102 |
| -function any(): AnyInvokedCountMatcher |
103 |
| -{ |
104 |
| - return new AnyInvokedCountMatcher; |
| 100 | +$buffer .= <<<'EOT' |
| 101 | +
|
| 102 | +if (!function_exists('PHPUnit\Framework\any')) { |
| 103 | + /** |
| 104 | + * Returns a matcher that matches when the method is executed |
| 105 | + * zero or more times. |
| 106 | + */ |
| 107 | + function any(): AnyInvokedCountMatcher |
| 108 | + { |
| 109 | + return new AnyInvokedCountMatcher; |
| 110 | + } |
105 | 111 | }
|
106 | 112 |
|
107 |
| -/** |
108 |
| - * Returns a matcher that matches when the method is never executed. |
109 |
| - */ |
110 |
| -function never(): InvokedCountMatcher |
111 |
| -{ |
112 |
| - return new InvokedCountMatcher(0); |
| 113 | +if (!function_exists('PHPUnit\Framework\never')) { |
| 114 | + /** |
| 115 | + * Returns a matcher that matches when the method is never executed. |
| 116 | + */ |
| 117 | + function never(): InvokedCountMatcher |
| 118 | + { |
| 119 | + return new InvokedCountMatcher(0); |
| 120 | + } |
113 | 121 | }
|
114 | 122 |
|
115 |
| -/** |
116 |
| - * Returns a matcher that matches when the method is executed |
117 |
| - * at least N times. |
118 |
| - */ |
119 |
| -function atLeast(int $requiredInvocations): InvokedAtLeastCountMatcher |
120 |
| -{ |
121 |
| - return new InvokedAtLeastCountMatcher( |
122 |
| - $requiredInvocations |
123 |
| - ); |
| 123 | +if (!function_exists('PHPUnit\Framework\atLeast')) { |
| 124 | + /** |
| 125 | + * Returns a matcher that matches when the method is executed |
| 126 | + * at least N times. |
| 127 | + */ |
| 128 | + function atLeast(int $requiredInvocations): InvokedAtLeastCountMatcher |
| 129 | + { |
| 130 | + return new InvokedAtLeastCountMatcher( |
| 131 | + $requiredInvocations |
| 132 | + ); |
| 133 | + } |
124 | 134 | }
|
125 | 135 |
|
126 |
| -/** |
127 |
| - * Returns a matcher that matches when the method is executed at least once. |
128 |
| - */ |
129 |
| -function atLeastOnce(): InvokedAtLeastOnceMatcher |
130 |
| -{ |
131 |
| - return new InvokedAtLeastOnceMatcher; |
| 136 | +if (!function_exists('PHPUnit\Framework\atLeastOnce')) { |
| 137 | + /** |
| 138 | + * Returns a matcher that matches when the method is executed at least once. |
| 139 | + */ |
| 140 | + function atLeastOnce(): InvokedAtLeastOnceMatcher |
| 141 | + { |
| 142 | + return new InvokedAtLeastOnceMatcher; |
| 143 | + } |
132 | 144 | }
|
133 | 145 |
|
134 |
| -/** |
135 |
| - * Returns a matcher that matches when the method is executed exactly once. |
136 |
| - */ |
137 |
| -function once(): InvokedCountMatcher |
138 |
| -{ |
139 |
| - return new InvokedCountMatcher(1); |
| 146 | +if (!function_exists('PHPUnit\Framework\once')) { |
| 147 | + /** |
| 148 | + * Returns a matcher that matches when the method is executed exactly once. |
| 149 | + */ |
| 150 | + function once(): InvokedCountMatcher |
| 151 | + { |
| 152 | + return new InvokedCountMatcher(1); |
| 153 | + } |
140 | 154 | }
|
141 | 155 |
|
142 |
| -/** |
143 |
| - * Returns a matcher that matches when the method is executed |
144 |
| - * exactly $count times. |
145 |
| - */ |
146 |
| -function exactly(int $count): InvokedCountMatcher |
147 |
| -{ |
148 |
| - return new InvokedCountMatcher($count); |
| 156 | +if (!function_exists('PHPUnit\Framework\exactly')) { |
| 157 | + /** |
| 158 | + * Returns a matcher that matches when the method is executed |
| 159 | + * exactly $count times. |
| 160 | + */ |
| 161 | + function exactly(int $count): InvokedCountMatcher |
| 162 | + { |
| 163 | + return new InvokedCountMatcher($count); |
| 164 | + } |
149 | 165 | }
|
150 | 166 |
|
151 |
| -/** |
152 |
| - * Returns a matcher that matches when the method is executed |
153 |
| - * at most N times. |
154 |
| - */ |
155 |
| -function atMost(int $allowedInvocations): InvokedAtMostCountMatcher |
156 |
| -{ |
157 |
| - return new InvokedAtMostCountMatcher($allowedInvocations); |
| 167 | +if (!function_exists('PHPUnit\Framework\atMost')) { |
| 168 | + /** |
| 169 | + * Returns a matcher that matches when the method is executed |
| 170 | + * at most N times. |
| 171 | + */ |
| 172 | + function atMost(int $allowedInvocations): InvokedAtMostCountMatcher |
| 173 | + { |
| 174 | + return new InvokedAtMostCountMatcher($allowedInvocations); |
| 175 | + } |
158 | 176 | }
|
159 | 177 |
|
160 |
| -/** |
161 |
| - * Returns a matcher that matches when the method is executed |
162 |
| - * at the given index. |
163 |
| - */ |
164 |
| -function at(int $index): InvokedAtIndexMatcher |
165 |
| -{ |
166 |
| - return new InvokedAtIndexMatcher($index); |
| 178 | +if (!function_exists('PHPUnit\Framework\at')) { |
| 179 | + /** |
| 180 | + * Returns a matcher that matches when the method is executed |
| 181 | + * at the given index. |
| 182 | + */ |
| 183 | + function at(int $index): InvokedAtIndexMatcher |
| 184 | + { |
| 185 | + return new InvokedAtIndexMatcher($index); |
| 186 | + } |
167 | 187 | }
|
168 | 188 |
|
169 |
| -function returnValue($value): ReturnStub |
170 |
| -{ |
171 |
| - return new ReturnStub($value); |
| 189 | +if (!function_exists('PHPUnit\Framework\returnValue')) { |
| 190 | + function returnValue($value): ReturnStub |
| 191 | + { |
| 192 | + return new ReturnStub($value); |
| 193 | + } |
172 | 194 | }
|
173 | 195 |
|
174 |
| -function returnValueMap(array $valueMap): ReturnValueMapStub |
175 |
| -{ |
176 |
| - return new ReturnValueMapStub($valueMap); |
| 196 | +if (!function_exists('PHPUnit\Framework\returnValueMap')) { |
| 197 | + function returnValueMap(array $valueMap): ReturnValueMapStub |
| 198 | + { |
| 199 | + return new ReturnValueMapStub($valueMap); |
| 200 | + } |
177 | 201 | }
|
178 | 202 |
|
179 |
| -function returnArgument(int $argumentIndex): ReturnArgumentStub |
180 |
| -{ |
181 |
| - return new ReturnArgumentStub($argumentIndex); |
| 203 | +if (!function_exists('PHPUnit\Framework\returnArgument')) { |
| 204 | + function returnArgument(int $argumentIndex): ReturnArgumentStub |
| 205 | + { |
| 206 | + return new ReturnArgumentStub($argumentIndex); |
| 207 | + } |
182 | 208 | }
|
183 | 209 |
|
184 |
| -function returnCallback($callback): ReturnCallbackStub |
185 |
| -{ |
186 |
| - return new ReturnCallbackStub($callback); |
| 210 | +if (!function_exists('PHPUnit\Framework\returnCallback')) { |
| 211 | + function returnCallback($callback): ReturnCallbackStub |
| 212 | + { |
| 213 | + return new ReturnCallbackStub($callback); |
| 214 | + } |
187 | 215 | }
|
188 | 216 |
|
189 |
| -/** |
190 |
| - * Returns the current object. |
191 |
| - * |
192 |
| - * This method is useful when mocking a fluent interface. |
193 |
| - */ |
194 |
| -function returnSelf(): ReturnSelfStub |
195 |
| -{ |
196 |
| - return new ReturnSelfStub; |
| 217 | +if (!function_exists('PHPUnit\Framework\returnSelf')) { |
| 218 | + /** |
| 219 | + * Returns the current object. |
| 220 | + * |
| 221 | + * This method is useful when mocking a fluent interface. |
| 222 | + */ |
| 223 | + function returnSelf(): ReturnSelfStub |
| 224 | + { |
| 225 | + return new ReturnSelfStub; |
| 226 | + } |
197 | 227 | }
|
198 | 228 |
|
199 |
| -function throwException(\Throwable $exception): ExceptionStub |
200 |
| -{ |
201 |
| - return new ExceptionStub($exception); |
| 229 | +if (!function_exists('PHPUnit\Framework\throwException')) { |
| 230 | + function throwException(\Throwable $exception): ExceptionStub |
| 231 | + { |
| 232 | + return new ExceptionStub($exception); |
| 233 | + } |
202 | 234 | }
|
203 | 235 |
|
204 |
| -/** |
205 |
| - * @param mixed $value , ... |
206 |
| - */ |
207 |
| -function onConsecutiveCalls(): ConsecutiveCallsStub |
208 |
| -{ |
209 |
| - $args = \func_get_args(); |
| 236 | +if (!function_exists('PHPUnit\Framework\onConsecutiveCalls')) { |
| 237 | + /** |
| 238 | + * @param mixed $value , ... |
| 239 | + */ |
| 240 | + function onConsecutiveCalls(): ConsecutiveCallsStub |
| 241 | + { |
| 242 | + $args = \func_get_args(); |
210 | 243 |
|
211 |
| - return new ConsecutiveCallsStub($args); |
| 244 | + return new ConsecutiveCallsStub($args); |
| 245 | + } |
212 | 246 | }
|
213 |
| -'; |
214 | 247 |
|
215 |
| -$buffer .= "\ndefine('__PHPUNIT_GLOBAL_ASSERT_WRAPPERS__', true);\n}"; |
| 248 | +EOT; |
216 | 249 |
|
217 | 250 | \file_put_contents(__DIR__ . '/../../src/Framework/Assert/Functions.php', $buffer);
|
0 commit comments