Merge branch '4.4' into 5.0

* 4.4:
  [PhpUnitBridge] cs fix
This commit is contained in:
Nicolas Grekas 2020-02-06 18:01:19 +01:00
commit 2e27c4fdf4
9 changed files with 40 additions and 44 deletions

View File

@ -94,7 +94,7 @@ class ClockMock
{
$self = \get_called_class();
$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
if (0 < strpos($class, '\\Tests\\')) {
$ns = str_replace('\\Tests\\', '\\', $class);
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));

View File

@ -16,8 +16,8 @@ namespace Symfony\Bridge\PhpUnit;
*/
class DnsMock
{
private static $hosts = array();
private static $dnsTypes = array(
private static $hosts = [];
private static $dnsTypes = [
'A' => DNS_A,
'MX' => DNS_MX,
'NS' => DNS_NS,
@ -30,7 +30,7 @@ class DnsMock
'NAPTR' => DNS_NAPTR,
'TXT' => DNS_TXT,
'HINFO' => DNS_HINFO,
);
];
/**
* Configures the mock values for DNS queries.
@ -68,7 +68,7 @@ class DnsMock
if (!self::$hosts) {
return \getmxrr($hostname, $mxhosts, $weight);
}
$mxhosts = $weight = array();
$mxhosts = $weight = [];
if (isset(self::$hosts[$hostname])) {
foreach (self::$hosts[$hostname] as $record) {
@ -125,7 +125,7 @@ class DnsMock
$ips = false;
if (isset(self::$hosts[$hostname])) {
$ips = array();
$ips = [];
foreach (self::$hosts[$hostname] as $record) {
if ('A' === $record['type']) {
@ -149,11 +149,11 @@ class DnsMock
if (DNS_ANY === $type) {
$type = DNS_ALL;
}
$records = array();
$records = [];
foreach (self::$hosts[$hostname] as $record) {
if (isset(self::$dnsTypes[$record['type']]) && (self::$dnsTypes[$record['type']] & $type)) {
$records[] = array_merge(array('host' => $hostname, 'class' => 'IN', 'ttl' => 1, 'type' => $record['type']), $record);
$records[] = array_merge(['host' => $hostname, 'class' => 'IN', 'ttl' => 1, 'type' => $record['type']], $record);
}
}
}
@ -165,7 +165,7 @@ class DnsMock
{
$self = \get_called_class();
$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
if (0 < strpos($class, '\\Tests\\')) {
$ns = str_replace('\\Tests\\', '\\', $class);
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));

View File

@ -23,7 +23,7 @@ class CommandForV5 extends \PHPUnit_TextUI_Command
*/
protected function createRunner()
{
$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : array();
$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : [];
$registeredLocally = false;

View File

@ -32,7 +32,7 @@ class CoverageListenerTrait
{
$this->sutFqcnResolver = $sutFqcnResolver;
$this->warningOnSutNotFound = $warningOnSutNotFound;
$this->warnings = array();
$this->warnings = [];
}
public function startTest($test)
@ -43,7 +43,7 @@ class CoverageListenerTrait
$annotations = $test->getAnnotations();
$ignoredAnnotations = array('covers', 'coversDefaultClass', 'coversNothing');
$ignoredAnnotations = ['covers', 'coversDefaultClass', 'coversNothing'];
foreach ($ignoredAnnotations as $annotation) {
if (isset($annotations['class'][$annotation]) || isset($annotations['method'][$annotation])) {
@ -70,11 +70,11 @@ class CoverageListenerTrait
$r->setAccessible(true);
$cache = $r->getValue();
$cache = array_replace_recursive($cache, array(
\get_class($test) => array(
'covers' => \is_array($sutFqcn) ? $sutFqcn : array($sutFqcn),
),
));
$cache = array_replace_recursive($cache, [
\get_class($test) => [
'covers' => \is_array($sutFqcn) ? $sutFqcn : [$sutFqcn],
],
]);
$r->setValue(Test::class, $cache);
}

View File

@ -22,7 +22,7 @@ class SymfonyTestsListenerForV5 extends \PHPUnit_Framework_BaseTestListener
{
private $trait;
public function __construct(array $mockedNamespaces = array())
public function __construct(array $mockedNamespaces = [])
{
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
}

View File

@ -14,7 +14,6 @@ namespace Symfony\Bridge\PhpUnit\Legacy;
use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
/**
* Collects and replays skipped tests.
@ -27,7 +26,7 @@ class SymfonyTestsListenerForV6 extends BaseTestListener
{
private $trait;
public function __construct(array $mockedNamespaces = array())
public function __construct(array $mockedNamespaces = [])
{
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
}

View File

@ -15,7 +15,6 @@ use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
/**
* Collects and replays skipped tests.
@ -30,7 +29,7 @@ class SymfonyTestsListenerForV7 implements TestListener
private $trait;
public function __construct(array $mockedNamespaces = array())
public function __construct(array $mockedNamespaces = [])
{
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
}

View File

@ -35,10 +35,10 @@ class SymfonyTestsListenerTrait
private static $globallyEnabled = false;
private $state = -1;
private $skippedFile = false;
private $wasSkipped = array();
private $isSkipped = array();
private $expectedDeprecations = array();
private $gatheredDeprecations = array();
private $wasSkipped = [];
private $isSkipped = [];
private $expectedDeprecations = [];
private $gatheredDeprecations = [];
private $previousErrorHandler;
private $error;
private $runsInSeparateProcess = false;
@ -46,7 +46,7 @@ class SymfonyTestsListenerTrait
/**
* @param array $mockedNamespaces List of namespaces, indexed by mocked features (time-sensitive or dns-sensitive)
*/
public function __construct(array $mockedNamespaces = array())
public function __construct(array $mockedNamespaces = [])
{
Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait'] = 2;
@ -54,7 +54,7 @@ class SymfonyTestsListenerTrait
foreach ($mockedNamespaces as $type => $namespaces) {
if (!\is_array($namespaces)) {
$namespaces = array($namespaces);
$namespaces = [$namespaces];
}
if ('time-sensitive' === $type) {
foreach ($namespaces as $ns) {
@ -140,11 +140,11 @@ class SymfonyTestsListenerTrait
if (!$this->wasSkipped = require $this->skippedFile) {
echo "All tests already ran successfully.\n";
$suite->setTests(array());
$suite->setTests([]);
}
}
}
$testSuites = array($suite);
$testSuites = [$suite];
for ($i = 0; isset($testSuites[$i]); ++$i) {
foreach ($testSuites[$i]->tests() as $test) {
if ($test instanceof TestSuite) {
@ -163,7 +163,7 @@ class SymfonyTestsListenerTrait
}
}
} elseif (2 === $this->state) {
$skipped = array();
$skipped = [];
foreach ($suite->tests() as $test) {
if (!($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)
|| isset($this->wasSkipped[$suiteName]['*'])
@ -228,7 +228,7 @@ class SymfonyTestsListenerTrait
$test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);
$this->expectedDeprecations = $annotations['method']['expectedDeprecation'];
$this->previousErrorHandler = set_error_handler(array($this, 'handleError'));
$this->previousErrorHandler = set_error_handler([$this, 'handleError']);
}
}
}
@ -251,8 +251,8 @@ class SymfonyTestsListenerTrait
$deprecations = file_get_contents($this->runsInSeparateProcess);
unlink($this->runsInSeparateProcess);
putenv('SYMFONY_DEPRECATIONS_SERIALIZE');
foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) {
$error = serialize(array('deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false), 'triggering_file' => isset($deprecation[2]) ? $deprecation[2] : null));
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]);
if ($deprecation[0]) {
// unsilenced on purpose
trigger_error($error, E_USER_DEPRECATED);
@ -264,13 +264,13 @@ class SymfonyTestsListenerTrait
}
if ($this->expectedDeprecations) {
if (!\in_array($test->getStatus(), array(BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE), true)) {
if (!\in_array($test->getStatus(), [BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE], true)) {
$test->addToAssertionCount(\count($this->expectedDeprecations));
}
restore_error_handler();
if (!$errored && !\in_array($test->getStatus(), array(BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE, BaseTestRunner::STATUS_FAILURE, BaseTestRunner::STATUS_ERROR), true)) {
if (!$errored && !\in_array($test->getStatus(), [BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE, BaseTestRunner::STATUS_FAILURE, BaseTestRunner::STATUS_ERROR], true)) {
try {
$prefix = "@expectedDeprecation:\n";
$test->assertStringMatchesFormat($prefix.'%A '.implode("\n%A ", $this->expectedDeprecations)."\n%A", $prefix.' '.implode("\n ", $this->gatheredDeprecations)."\n");
@ -279,7 +279,7 @@ class SymfonyTestsListenerTrait
}
}
$this->expectedDeprecations = $this->gatheredDeprecations = array();
$this->expectedDeprecations = $this->gatheredDeprecations = [];
$this->previousErrorHandler = null;
}
if (!$this->runsInSeparateProcess && -2 < $this->state && ($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) {
@ -287,12 +287,12 @@ class SymfonyTestsListenerTrait
ClockMock::withClockMock(false);
}
if (\in_array('dns-sensitive', $groups, true)) {
DnsMock::withMockedHosts(array());
DnsMock::withMockedHosts([]);
}
}
}
public function handleError($type, $msg, $file, $line, $context = array())
public function handleError($type, $msg, $file, $line, $context = [])
{
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
$h = $this->previousErrorHandler;

View File

@ -11,7 +11,6 @@
namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler;
use Composer\Autoload\ClassLoader;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
@ -46,7 +45,6 @@ class DeprecationTest extends TestCase
touch($vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile2.php');
touch($vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php');
return self::$vendorDir;
}
@ -106,12 +104,12 @@ class DeprecationTest extends TestCase
yield 'not from phpunit, and not a whitelisted message' => [
false,
\My\Source\Code::class,
'Self deprecating humor is deprecated by itself'
'Self deprecating humor is deprecated by itself',
];
yield 'from phpunit, but not a whitelisted message' => [
false,
\PHPUnit\Random\Piece\Of\Code::class,
'Self deprecating humor is deprecated by itself'
'Self deprecating humor is deprecated by itself',
];
yield 'whitelisted message, but not from phpunit' => [
false,
@ -146,7 +144,7 @@ class DeprecationTest extends TestCase
['file' => 'should_not_matter.php'],
['file' => 'should_not_matter_either.php'],
],
'random_path' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'phpunit' . \DIRECTORY_SEPARATOR . 'whatever.php'
'random_path'.\DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR.'whatever.php'
);
$this->assertTrue($deprecation->isMuted());
}