Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f27bdce

Browse filesBrowse files
bug #25097 [Bridge\PhpUnit] Turn "preserveGlobalState" to false by default, revert "Blacklist" removal (nicolas-grekas)
This PR was merged into the 3.3 branch. Discussion ---------- [Bridge\PhpUnit] Turn "preserveGlobalState" to false by default, revert "Blacklist" removal | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25090 | License | MIT | Doc PR | - This reverts commit 0577d20. And replaces it by a change of the default configuration of the "preserveGlobalState" option of PHPUnit. This option is a thing from the past (pre-Composer ages) that is usually useless, and breaks otherwise. Note that to get the changed default, you must either enable the bridge's listener, or use `simple-phpunit`. Using the original `phpunit` directly will not fix the bad default, and your *isolated tests* will likely break with the new dumped container, now split in several files. Commits ------- e233ba3 [Bridge\PhpUnit] Turn "preserveGlobalState" to false by default, revert "Blacklist" removal
2 parents 1a1079d + e233ba3 commit f27bdce
Copy full SHA for f27bdce

File tree

4 files changed

+32
-60
lines changed
Filter options

4 files changed

+32
-60
lines changed

‎src/Symfony/Bridge/PhpUnit/Blacklist.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/Blacklist.php
-52Lines changed: 0 additions & 52 deletions
This file was deleted.

‎src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php
+18-3Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\AssertionFailedError;
1616
use PHPUnit\Framework\TestCase;
1717
use PHPUnit\Framework\TestSuite;
18+
use PHPUnit\Util\Blacklist;
1819
use Symfony\Bridge\PhpUnit\ClockMock;
1920
use Symfony\Bridge\PhpUnit\DnsMock;
2021

@@ -45,6 +46,14 @@ class SymfonyTestsListenerTrait
4546
*/
4647
public function __construct(array $mockedNamespaces = array())
4748
{
49+
if (class_exists('PHPUnit_Util_Blacklist')) {
50+
\PHPUnit_Util_Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\SymfonyTestsListener'] = 1;
51+
\PHPUnit_Util_Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener'] = 1;
52+
} else {
53+
Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\SymfonyTestsListener'] = 1;
54+
Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener'] = 1;
55+
}
56+
4857
$warn = false;
4958
foreach ($mockedNamespaces as $type => $namespaces) {
5059
if (!is_array($namespaces)) {
@@ -91,7 +100,7 @@ public function globalListenerDisabled()
91100

92101
public function startTestSuite($suite)
93102
{
94-
if (class_exists('PHPUnit_Util_Test', false)) {
103+
if (class_exists('PHPUnit_Util_Blacklist', false)) {
95104
$Test = 'PHPUnit_Util_Test';
96105
} else {
97106
$Test = 'PHPUnit\Util\Test';
@@ -134,6 +143,10 @@ public function startTestSuite($suite)
134143
if (in_array('dns-sensitive', $groups, true)) {
135144
DnsMock::register($test->getName());
136145
}
146+
} elseif (!($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) {
147+
// no-op
148+
} elseif (null === $Test::getPreserveGlobalStateSettings(get_class($test), $test->getName(false))) {
149+
$test->setPreserveGlobalState(false);
137150
}
138151
}
139152
}
@@ -144,6 +157,8 @@ public function startTestSuite($suite)
144157
|| isset($this->wasSkipped[$suiteName]['*'])
145158
|| isset($this->wasSkipped[$suiteName][$test->getName()])) {
146159
$skipped[] = $test;
160+
} elseif (null === $Test::getPreserveGlobalStateSettings(get_class($test), $test->getName(false))) {
161+
$test->setPreserveGlobalState(false);
147162
}
148163
}
149164
$suite->setTests($skipped);
@@ -178,7 +193,7 @@ public function startTest($test)
178193
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$this->runsInSeparateProcess);
179194
}
180195

181-
if (class_exists('PHPUnit_Util_Test', false)) {
196+
if (class_exists('PHPUnit_Util_Blacklist', false)) {
182197
$Test = 'PHPUnit_Util_Test';
183198
$AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError';
184199
} else {
@@ -224,7 +239,7 @@ public function addWarning($test, $e, $time)
224239

225240
public function endTest($test, $time)
226241
{
227-
if (class_exists('PHPUnit_Util_Test', false)) {
242+
if (class_exists('PHPUnit_Util_Blacklist', false)) {
228243
$Test = 'PHPUnit_Util_Test';
229244
$BaseTestRunner = 'PHPUnit_Runner_BaseTestRunner';
230245
$Warning = 'PHPUnit_Framework_Warning';

‎src/Symfony/Bridge/PhpUnit/bin/simple-phpunit

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/bin/simple-phpunit
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
8282
define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
8383
require PHPUNIT_COMPOSER_INSTALL;
8484
85+
if (!class_exists('SymfonyBlacklistPhpunit', false)) {
86+
class SymfonyBlacklistPhpunit {}
87+
}
88+
if (class_exists('PHPUnit_Util_Blacklist')) {
89+
PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
90+
PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
91+
} else {
92+
PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
93+
PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
94+
}
95+
8596
Symfony\Bridge\PhpUnit\TextUI\Command::main();
8697

8798
EOPHP
@@ -200,6 +211,9 @@ if ($components) {
200211
}
201212
}
202213
} elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) {
214+
if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) {
215+
class SymfonyBlacklistSimplePhpunit {}
216+
}
203217
array_splice($argv, 1, 0, array('--colors=always'));
204218
$_SERVER['argv'] = $argv;
205219
$_SERVER['argc'] = ++$argc;

‎src/Symfony/Bridge/PhpUnit/bootstrap.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/bootstrap.php
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
use Doctrine\Common\Annotations\AnnotationRegistry;
1313
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
1414

15-
// Replace the native phpunit Blacklist, it's a broken artifact from the past
16-
if (!class_exists('Symfony\Bridge\PhpUnit\Blacklist', false)) {
17-
require_once __DIR__.'/Blacklist.php';
18-
}
19-
2015
// Detect if we need to serialize deprecations to a file.
2116
if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
2217
DeprecationErrorHandler::collectDeprecations($file);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.