[Bridge\PhpUnit] Turn "preserveGlobalState" to false by default, revert "Blacklist" removal
This reverts commit 0577d20ade
.
This commit is contained in:
parent
1a1079d7c4
commit
e233ba3a3f
@ -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\AssertionFailedError;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\TestSuite;
|
use PHPUnit\Framework\TestSuite;
|
||||||
|
use PHPUnit\Util\Blacklist;
|
||||||
use Symfony\Bridge\PhpUnit\ClockMock;
|
use Symfony\Bridge\PhpUnit\ClockMock;
|
||||||
use Symfony\Bridge\PhpUnit\DnsMock;
|
use Symfony\Bridge\PhpUnit\DnsMock;
|
||||||
|
|
||||||
@ -45,6 +46,14 @@ class SymfonyTestsListenerTrait
|
|||||||
*/
|
*/
|
||||||
public function __construct(array $mockedNamespaces = array())
|
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;
|
$warn = false;
|
||||||
foreach ($mockedNamespaces as $type => $namespaces) {
|
foreach ($mockedNamespaces as $type => $namespaces) {
|
||||||
if (!is_array($namespaces)) {
|
if (!is_array($namespaces)) {
|
||||||
@ -91,7 +100,7 @@ class SymfonyTestsListenerTrait
|
|||||||
|
|
||||||
public function startTestSuite($suite)
|
public function startTestSuite($suite)
|
||||||
{
|
{
|
||||||
if (class_exists('PHPUnit_Util_Test', false)) {
|
if (class_exists('PHPUnit_Util_Blacklist', false)) {
|
||||||
$Test = 'PHPUnit_Util_Test';
|
$Test = 'PHPUnit_Util_Test';
|
||||||
} else {
|
} else {
|
||||||
$Test = 'PHPUnit\Util\Test';
|
$Test = 'PHPUnit\Util\Test';
|
||||||
@ -134,6 +143,10 @@ class SymfonyTestsListenerTrait
|
|||||||
if (in_array('dns-sensitive', $groups, true)) {
|
if (in_array('dns-sensitive', $groups, true)) {
|
||||||
DnsMock::register($test->getName());
|
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]['*'])
|
||||||
|| isset($this->wasSkipped[$suiteName][$test->getName()])) {
|
|| isset($this->wasSkipped[$suiteName][$test->getName()])) {
|
||||||
$skipped[] = $test;
|
$skipped[] = $test;
|
||||||
|
} elseif (null === $Test::getPreserveGlobalStateSettings(get_class($test), $test->getName(false))) {
|
||||||
|
$test->setPreserveGlobalState(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$suite->setTests($skipped);
|
$suite->setTests($skipped);
|
||||||
@ -178,7 +193,7 @@ class SymfonyTestsListenerTrait
|
|||||||
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$this->runsInSeparateProcess);
|
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$this->runsInSeparateProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (class_exists('PHPUnit_Util_Test', false)) {
|
if (class_exists('PHPUnit_Util_Blacklist', false)) {
|
||||||
$Test = 'PHPUnit_Util_Test';
|
$Test = 'PHPUnit_Util_Test';
|
||||||
$AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError';
|
$AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError';
|
||||||
} else {
|
} else {
|
||||||
@ -224,7 +239,7 @@ class SymfonyTestsListenerTrait
|
|||||||
|
|
||||||
public function endTest($test, $time)
|
public function endTest($test, $time)
|
||||||
{
|
{
|
||||||
if (class_exists('PHPUnit_Util_Test', false)) {
|
if (class_exists('PHPUnit_Util_Blacklist', false)) {
|
||||||
$Test = 'PHPUnit_Util_Test';
|
$Test = 'PHPUnit_Util_Test';
|
||||||
$BaseTestRunner = 'PHPUnit_Runner_BaseTestRunner';
|
$BaseTestRunner = 'PHPUnit_Runner_BaseTestRunner';
|
||||||
$Warning = 'PHPUnit_Framework_Warning';
|
$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');
|
define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
|
||||||
require PHPUNIT_COMPOSER_INSTALL;
|
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();
|
Symfony\Bridge\PhpUnit\TextUI\Command::main();
|
||||||
|
|
||||||
EOPHP
|
EOPHP
|
||||||
@ -200,6 +211,9 @@ if ($components) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) {
|
} 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'));
|
array_splice($argv, 1, 0, array('--colors=always'));
|
||||||
$_SERVER['argv'] = $argv;
|
$_SERVER['argv'] = $argv;
|
||||||
$_SERVER['argc'] = ++$argc;
|
$_SERVER['argc'] = ++$argc;
|
||||||
|
@ -12,11 +12,6 @@
|
|||||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||||
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
|
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.
|
// Detect if we need to serialize deprecations to a file.
|
||||||
if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
|
if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
|
||||||
DeprecationErrorHandler::collectDeprecations($file);
|
DeprecationErrorHandler::collectDeprecations($file);
|
||||||
|
Reference in New Issue
Block a user