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 commit0577d20ade
. 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
This commit is contained in:
commit
f27bdcec17
@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PhpUnit;
|
||||
|
||||
/**
|
||||
* Utility class replacing PHPUnit's implementation of the same class.
|
||||
*
|
||||
* All files are blacklisted so that process-isolated tests don't start with broken
|
||||
* "require_once" statements. Composer is the only supported way to load code there.
|
||||
*/
|
||||
class Blacklist
|
||||
{
|
||||
public static $blacklistedClassNames = array();
|
||||
|
||||
public function getBlacklistedDirectories()
|
||||
{
|
||||
$blacklist = array();
|
||||
|
||||
foreach (get_declared_classes() as $class) {
|
||||
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
|
||||
$r = new \ReflectionClass($class);
|
||||
$v = dirname(dirname($r->getFileName()));
|
||||
if (file_exists($v.'/composer/installed.json')) {
|
||||
$blacklist[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $blacklist;
|
||||
}
|
||||
|
||||
public function isBlacklisted($file)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (class_exists('PHPUnit\Util\Test')) {
|
||||
class_alias('Symfony\Bridge\PhpUnit\Blacklist', 'PHPUnit\Util\Blacklist');
|
||||
}
|
||||
if (class_exists('PHPUnit_Util_Test')) {
|
||||
class_alias('Symfony\Bridge\PhpUnit\Blacklist', 'PHPUnit_Util_Blacklist');
|
||||
}
|
@ -15,6 +15,7 @@ use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
use PHPUnit\Framework\AssertionFailedError;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\TestSuite;
|
||||
use PHPUnit\Util\Blacklist;
|
||||
use Symfony\Bridge\PhpUnit\ClockMock;
|
||||
use Symfony\Bridge\PhpUnit\DnsMock;
|
||||
|
||||
@ -45,6 +46,14 @@ class SymfonyTestsListenerTrait
|
||||
*/
|
||||
public function __construct(array $mockedNamespaces = array())
|
||||
{
|
||||
if (class_exists('PHPUnit_Util_Blacklist')) {
|
||||
\PHPUnit_Util_Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\SymfonyTestsListener'] = 1;
|
||||
\PHPUnit_Util_Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener'] = 1;
|
||||
} else {
|
||||
Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\SymfonyTestsListener'] = 1;
|
||||
Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener'] = 1;
|
||||
}
|
||||
|
||||
$warn = false;
|
||||
foreach ($mockedNamespaces as $type => $namespaces) {
|
||||
if (!is_array($namespaces)) {
|
||||
@ -91,7 +100,7 @@ class SymfonyTestsListenerTrait
|
||||
|
||||
public function startTestSuite($suite)
|
||||
{
|
||||
if (class_exists('PHPUnit_Util_Test', false)) {
|
||||
if (class_exists('PHPUnit_Util_Blacklist', false)) {
|
||||
$Test = 'PHPUnit_Util_Test';
|
||||
} else {
|
||||
$Test = 'PHPUnit\Util\Test';
|
||||
@ -134,6 +143,10 @@ class SymfonyTestsListenerTrait
|
||||
if (in_array('dns-sensitive', $groups, true)) {
|
||||
DnsMock::register($test->getName());
|
||||
}
|
||||
} elseif (!($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) {
|
||||
// no-op
|
||||
} elseif (null === $Test::getPreserveGlobalStateSettings(get_class($test), $test->getName(false))) {
|
||||
$test->setPreserveGlobalState(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -144,6 +157,8 @@ class SymfonyTestsListenerTrait
|
||||
|| isset($this->wasSkipped[$suiteName]['*'])
|
||||
|| isset($this->wasSkipped[$suiteName][$test->getName()])) {
|
||||
$skipped[] = $test;
|
||||
} elseif (null === $Test::getPreserveGlobalStateSettings(get_class($test), $test->getName(false))) {
|
||||
$test->setPreserveGlobalState(false);
|
||||
}
|
||||
}
|
||||
$suite->setTests($skipped);
|
||||
@ -178,7 +193,7 @@ class SymfonyTestsListenerTrait
|
||||
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$this->runsInSeparateProcess);
|
||||
}
|
||||
|
||||
if (class_exists('PHPUnit_Util_Test', false)) {
|
||||
if (class_exists('PHPUnit_Util_Blacklist', false)) {
|
||||
$Test = 'PHPUnit_Util_Test';
|
||||
$AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError';
|
||||
} else {
|
||||
@ -224,7 +239,7 @@ class SymfonyTestsListenerTrait
|
||||
|
||||
public function endTest($test, $time)
|
||||
{
|
||||
if (class_exists('PHPUnit_Util_Test', false)) {
|
||||
if (class_exists('PHPUnit_Util_Blacklist', false)) {
|
||||
$Test = 'PHPUnit_Util_Test';
|
||||
$BaseTestRunner = 'PHPUnit_Runner_BaseTestRunner';
|
||||
$Warning = 'PHPUnit_Framework_Warning';
|
||||
|
@ -82,6 +82,17 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
|
||||
define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
|
||||
require PHPUNIT_COMPOSER_INSTALL;
|
||||
|
||||
if (!class_exists('SymfonyBlacklistPhpunit', false)) {
|
||||
class SymfonyBlacklistPhpunit {}
|
||||
}
|
||||
if (class_exists('PHPUnit_Util_Blacklist')) {
|
||||
PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
|
||||
PHPUnit_Util_Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
|
||||
} else {
|
||||
PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistPhpunit'] = 1;
|
||||
PHPUnit\Util\Blacklist::$blacklistedClassNames['SymfonyBlacklistSimplePhpunit'] = 1;
|
||||
}
|
||||
|
||||
Symfony\Bridge\PhpUnit\TextUI\Command::main();
|
||||
|
||||
EOPHP
|
||||
@ -200,6 +211,9 @@ if ($components) {
|
||||
}
|
||||
}
|
||||
} elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) {
|
||||
if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) {
|
||||
class SymfonyBlacklistSimplePhpunit {}
|
||||
}
|
||||
array_splice($argv, 1, 0, array('--colors=always'));
|
||||
$_SERVER['argv'] = $argv;
|
||||
$_SERVER['argc'] = ++$argc;
|
||||
|
@ -12,11 +12,6 @@
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
|
||||
|
||||
// Replace the native phpunit Blacklist, it's a broken artifact from the past
|
||||
if (!class_exists('Symfony\Bridge\PhpUnit\Blacklist', false)) {
|
||||
require_once __DIR__.'/Blacklist.php';
|
||||
}
|
||||
|
||||
// Detect if we need to serialize deprecations to a file.
|
||||
if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
|
||||
DeprecationErrorHandler::collectDeprecations($file);
|
||||
|
Reference in New Issue
Block a user