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 146cefd

Browse filesBrowse files
bug #25032 [Bridge\PhpUnit] Disable broken auto-require mechanism of phpunit (nicolas-grekas)
This PR was merged into the 3.3 branch. Discussion ---------- [Bridge\PhpUnit] Disable broken auto-require mechanism of phpunit | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25017 | License | MIT | Doc PR | - It took me all the flight back from Cluj to figure out this is the only way to solve this nasty issue created by phpunit generating inlined `require_once` in the global scope for isolated tests. This mechanism predates the autoloading mechanism, and it's behavior is just hardcoded. Needs to be merged in 3.4, where the split container triggers this situation very quickly. Will allow removing the `function_exists('__phpunit_run_isolated_test')` workarounds already in place in the code base (2.7 up to master.) Commits ------- 0577d20 [Bridge\PhpUnit] Disable broken auto-require mechanism of phpunit
2 parents 3b6c22e + 0577d20 commit 146cefd
Copy full SHA for 146cefd

File tree

4 files changed

+47
-29
lines changed
Filter options

4 files changed

+47
-29
lines changed
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit;
13+
14+
/**
15+
* Utility class replacing PHPUnit's implementation of the same class.
16+
*
17+
* All files are blacklisted so that process-isolated tests don't start with broken
18+
* "require_once" statements. Composer is the only supported way to load code there.
19+
*/
20+
class Blacklist
21+
{
22+
public static $blacklistedClassNames = array();
23+
24+
public function getBlacklistedDirectories()
25+
{
26+
$root = dirname(__DIR__);
27+
while ($root !== $parent = dirname($root)) {
28+
$root = $parent;
29+
}
30+
31+
return array($root);
32+
}
33+
34+
public function isBlacklisted($file)
35+
{
36+
return true;
37+
}
38+
}
39+
40+
class_alias('Symfony\Bridge\PhpUnit\Blacklist', 'PHPUnit\Util\Blacklist');
41+
class_alias('Symfony\Bridge\PhpUnit\Blacklist', 'PHPUnit_Util_Blacklist');

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

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

@@ -46,17 +45,6 @@ class SymfonyTestsListenerTrait
4645
*/
4746
public function __construct(array $mockedNamespaces = array())
4847
{
49-
if (class_exists('PHPUnit_Util_Blacklist')) {
50-
\PHPUnit_Util_Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\DeprecationErrorHandler'] = 1;
51-
\PHPUnit_Util_Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\SymfonyTestsListener'] = 1;
52-
\PHPUnit_Util_Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener'] = 1;
53-
\PHPUnit_Util_Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait'] = 1;
54-
} else {
55-
Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\DeprecationErrorHandler'] = 1;
56-
Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\SymfonyTestsListener'] = 1;
57-
Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait'] = 1;
58-
}
59-
6048
$warn = false;
6149
foreach ($mockedNamespaces as $type => $namespaces) {
6250
if (!is_array($namespaces)) {
@@ -103,7 +91,7 @@ public function globalListenerDisabled()
10391

10492
public function startTestSuite($suite)
10593
{
106-
if (class_exists('PHPUnit_Util_Blacklist', false)) {
94+
if (class_exists('PHPUnit_Util_Test', false)) {
10795
$Test = 'PHPUnit_Util_Test';
10896
} else {
10997
$Test = 'PHPUnit\Util\Test';
@@ -190,7 +178,7 @@ public function startTest($test)
190178
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$this->runsInSeparateProcess);
191179
}
192180

193-
if (class_exists('PHPUnit_Util_Blacklist', false)) {
181+
if (class_exists('PHPUnit_Util_Test', false)) {
194182
$Test = 'PHPUnit_Util_Test';
195183
$AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError';
196184
} else {
@@ -236,7 +224,7 @@ public function addWarning($test, $e, $time)
236224

237225
public function endTest($test, $time)
238226
{
239-
if (class_exists('PHPUnit_Util_Blacklist', false)) {
227+
if (class_exists('PHPUnit_Util_Test', false)) {
240228
$Test = 'PHPUnit_Util_Test';
241229
$BaseTestRunner = 'PHPUnit_Runner_BaseTestRunner';
242230
$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: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,6 @@ 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-
9685
Symfony\Bridge\PhpUnit\TextUI\Command::main();
9786

9887
EOPHP
@@ -211,9 +200,6 @@ if ($components) {
211200
}
212201
}
213202
} elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) {
214-
if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) {
215-
class SymfonyBlacklistSimplePhpunit {}
216-
}
217203
array_splice($argv, 1, 0, array('--colors=always'));
218204
$_SERVER['argv'] = $argv;
219205
$_SERVER['argc'] = ++$argc;

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/bootstrap.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
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+
require_once __DIR__.'/Blacklist.php';
17+
1518
// Detect if we need to serialize deprecations to a file.
1619
if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
1720
DeprecationErrorHandler::collectDeprecations($file);

0 commit comments

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