Merge branch '3.3' into 3.4
* 3.3: [Bridge\PhpUnit] Turn "preserveGlobalState" to false by default, revert "Blacklist" removal
This commit is contained in:
commit
125934a7e8
@ -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';
|
||||
|
@ -98,6 +98,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
|
||||
@ -216,6 +227,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