Skip to content

Commit a1d0515

Browse files
Closes #4435
1 parent 6548126 commit a1d0515

File tree

3 files changed

+604
-265
lines changed

3 files changed

+604
-265
lines changed

ChangeLog-9.3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 9.3 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [9.3.8] - 2020-MM-DD
6+
7+
### Fixed
8+
9+
* [#4435](https://github.com/sebastianbergmann/phpunit/issues/4435): Global assert wrappers break preloading
10+
511
## [9.3.7] - 2020-08-11
612

713
### Fixed
@@ -219,6 +225,7 @@ If you have an XML configuration file that validates against [PHPUnit 9.2's XML
219225
* [#4396](https://github.com/sebastianbergmann/phpunit/issues/4396): Deprecate confusing parameter options for XML assertions
220226
* The `cacheTokens` attribute is no longer supported in XML configuration files
221227

228+
[9.3.8]: https://github.com/sebastianbergmann/phpunit/compare/9.3.7...9.3
222229
[9.3.7]: https://github.com/sebastianbergmann/phpunit/compare/9.3.6...9.3.7
223230
[9.3.6]: https://github.com/sebastianbergmann/phpunit/compare/9.3.5...9.3.6
224231
[9.3.5]: https://github.com/sebastianbergmann/phpunit/compare/9.3.4...9.3.5

build/scripts/generate-global-assert-wrappers.php

Lines changed: 122 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
}
7676

7777
$buffer .= "\n";
78-
$buffer .= "if (!\defined('__PHPUNIT_GLOBAL_ASSERT_WRAPPERS__')) {\n";
7978

8079
foreach ($class->getMethods() as $method) {
8180
if (\strpos($method->getName(), 'assert') !== 0) {
@@ -90,128 +89,162 @@
9089

9190
$signature = \str_replace('public static ', '', \trim($lines[$method->getStartLine() - 1]));
9291
$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";
9496
}
9597

9698
$buffer .= $constraintMethods;
9799

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+
}
105111
}
106112
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+
}
113121
}
114122
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+
}
124134
}
125135
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+
}
132144
}
133145
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+
}
140154
}
141155
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+
}
149165
}
150166
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+
}
158176
}
159177
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+
}
167187
}
168188
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+
}
172194
}
173195
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+
}
177201
}
178202
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+
}
182208
}
183209
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+
}
187215
}
188216
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+
}
197227
}
198228
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+
}
202234
}
203235
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();
210243
211-
return new ConsecutiveCallsStub($args);
244+
return new ConsecutiveCallsStub($args);
245+
}
212246
}
213-
';
214247

215-
$buffer .= "\ndefine('__PHPUNIT_GLOBAL_ASSERT_WRAPPERS__', true);\n}";
248+
EOT;
216249

217250
\file_put_contents(__DIR__ . '/../../src/Framework/Assert/Functions.php', $buffer);

0 commit comments

Comments
 (0)