[PhpUnitBridge] bump "php" to 7.1+ and "phpunit" to 7.5+

This commit is contained in:
Nicolas Grekas 2020-12-09 20:07:39 +01:00
parent 266a6bb97e
commit fe24f73ec0
28 changed files with 59 additions and 675 deletions

View File

@ -1,6 +1,12 @@
CHANGELOG CHANGELOG
========= =========
5.3.0
-----
* bumped the minimum PHP version to 7.1.3
* bumped the minimum PHPUnit version to 7.5
5.1.0 5.1.0
----- -----

View File

@ -45,7 +45,7 @@ class ClassExistsMock
public static function register($class) public static function register($class)
{ {
$self = \get_called_class(); $self = static::class;
$mockedNs = [substr($class, 0, strrpos($class, '\\'))]; $mockedNs = [substr($class, 0, strrpos($class, '\\'))];
if (0 < strpos($class, '\\Tests\\')) { if (0 < strpos($class, '\\Tests\\')) {

View File

@ -92,7 +92,7 @@ class ClockMock
public static function register($class) public static function register($class)
{ {
$self = \get_called_class(); $self = static::class;
$mockedNs = [substr($class, 0, strrpos($class, '\\'))]; $mockedNs = [substr($class, 0, strrpos($class, '\\'))];
if (0 < strpos($class, '\\Tests\\')) { if (0 < strpos($class, '\\Tests\\')) {

View File

@ -15,12 +15,7 @@ use PHPUnit\Framework\Constraint\Constraint;
use ReflectionClass; use ReflectionClass;
$r = new ReflectionClass(Constraint::class); $r = new ReflectionClass(Constraint::class);
if (\PHP_VERSION_ID < 70000 || !$r->getMethod('matches')->hasReturnType()) { if ($r->getProperty('exporter')->isProtected()) {
trait ConstraintTrait
{
use Legacy\ConstraintTraitForV6;
}
} elseif ($r->getProperty('exporter')->isProtected()) {
trait ConstraintTrait trait ConstraintTrait
{ {
use Legacy\ConstraintTraitForV7; use Legacy\ConstraintTraitForV7;

View File

@ -11,13 +11,7 @@
namespace Symfony\Bridge\PhpUnit; namespace Symfony\Bridge\PhpUnit;
if (version_compare(\PHPUnit\Runner\Version::id(), '6.0.0', '<')) { class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListenerForV7', 'Symfony\Bridge\PhpUnit\CoverageListener');
class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListenerForV5', 'Symfony\Bridge\PhpUnit\CoverageListener');
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListenerForV6', 'Symfony\Bridge\PhpUnit\CoverageListener');
} else {
class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListenerForV7', 'Symfony\Bridge\PhpUnit\CoverageListener');
}
if (false) { if (false) {
class CoverageListener class CoverageListener

View File

@ -25,9 +25,9 @@ use Symfony\Component\ErrorHandler\DebugClassLoader;
*/ */
class DeprecationErrorHandler class DeprecationErrorHandler
{ {
const MODE_DISABLED = 'disabled'; public const MODE_DISABLED = 'disabled';
const MODE_WEAK = 'max[total]=999999&verbose=0'; public const MODE_WEAK = 'max[total]=999999&verbose=0';
const MODE_STRICT = 'max[total]=0'; public const MODE_STRICT = 'max[total]=0';
private $mode; private $mode;
private $configuration; private $configuration;
@ -238,13 +238,7 @@ class DeprecationErrorHandler
return $this->configuration; return $this->configuration;
} }
if (false === $mode = $this->mode) { if (false === $mode = $this->mode) {
if (isset($_SERVER['SYMFONY_DEPRECATIONS_HELPER'])) { $mode = $_SERVER['SYMFONY_DEPRECATIONS_HELPER'] ?? $_ENV['SYMFONY_DEPRECATIONS_HELPER'] ?? getenv('SYMFONY_DEPRECATIONS_HELPER');
$mode = $_SERVER['SYMFONY_DEPRECATIONS_HELPER'];
} elseif (isset($_ENV['SYMFONY_DEPRECATIONS_HELPER'])) {
$mode = $_ENV['SYMFONY_DEPRECATIONS_HELPER'];
} else {
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
}
} }
if ('strict' === $mode) { if ('strict' === $mode) {
return $this->configuration = Configuration::inStrictMode(); return $this->configuration = Configuration::inStrictMode();

View File

@ -278,7 +278,7 @@ class Configuration
} }
return new self( return new self(
isset($normalizedConfiguration['max']) ? $normalizedConfiguration['max'] : [], $normalizedConfiguration['max'] ?? [],
'', '',
$verboseOutput, $verboseOutput,
filter_var($normalizedConfiguration['generateBaseline'], \FILTER_VALIDATE_BOOLEAN), filter_var($normalizedConfiguration['generateBaseline'], \FILTER_VALIDATE_BOOLEAN),

View File

@ -21,14 +21,14 @@ use Symfony\Component\ErrorHandler\DebugClassLoader;
*/ */
class Deprecation class Deprecation
{ {
const PATH_TYPE_VENDOR = 'path_type_vendor'; public const PATH_TYPE_VENDOR = 'path_type_vendor';
const PATH_TYPE_SELF = 'path_type_internal'; public const PATH_TYPE_SELF = 'path_type_internal';
const PATH_TYPE_UNDETERMINED = 'path_type_undetermined'; public const PATH_TYPE_UNDETERMINED = 'path_type_undetermined';
const TYPE_SELF = 'type_self'; public const TYPE_SELF = 'type_self';
const TYPE_DIRECT = 'type_direct'; public const TYPE_DIRECT = 'type_direct';
const TYPE_INDIRECT = 'type_indirect'; public const TYPE_INDIRECT = 'type_indirect';
const TYPE_UNDETERMINED = 'type_undetermined'; public const TYPE_UNDETERMINED = 'type_undetermined';
private $trace = []; private $trace = [];
private $message; private $message;
@ -61,10 +61,10 @@ class Deprecation
$this->trace = $trace; $this->trace = $trace;
if ('trigger_error' === (isset($trace[1]['function']) ? $trace[1]['function'] : null) if ('trigger_error' === ($trace[1]['function'] ?? null)
&& (DebugClassLoader::class === ($class = (isset($trace[2]['class']) ? $trace[2]['class'] : null)) || LegacyDebugClassLoader::class === $class) && (DebugClassLoader::class === ($class = $trace[2]['class'] ?? null) || LegacyDebugClassLoader::class === $class)
&& 'checkClass' === (isset($trace[2]['function']) ? $trace[2]['function'] : null) && 'checkClass' === ($trace[2]['function'] ?? null)
&& null !== ($extraFile = (isset($trace[2]['args'][1]) ? $trace[2]['args'][1] : null)) && null !== ($extraFile = $trace[2]['args'][1] ?? null)
&& '' !== $extraFile && '' !== $extraFile
&& false !== $extraFile = realpath($extraFile) && false !== $extraFile = realpath($extraFile)
) { ) {
@ -118,7 +118,7 @@ class Deprecation
} }
$class = $line['class']; $class = $line['class'];
return 'ReflectionMethod' === $class || 0 === strpos($class, 'PHPUnit_') || 0 === strpos($class, 'PHPUnit\\'); return 'ReflectionMethod' === $class || 0 === strpos($class, 'PHPUnit\\');
} }
/** /**
@ -290,7 +290,7 @@ class Deprecation
foreach (get_declared_classes() as $class) { foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) { if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class); $r = new \ReflectionClass($class);
$v = \dirname(\dirname($r->getFileName())); $v = \dirname($r->getFileName(), 2);
if (file_exists($v.'/composer/installed.json')) { if (file_exists($v.'/composer/installed.json')) {
self::$vendors[] = $v; self::$vendors[] = $v;
$loader = require $v.'/autoload.php'; $loader = require $v.'/autoload.php';

View File

@ -55,11 +55,7 @@ final class DeprecationGroup
*/ */
private function deprecationNotice($message) private function deprecationNotice($message)
{ {
if (!isset($this->deprecationNotices[$message])) { return $this->deprecationNotices[$message] ?? $this->deprecationNotices[$message] = new DeprecationNotice();
$this->deprecationNotices[$message] = new DeprecationNotice();
}
return $this->deprecationNotices[$message];
} }
public function count() public function count()

View File

@ -152,7 +152,7 @@ class DnsMock
$records = []; $records = [];
foreach (self::$hosts[$hostname] as $record) { foreach (self::$hosts[$hostname] as $record) {
if (isset(self::$dnsTypes[$record['type']]) && (self::$dnsTypes[$record['type']] & $type)) { if ((self::$dnsTypes[$record['type']] ?? 0) & $type) {
$records[] = array_merge(['host' => $hostname, 'class' => 'IN', 'ttl' => 1, 'type' => $record['type']], $record); $records[] = array_merge(['host' => $hostname, 'class' => 'IN', 'ttl' => 1, 'type' => $record['type']], $record);
} }
} }
@ -163,7 +163,7 @@ class DnsMock
public static function register($class) public static function register($class)
{ {
$self = \get_called_class(); $self = static::class;
$mockedNs = [substr($class, 0, strrpos($class, '\\'))]; $mockedNs = [substr($class, 0, strrpos($class, '\\'))];
if (0 < strpos($class, '\\Tests\\')) { if (0 < strpos($class, '\\Tests\\')) {

View File

@ -1,57 +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\Legacy;
/**
* {@inheritdoc}
*
* @internal
*/
class CommandForV5 extends \PHPUnit_TextUI_Command
{
/**
* {@inheritdoc}
*/
protected function createRunner()
{
$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : [];
$registeredLocally = false;
foreach ($this->arguments['listeners'] as $registeredListener) {
if ($registeredListener instanceof SymfonyTestsListenerForV5) {
$registeredListener->globalListenerDisabled();
$registeredLocally = true;
break;
}
}
if (isset($this->arguments['configuration'])) {
$configuration = $this->arguments['configuration'];
if (!$configuration instanceof \PHPUnit_Util_Configuration) {
$configuration = \PHPUnit_Util_Configuration::getInstance($this->arguments['configuration']);
}
foreach ($configuration->getListenerConfiguration() as $registeredListener) {
if ('Symfony\Bridge\PhpUnit\SymfonyTestsListener' === ltrim($registeredListener['class'], '\\')) {
$registeredLocally = true;
break;
}
}
}
if (!$registeredLocally) {
$this->arguments['listeners'][] = new SymfonyTestsListenerForV5();
}
return parent::createRunner();
}
}

View File

@ -21,14 +21,14 @@ use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
* *
* @internal * @internal
*/ */
class CommandForV6 extends BaseCommand class CommandForV7 extends BaseCommand
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function createRunner(): BaseRunner protected function createRunner(): BaseRunner
{ {
$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : []; $this->arguments['listeners'] ?? $this->arguments['listeners'] = [];
$registeredLocally = false; $registeredLocally = false;

View File

@ -31,7 +31,7 @@ class CommandForV9 extends BaseCommand
*/ */
protected function createRunner(): BaseRunner protected function createRunner(): BaseRunner
{ {
$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : []; $this->arguments['listeners'] ?? $this->arguments['listeners'] = [];
$registeredLocally = false; $registeredLocally = false;

View File

@ -1,130 +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\Legacy;
use SebastianBergmann\Exporter\Exporter;
/**
* @internal
*/
trait ConstraintTraitForV6
{
/**
* @return bool|null
*/
public function evaluate($other, $description = '', $returnResult = false)
{
return $this->doEvaluate($other, $description, $returnResult);
}
/**
* @return int
*/
public function count()
{
return $this->doCount();
}
/**
* @return string
*/
public function toString()
{
return $this->doToString();
}
/**
* @param mixed $other
*
* @return string
*/
protected function additionalFailureDescription($other)
{
return $this->doAdditionalFailureDescription($other);
}
/**
* @return Exporter
*/
protected function exporter()
{
if (null === $this->exporter) {
$this->exporter = new Exporter();
}
return $this->exporter;
}
/**
* @param mixed $other
*
* @return string
*/
protected function failureDescription($other)
{
return $this->doFailureDescription($other);
}
/**
* @param mixed $other
*
* @return bool
*/
protected function matches($other)
{
return $this->doMatches($other);
}
private function doAdditionalFailureDescription($other)
{
return '';
}
private function doCount()
{
return 1;
}
private function doEvaluate($other, $description, $returnResult)
{
$success = false;
if ($this->matches($other)) {
$success = true;
}
if ($returnResult) {
return $success;
}
if (!$success) {
$this->fail($other, $description);
}
return null;
}
private function doFailureDescription($other)
{
return $this->exporter()->export($other).' '.$this->toString();
}
private function doMatches($other)
{
return false;
}
private function doToString()
{
return '';
}
}

View File

@ -1,35 +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\Legacy;
/**
* CoverageListener adds `@covers <className>` on each test when possible to
* make the code coverage more accurate.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @internal
*/
class CoverageListenerForV5 extends \PHPUnit_Framework_BaseTestListener
{
private $trait;
public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFound = false)
{
$this->trait = new CoverageListenerTrait($sutFqcnResolver, $warningOnSutNotFound);
}
public function startTest(\PHPUnit_Framework_Test $test)
{
$this->trait->startTest($test);
}
}

View File

@ -1,41 +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\Legacy;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
/**
* CoverageListener adds `@covers <className>` on each test when possible to
* make the code coverage more accurate.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @internal
*/
class CoverageListenerForV6 implements TestListener
{
use TestListenerDefaultImplementation;
private $trait;
public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFound = false)
{
$this->trait = new CoverageListenerTrait($sutFqcnResolver, $warningOnSutNotFound);
}
public function startTest(Test $test)
{
$this->trait->startTest($test);
}
}

View File

@ -1,70 +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\Legacy;
/**
* @internal
*/
trait SetUpTearDownTraitForV5
{
/**
* @return void
*/
public static function setUpBeforeClass()
{
self::doSetUpBeforeClass();
}
/**
* @return void
*/
public static function tearDownAfterClass()
{
self::doTearDownAfterClass();
}
/**
* @return void
*/
protected function setUp()
{
self::doSetUp();
}
/**
* @return void
*/
protected function tearDown()
{
self::doTearDown();
}
private static function doSetUpBeforeClass()
{
parent::setUpBeforeClass();
}
private static function doTearDownAfterClass()
{
parent::tearDownAfterClass();
}
private function doSetUp()
{
parent::setUp();
}
private function doTearDown()
{
parent::tearDown();
}
}

View File

@ -1,54 +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\Legacy;
/**
* Collects and replays skipped tests.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
class SymfonyTestsListenerForV5 extends \PHPUnit_Framework_BaseTestListener
{
private $trait;
public function __construct(array $mockedNamespaces = [])
{
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
}
public function globalListenerDisabled()
{
$this->trait->globalListenerDisabled();
}
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
{
$this->trait->startTestSuite($suite);
}
public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
{
$this->trait->addSkippedTest($test, $e, $time);
}
public function startTest(\PHPUnit_Framework_Test $test)
{
$this->trait->startTest($test);
}
public function endTest(\PHPUnit_Framework_Test $test, $time)
{
$this->trait->endTest($test, $time);
}
}

View File

@ -1,58 +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\Legacy;
use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestSuite;
/**
* Collects and replays skipped tests.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
class SymfonyTestsListenerForV6 extends BaseTestListener
{
private $trait;
public function __construct(array $mockedNamespaces = [])
{
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
}
public function globalListenerDisabled()
{
$this->trait->globalListenerDisabled();
}
public function startTestSuite(TestSuite $suite)
{
$this->trait->startTestSuite($suite);
}
public function addSkippedTest(Test $test, \Exception $e, $time)
{
$this->trait->addSkippedTest($test, $e, $time);
}
public function startTest(Test $test)
{
$this->trait->startTest($test);
}
public function endTest(Test $test, $time)
{
$this->trait->endTest($test, $time);
}
}

View File

@ -123,7 +123,7 @@ class SymfonyTestsListenerTrait
$suiteName = $suite->getName(); $suiteName = $suite->getName();
foreach ($suite->tests() as $test) { foreach ($suite->tests() as $test) {
if (!($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) { if (!$test instanceof TestCase) {
continue; continue;
} }
if (null === Test::getPreserveGlobalStateSettings(\get_class($test), $test->getName(false))) { if (null === Test::getPreserveGlobalStateSettings(\get_class($test), $test->getName(false))) {
@ -158,7 +158,7 @@ class SymfonyTestsListenerTrait
$testSuites = [$suite]; $testSuites = [$suite];
for ($i = 0; isset($testSuites[$i]); ++$i) { for ($i = 0; isset($testSuites[$i]); ++$i) {
foreach ($testSuites[$i]->tests() as $test) { foreach ($testSuites[$i]->tests() as $test) {
if ($test instanceof \PHPUnit_Framework_TestSuite || $test instanceof TestSuite) { if ($test instanceof TestSuite) {
if (!class_exists($test->getName(), false)) { if (!class_exists($test->getName(), false)) {
$testSuites[] = $test; $testSuites[] = $test;
continue; continue;
@ -178,11 +178,11 @@ class SymfonyTestsListenerTrait
$skipped = []; $skipped = [];
while ($s = array_shift($suites)) { while ($s = array_shift($suites)) {
foreach ($s->tests() as $test) { foreach ($s->tests() as $test) {
if ($test instanceof \PHPUnit_Framework_TestSuite || $test instanceof TestSuite) { if ($test instanceof TestSuite) {
$suites[] = $test; $suites[] = $test;
continue; continue;
} }
if (($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase) if ($test instanceof TestCase
&& isset($this->wasSkipped[\get_class($test)][$test->getName()]) && isset($this->wasSkipped[\get_class($test)][$test->getName()])
) { ) {
$skipped[] = $test; $skipped[] = $test;
@ -202,7 +202,7 @@ class SymfonyTestsListenerTrait
public function startTest($test) public function startTest($test)
{ {
if (-2 < $this->state && ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) { if (-2 < $this->state && $test instanceof TestCase) {
// This event is triggered before the test is re-run in isolation // This event is triggered before the test is re-run in isolation
if ($this->willBeIsolated($test)) { if ($this->willBeIsolated($test)) {
$this->runsInSeparateProcess = tempnam(sys_get_temp_dir(), 'deprec'); $this->runsInSeparateProcess = tempnam(sys_get_temp_dir(), 'deprec');
@ -280,7 +280,7 @@ class SymfonyTestsListenerTrait
unlink($this->runsInSeparateProcess); unlink($this->runsInSeparateProcess);
putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); putenv('SYMFONY_DEPRECATIONS_SERIALIZE');
foreach ($deprecations ? unserialize($deprecations) : [] as $deprecation) { foreach ($deprecations ? unserialize($deprecations) : [] as $deprecation) {
$error = serialize(['deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false), 'triggering_file' => isset($deprecation[2]) ? $deprecation[2] : null]); $error = serialize(['deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false), 'triggering_file' => $deprecation[2] ?? null]);
if ($deprecation[0]) { if ($deprecation[0]) {
// unsilenced on purpose // unsilenced on purpose
trigger_error($error, \E_USER_DEPRECATED); trigger_error($error, \E_USER_DEPRECATED);
@ -312,7 +312,7 @@ class SymfonyTestsListenerTrait
self::$expectedDeprecations = self::$gatheredDeprecations = []; self::$expectedDeprecations = self::$gatheredDeprecations = [];
self::$previousErrorHandler = null; self::$previousErrorHandler = null;
} }
if (!$this->runsInSeparateProcess && -2 < $this->state && ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) { if (!$this->runsInSeparateProcess && -2 < $this->state && $test instanceof TestCase) {
if (\in_array('time-sensitive', $groups, true)) { if (\in_array('time-sensitive', $groups, true)) {
ClockMock::withClockMock(false); ClockMock::withClockMock(false);
} }

View File

@ -11,13 +11,7 @@
namespace Symfony\Bridge\PhpUnit; namespace Symfony\Bridge\PhpUnit;
if (version_compare(\PHPUnit\Runner\Version::id(), '6.0.0', '<')) { class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV5', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV6', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
} else {
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
}
if (false) { if (false) {
class SymfonyTestsListener class SymfonyTestsListener

View File

@ -1,40 +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\Tests;
use PHPUnit\Framework\TestCase;
class BootstrapTest extends TestCase
{
/**
* @requires PHPUnit < 6.0
*/
public function testAliasingOfErrorClasses()
{
$this->assertInstanceOf(
\PHPUnit_Framework_Error::class,
new \PHPUnit\Framework\Error\Error('message', 0, __FILE__, __LINE__)
);
$this->assertInstanceOf(
\PHPUnit_Framework_Error_Deprecated::class,
new \PHPUnit\Framework\Error\Deprecated('message', 0, __FILE__, __LINE__)
);
$this->assertInstanceOf(
\PHPUnit_Framework_Error_Notice::class,
new \PHPUnit\Framework\Error\Notice('message', 0, __FILE__, __LINE__)
);
$this->assertInstanceOf(
\PHPUnit_Framework_Error_Warning::class,
new \PHPUnit\Framework\Error\Warning('message', 0, __FILE__, __LINE__)
);
}
}

View File

@ -33,7 +33,7 @@ class DeprecationTest extends TestCase
foreach (get_declared_classes() as $class) { foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) { if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class); $r = new \ReflectionClass($class);
$vendorDir = \dirname(\dirname($r->getFileName())); $vendorDir = \dirname($r->getFileName(), 2);
if (file_exists($vendorDir.'/composer/installed.json') && @mkdir($vendorDir.'/myfakevendor/myfakepackage1', 0777, true)) { if (file_exists($vendorDir.'/composer/installed.json') && @mkdir($vendorDir.'/myfakevendor/myfakepackage1', 0777, true)) {
break; break;
} }
@ -61,7 +61,7 @@ class DeprecationTest extends TestCase
{ {
$r = new \ReflectionClass(Deprecation::class); $r = new \ReflectionClass(Deprecation::class);
if (\dirname(\dirname($r->getFileName())) !== \dirname(\dirname(__DIR__))) { if (\dirname($r->getFileName(), 2) !== \dirname(__DIR__, 2)) {
$this->markTestSkipped('Test case is not compatible with having the bridge in vendor/'); $this->markTestSkipped('Test case is not compatible with having the bridge in vendor/');
} }
@ -266,7 +266,7 @@ class DeprecationTest extends TestCase
foreach (get_declared_classes() as $class) { foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) { if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class); $r = new \ReflectionClass($class);
$v = \dirname(\dirname($r->getFileName())); $v = \dirname($r->getFileName(), 2);
if (file_exists($v.'/composer/installed.json')) { if (file_exists($v.'/composer/installed.json')) {
$loader = require $v.'/autoload.php'; $loader = require $v.'/autoload.php';
$reflection = new \ReflectionClass($loader); $reflection = new \ReflectionClass($loader);

View File

@ -13,13 +13,5 @@ require __DIR__.'/../src/BarCov.php';
require __DIR__.'/../src/FooCov.php'; require __DIR__.'/../src/FooCov.php';
require __DIR__.'/../../../../Legacy/CoverageListenerTrait.php'; require __DIR__.'/../../../../Legacy/CoverageListenerTrait.php';
require_once __DIR__.'/../../../../Legacy/CoverageListenerForV7.php';
if (version_compare(\PHPUnit\Runner\Version::id(), '6.0.0', '<')) {
require_once __DIR__.'/../../../../Legacy/CoverageListenerForV5.php';
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '<')) {
require_once __DIR__.'/../../../../Legacy/CoverageListenerForV6.php';
} else {
require_once __DIR__.'/../../../../Legacy/CoverageListenerForV7.php';
}
require __DIR__.'/../../../../CoverageListener.php'; require __DIR__.'/../../../../CoverageListener.php';

View File

@ -11,10 +11,8 @@
namespace Symfony\Bridge\PhpUnit\TextUI; namespace Symfony\Bridge\PhpUnit\TextUI;
if (version_compare(\PHPUnit\Runner\Version::id(), '6.0.0', '<')) { if (version_compare(\PHPUnit\Runner\Version::id(), '9.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV5', 'Symfony\Bridge\PhpUnit\TextUI\Command'); class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV7', 'Symfony\Bridge\PhpUnit\TextUI\Command');
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '9.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV6', 'Symfony\Bridge\PhpUnit\TextUI\Command');
} else { } else {
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV9', 'Symfony\Bridge\PhpUnit\TextUI\Command'); class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV9', 'Symfony\Bridge\PhpUnit\TextUI\Command');
} }

View File

@ -15,8 +15,8 @@
error_reporting(-1); error_reporting(-1);
global $argv, $argc; global $argv, $argc;
$argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : []; $argv = $_SERVER['argv'] ?? [];
$argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0; $argc = $_SERVER['argc'] ?? 0;
$getEnvVar = function ($name, $default = false) use ($argv) { $getEnvVar = function ($name, $default = false) use ($argv) {
if (false !== $value = getenv($name)) { if (false !== $value = getenv($name)) {
return $value; return $value;
@ -98,19 +98,9 @@ if (\PHP_VERSION_ID >= 80000) {
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '9.4'); $PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '9.4');
} elseif (\PHP_VERSION_ID >= 70200) { } elseif (\PHP_VERSION_ID >= 70200) {
// PHPUnit 8 requires PHP 7.2+ // PHPUnit 8 requires PHP 7.2+
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '8.3'); $PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '8.5');
} elseif (\PHP_VERSION_ID >= 70100) {
// PHPUnit 7 requires PHP 7.1+
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '7.5');
} elseif (\PHP_VERSION_ID >= 70000) {
// PHPUnit 6 requires PHP 7.0+
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '6.5');
} elseif (\PHP_VERSION_ID >= 50600) {
// PHPUnit 4 does not support PHP 7
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '5.7');
} else { } else {
// PHPUnit 5.1 requires PHP 5.6+ $PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '7.5');
$PHPUNIT_VERSION = '4.8';
} }
$MAX_PHPUNIT_VERSION = $getEnvVar('SYMFONY_MAX_PHPUNIT_VERSION', false); $MAX_PHPUNIT_VERSION = $getEnvVar('SYMFONY_MAX_PHPUNIT_VERSION', false);
@ -255,12 +245,12 @@ if (!file_exists("$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR/phpunit") || $configurationH
if ($PHPUNIT_REMOVE_RETURN_TYPEHINT) { if ($PHPUNIT_REMOVE_RETURN_TYPEHINT) {
$alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode); $alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode);
} }
$alteredCode = preg_replace('/abstract class (?:TestCase|PHPUnit_Framework_TestCase)[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillTestCaseTrait;", $alteredCode, 1); $alteredCode = preg_replace('/abstract class TestCase[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillTestCaseTrait;", $alteredCode, 1);
file_put_contents($alteredFile, $alteredCode); file_put_contents($alteredFile, $alteredCode);
// Mutate Assert code // Mutate Assert code
$alteredCode = file_get_contents($alteredFile = './src/Framework/Assert.php'); $alteredCode = file_get_contents($alteredFile = './src/Framework/Assert.php');
$alteredCode = preg_replace('/abstract class (?:Assert|PHPUnit_Framework_Assert)[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillAssertTrait;", $alteredCode, 1); $alteredCode = preg_replace('/abstract class Assert[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillAssertTrait;", $alteredCode, 1);
file_put_contents($alteredFile, $alteredCode); file_put_contents($alteredFile, $alteredCode);
file_put_contents('phpunit', <<<'EOPHP' file_put_contents('phpunit', <<<'EOPHP'
@ -352,7 +342,7 @@ if ('\\' === \DIRECTORY_SEPARATOR) {
} }
if ($components) { if ($components) {
$skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false; $skippedTests = $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] ?? false;
$runningProcs = []; $runningProcs = [];
foreach ($components as $component) { foreach ($components as $component) {

View File

@ -12,96 +12,6 @@
use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Common\Annotations\AnnotationRegistry;
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
$classes = [
'PHPUnit_Framework_Assert', // override PhpUnit's ForwardCompat child class
'PHPUnit_Framework_AssertionFailedError', // override PhpUnit's ForwardCompat child class
'PHPUnit_Framework_BaseTestListener', // override PhpUnit's ForwardCompat child class
'PHPUnit_Framework_Constraint',
'PHPUnit_Framework_Constraint_ArrayHasKey',
'PHPUnit_Framework_Constraint_ArraySubset',
'PHPUnit_Framework_Constraint_Attribute',
'PHPUnit_Framework_Constraint_Callback',
'PHPUnit_Framework_Constraint_ClassHasAttribute',
'PHPUnit_Framework_Constraint_ClassHasStaticAttribute',
'PHPUnit_Framework_Constraint_Composite',
'PHPUnit_Framework_Constraint_Count',
'PHPUnit_Framework_Constraint_Exception',
'PHPUnit_Framework_Constraint_ExceptionCode',
'PHPUnit_Framework_Constraint_ExceptionMessage',
'PHPUnit_Framework_Constraint_ExceptionMessageRegExp',
'PHPUnit_Framework_Constraint_FileExists',
'PHPUnit_Framework_Constraint_GreaterThan',
'PHPUnit_Framework_Constraint_IsAnything',
'PHPUnit_Framework_Constraint_IsEmpty',
'PHPUnit_Framework_Constraint_IsEqual',
'PHPUnit_Framework_Constraint_IsFalse',
'PHPUnit_Framework_Constraint_IsIdentical',
'PHPUnit_Framework_Constraint_IsInstanceOf',
'PHPUnit_Framework_Constraint_IsJson',
'PHPUnit_Framework_Constraint_IsNull',
'PHPUnit_Framework_Constraint_IsTrue',
'PHPUnit_Framework_Constraint_IsType',
'PHPUnit_Framework_Constraint_JsonMatches',
'PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider',
'PHPUnit_Framework_Constraint_LessThan',
'PHPUnit_Framework_Constraint_ObjectHasAttribute',
'PHPUnit_Framework_Constraint_PCREMatch',
'PHPUnit_Framework_Constraint_SameSize',
'PHPUnit_Framework_Constraint_StringContains',
'PHPUnit_Framework_Constraint_StringEndsWith',
'PHPUnit_Framework_Constraint_StringMatches',
'PHPUnit_Framework_Constraint_StringStartsWith',
'PHPUnit_Framework_Constraint_TraversableContains',
'PHPUnit_Framework_Constraint_TraversableContainsOnly',
'PHPUnit_Framework_Error_Deprecated',
'PHPUnit_Framework_Error_Notice',
'PHPUnit_Framework_Error_Warning',
'PHPUnit_Framework_Exception',
'PHPUnit_Framework_ExpectationFailedException',
'PHPUnit_Framework_MockObject_MockObject',
'PHPUnit_Framework_IncompleteTest',
'PHPUnit_Framework_IncompleteTestCase',
'PHPUnit_Framework_IncompleteTestError',
'PHPUnit_Framework_RiskyTest',
'PHPUnit_Framework_RiskyTestError',
'PHPUnit_Framework_SkippedTest',
'PHPUnit_Framework_SkippedTestCase',
'PHPUnit_Framework_SkippedTestError',
'PHPUnit_Framework_SkippedTestSuiteError',
'PHPUnit_Framework_SyntheticError',
'PHPUnit_Framework_Test',
'PHPUnit_Framework_TestCase', // override PhpUnit's ForwardCompat child class
'PHPUnit_Framework_TestFailure',
'PHPUnit_Framework_TestListener',
'PHPUnit_Framework_TestResult',
'PHPUnit_Framework_TestSuite', // override PhpUnit's ForwardCompat child class
'PHPUnit_Runner_BaseTestRunner',
'PHPUnit_Runner_Version',
'PHPUnit_Util_Blacklist',
'PHPUnit_Util_ErrorHandler',
'PHPUnit_Util_Test',
'PHPUnit_Util_XML',
];
foreach ($classes as $class) {
class_alias($class, '\\'.strtr($class, '_', '\\'));
}
class_alias('PHPUnit_Framework_Constraint_And', 'PHPUnit\Framework\Constraint\LogicalAnd');
class_alias('PHPUnit_Framework_Constraint_Not', 'PHPUnit\Framework\Constraint\LogicalNot');
class_alias('PHPUnit_Framework_Constraint_Or', 'PHPUnit\Framework\Constraint\LogicalOr');
class_alias('PHPUnit_Framework_Constraint_Xor', 'PHPUnit\Framework\Constraint\LogicalXor');
class_alias('PHPUnit_Framework_Error', 'PHPUnit\Framework\Error\Error');
}
// 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);
@ -110,7 +20,7 @@ if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
} }
// Detect if we're loaded by an actual run of phpunit // Detect if we're loaded by an actual run of phpunit
if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists('PHPUnit_TextUI_Command', false) && !class_exists('PHPUnit\TextUI\Command', false)) { if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists('PHPUnit\TextUI\Command', false)) {
return; return;
} }

View File

@ -16,9 +16,9 @@
} }
], ],
"require": { "require": {
"php": ">=5.5.9 EVEN ON LATEST SYMFONY VERSIONS TO ALLOW USING", "php": ">=7.1.3 EVEN ON LATEST SYMFONY VERSIONS TO ALLOW USING",
"php": "THIS BRIDGE WHEN TESTING LOWEST SYMFONY VERSIONS.", "php": "THIS BRIDGE WHEN TESTING LOWEST SYMFONY VERSIONS.",
"php": ">=5.5.9" "php": ">=7.1.3"
}, },
"require-dev": { "require-dev": {
"symfony/deprecation-contracts": "^2.1", "symfony/deprecation-contracts": "^2.1",
@ -28,7 +28,7 @@
"symfony/error-handler": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" "symfony/error-handler": "For tracking deprecated interfaces usages at runtime with DebugClassLoader"
}, },
"conflict": { "conflict": {
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0|<6.4,>=6.0|9.1.2" "phpunit/phpunit": "<7.5|9.1.2"
}, },
"autoload": { "autoload": {
"files": [ "bootstrap.php" ], "files": [ "bootstrap.php" ],