Skip to content

Commit

Permalink
minor #30041 PHPUnit Bridge: Rollback to traditional array syntax. (d…
Browse files Browse the repository at this point in the history
…errabus)

This PR was merged into the 3.4 branch.

Discussion
----------

PHPUnit Bridge: Rollback to traditional array syntax.

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30039
| License       | MIT
| Doc PR        | N/A

I've used PHP CS Fixer to convert all short array expressions back to the traditional syntax understood by php 5.3. Unfortunately, I don't have a local php 5.3 setup anymore, so I hope I've caught all occurrences.

Commits
-------

8b330de PHPUnit Bridge: Rollback to traditional array syntax.
  • Loading branch information
nicolas-grekas committed Jan 30, 2019
2 parents 11dc73d + 8b330de commit 83bab56
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 114 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/ClockMock.php
Expand Up @@ -73,7 +73,7 @@ public static function register($class)
{
$self = \get_called_class();

$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
if (0 < strpos($class, '\\Tests\\')) {
$ns = str_replace('\\Tests\\', '\\', $class);
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
Expand Down
28 changes: 14 additions & 14 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Expand Up @@ -92,19 +92,19 @@ public static function register($mode = 0)
return false;
};

$deprecations = [
$deprecations = array(
'unsilencedCount' => 0,
'remainingCount' => 0,
'legacyCount' => 0,
'otherCount' => 0,
'remaining vendorCount' => 0,
'unsilenced' => [],
'remaining' => [],
'legacy' => [],
'other' => [],
'remaining vendor' => [],
];
$deprecationHandler = function ($type, $msg, $file, $line, $context = []) use (&$deprecations, $getMode, $UtilPrefix, $inVendors) {
'unsilenced' => array(),
'remaining' => array(),
'legacy' => array(),
'other' => array(),
'remaining vendor' => array(),
);
$deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, $getMode, $UtilPrefix, $inVendors) {
$mode = $getMode();
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || self::MODE_DISABLED === $mode) {
$ErrorHandler = $UtilPrefix.'ErrorHandler';
Expand Down Expand Up @@ -184,7 +184,7 @@ public static function register($mode = 0)

if (null !== $oldErrorHandler) {
restore_error_handler();
if ([$UtilPrefix.'ErrorHandler', 'handleError'] === $oldErrorHandler) {
if (array($UtilPrefix.'ErrorHandler', 'handleError') === $oldErrorHandler) {
restore_error_handler();
self::register($mode);
}
Expand Down Expand Up @@ -218,7 +218,7 @@ public static function register($mode = 0)
return $b['count'] - $a['count'];
};

$groups = ['unsilenced', 'remaining'];
$groups = array('unsilenced', 'remaining');
if (self::MODE_WEAK_VENDORS === $mode) {
$groups[] = 'remaining vendor';
}
Expand Down Expand Up @@ -259,7 +259,7 @@ public static function register($mode = 0)

// reset deprecations array
foreach ($deprecations as $group => $arrayOrInt) {
$deprecations[$group] = \is_int($arrayOrInt) ? 0 : [];
$deprecations[$group] = \is_int($arrayOrInt) ? 0 : array();
}

register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) {
Expand All @@ -280,8 +280,8 @@ public static function register($mode = 0)

public static function collectDeprecations($outputFile)
{
$deprecations = [];
$previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$previousErrorHandler) {
$deprecations = array();
$previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, &$previousErrorHandler) {
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
if ($previousErrorHandler) {
return $previousErrorHandler($type, $msg, $file, $line, $context);
Expand All @@ -293,7 +293,7 @@ public static function collectDeprecations($outputFile)

return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
}
$deprecations[] = [error_reporting(), $msg, $file];
$deprecations[] = array(error_reporting(), $msg, $file);
});

register_shutdown_function(function () use ($outputFile, &$deprecations) {
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Bridge/PhpUnit/DnsMock.php
Expand Up @@ -16,8 +16,8 @@
*/
class DnsMock
{
private static $hosts = [];
private static $dnsTypes = [
private static $hosts = array();
private static $dnsTypes = array(
'A' => DNS_A,
'MX' => DNS_MX,
'NS' => DNS_NS,
Expand All @@ -30,7 +30,7 @@ class DnsMock
'NAPTR' => DNS_NAPTR,
'TXT' => DNS_TXT,
'HINFO' => DNS_HINFO,
];
);

/**
* Configures the mock values for DNS queries.
Expand Down Expand Up @@ -68,7 +68,7 @@ public static function getmxrr($hostname, &$mxhosts, &$weight = null)
if (!self::$hosts) {
return \getmxrr($hostname, $mxhosts, $weight);
}
$mxhosts = $weight = [];
$mxhosts = $weight = array();

if (isset(self::$hosts[$hostname])) {
foreach (self::$hosts[$hostname] as $record) {
Expand Down Expand Up @@ -125,7 +125,7 @@ public static function gethostbynamel($hostname)
$ips = false;

if (isset(self::$hosts[$hostname])) {
$ips = [];
$ips = array();

foreach (self::$hosts[$hostname] as $record) {
if ('A' === $record['type']) {
Expand All @@ -149,11 +149,11 @@ public static function dns_get_record($hostname, $type = DNS_ANY, &$authns = nul
if (DNS_ANY === $type) {
$type = DNS_ALL;
}
$records = [];
$records = array();

foreach (self::$hosts[$hostname] as $record) {
if (isset(self::$dnsTypes[$record['type']]) && (self::$dnsTypes[$record['type']] & $type)) {
$records[] = array_merge(['host' => $hostname, 'class' => 'IN', 'ttl' => 1, 'type' => $record['type']], $record);
$records[] = array_merge(array('host' => $hostname, 'class' => 'IN', 'ttl' => 1, 'type' => $record['type']), $record);
}
}
}
Expand All @@ -165,7 +165,7 @@ public static function register($class)
{
$self = \get_called_class();

$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
if (0 < strpos($class, '\\Tests\\')) {
$ns = str_replace('\\Tests\\', '\\', $class);
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
Expand Down
14 changes: 7 additions & 7 deletions src/Symfony/Bridge/PhpUnit/Legacy/CoverageListenerTrait.php
Expand Up @@ -31,7 +31,7 @@ public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFo
{
$this->sutFqcnResolver = $sutFqcnResolver;
$this->warningOnSutNotFound = $warningOnSutNotFound;
$this->warnings = [];
$this->warnings = array();
}

public function startTest($test)
Expand All @@ -42,7 +42,7 @@ public function startTest($test)

$annotations = $test->getAnnotations();

$ignoredAnnotations = ['covers', 'coversDefaultClass', 'coversNothing'];
$ignoredAnnotations = array('covers', 'coversDefaultClass', 'coversNothing');

foreach ($ignoredAnnotations as $annotation) {
if (isset($annotations['class'][$annotation]) || isset($annotations['method'][$annotation])) {
Expand Down Expand Up @@ -74,11 +74,11 @@ public function startTest($test)
$r->setAccessible(true);

$cache = $r->getValue();
$cache = array_replace_recursive($cache, [
\get_class($test) => [
'covers' => [$sutFqcn],
],
]);
$cache = array_replace_recursive($cache, array(
\get_class($test) => array(
'covers' => array($sutFqcn),
),
));
$r->setValue($testClass, $cache);
}

Expand Down
Expand Up @@ -22,7 +22,7 @@ class SymfonyTestsListenerForV5 extends \PHPUnit_Framework_BaseTestListener
{
private $trait;

public function __construct(array $mockedNamespaces = [])
public function __construct(array $mockedNamespaces = array())
{
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
}
Expand Down
Expand Up @@ -27,7 +27,7 @@ class SymfonyTestsListenerForV6 extends BaseTestListener
{
private $trait;

public function __construct(array $mockedNamespaces = [])
public function __construct(array $mockedNamespaces = array())
{
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
}
Expand Down
Expand Up @@ -30,7 +30,7 @@ class SymfonyTestsListenerForV7 implements TestListener

private $trait;

public function __construct(array $mockedNamespaces = [])
public function __construct(array $mockedNamespaces = array())
{
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
}
Expand Down
36 changes: 18 additions & 18 deletions src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php
Expand Up @@ -31,10 +31,10 @@ class SymfonyTestsListenerTrait
private static $globallyEnabled = false;
private $state = -1;
private $skippedFile = false;
private $wasSkipped = [];
private $isSkipped = [];
private $expectedDeprecations = [];
private $gatheredDeprecations = [];
private $wasSkipped = array();
private $isSkipped = array();
private $expectedDeprecations = array();
private $gatheredDeprecations = array();
private $previousErrorHandler;
private $testsWithWarnings;
private $reportUselessTests;
Expand All @@ -44,7 +44,7 @@ class SymfonyTestsListenerTrait
/**
* @param array $mockedNamespaces List of namespaces, indexed by mocked features (time-sensitive or dns-sensitive)
*/
public function __construct(array $mockedNamespaces = [])
public function __construct(array $mockedNamespaces = array())
{
if (class_exists('PHPUnit_Util_Blacklist')) {
\PHPUnit_Util_Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait'] = 2;
Expand All @@ -55,7 +55,7 @@ public function __construct(array $mockedNamespaces = [])
$warn = false;
foreach ($mockedNamespaces as $type => $namespaces) {
if (!\is_array($namespaces)) {
$namespaces = [$namespaces];
$namespaces = array($namespaces);
}
if (\is_int($type)) {
// @deprecated BC with v2.8 to v3.0
Expand Down Expand Up @@ -104,7 +104,7 @@ public function startTestSuite($suite)
$Test = 'PHPUnit\Util\Test';
}
$suiteName = $suite->getName();
$this->testsWithWarnings = [];
$this->testsWithWarnings = array();

foreach ($suite->tests() as $test) {
if (!($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) {
Expand Down Expand Up @@ -135,11 +135,11 @@ public function startTestSuite($suite)

if (!$this->wasSkipped = require $this->skippedFile) {
echo "All tests already ran successfully.\n";
$suite->setTests([]);
$suite->setTests(array());
}
}
}
$testSuites = [$suite];
$testSuites = array($suite);
for ($i = 0; isset($testSuites[$i]); ++$i) {
foreach ($testSuites[$i]->tests() as $test) {
if ($test instanceof \PHPUnit_Framework_TestSuite || $test instanceof TestSuite) {
Expand All @@ -158,7 +158,7 @@ public function startTestSuite($suite)
}
}
} elseif (2 === $this->state) {
$skipped = [];
$skipped = array();
foreach ($suite->tests() as $test) {
if (!($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)
|| isset($this->wasSkipped[$suiteName]['*'])
Expand Down Expand Up @@ -230,7 +230,7 @@ public function startTest($test)
$test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);

$this->expectedDeprecations = $annotations['method']['expectedDeprecation'];
$this->previousErrorHandler = set_error_handler([$this, 'handleError']);
$this->previousErrorHandler = set_error_handler(array($this, 'handleError'));
}
}
}
Expand Down Expand Up @@ -271,8 +271,8 @@ public function endTest($test, $time)
$deprecations = file_get_contents($this->runsInSeparateProcess);
unlink($this->runsInSeparateProcess);
putenv('SYMFONY_DEPRECATIONS_SERIALIZE');
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]);
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));
if ($deprecation[0]) {
@trigger_error($error, E_USER_DEPRECATED);
} else {
Expand All @@ -283,13 +283,13 @@ public function endTest($test, $time)
}

if ($this->expectedDeprecations) {
if (!\in_array($test->getStatus(), [$BaseTestRunner::STATUS_SKIPPED, $BaseTestRunner::STATUS_INCOMPLETE], true)) {
if (!\in_array($test->getStatus(), array($BaseTestRunner::STATUS_SKIPPED, $BaseTestRunner::STATUS_INCOMPLETE), true)) {
$test->addToAssertionCount(\count($this->expectedDeprecations));
}

restore_error_handler();

if (!$errored && !\in_array($test->getStatus(), [$BaseTestRunner::STATUS_SKIPPED, $BaseTestRunner::STATUS_INCOMPLETE, $BaseTestRunner::STATUS_FAILURE, $BaseTestRunner::STATUS_ERROR], true)) {
if (!$errored && !\in_array($test->getStatus(), array($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");
Expand All @@ -300,15 +300,15 @@ public function endTest($test, $time)
}
}

$this->expectedDeprecations = $this->gatheredDeprecations = [];
$this->expectedDeprecations = $this->gatheredDeprecations = array();
$this->previousErrorHandler = null;
}
if (!$this->runsInSeparateProcess && -2 < $this->state && ($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) {
if (\in_array('time-sensitive', $groups, true)) {
ClockMock::withClockMock(false);
}
if (\in_array('dns-sensitive', $groups, true)) {
DnsMock::withMockedHosts([]);
DnsMock::withMockedHosts(array());
}
}

Expand All @@ -329,7 +329,7 @@ public function endTest($test, $time)
}
}

public function handleError($type, $msg, $file, $line, $context = [])
public function handleError($type, $msg, $file, $line, $context = array())
{
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
$h = $this->previousErrorHandler;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/Legacy/TestRunnerForV5.php
Expand Up @@ -27,7 +27,7 @@ protected function handleConfiguration(array &$arguments)

$result = parent::handleConfiguration($arguments);

$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : [];
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();

$registeredLocally = false;

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/Legacy/TestRunnerForV6.php
Expand Up @@ -30,7 +30,7 @@ protected function handleConfiguration(array &$arguments)

parent::handleConfiguration($arguments);

$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : [];
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();

$registeredLocally = false;

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/Legacy/TestRunnerForV7.php
Expand Up @@ -30,7 +30,7 @@ protected function handleConfiguration(array &$arguments): void

parent::handleConfiguration($arguments);

$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : [];
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();

$registeredLocally = false;

Expand Down
Expand Up @@ -35,7 +35,7 @@ class PHPUnit_Util_Test
{
public static function getGroups()
{
return [];
return array();
}
}

Expand Down
Expand Up @@ -35,7 +35,7 @@ class PHPUnit_Util_Test
{
public static function getGroups()
{
return [];
return array();
}
}

Expand Down

0 comments on commit 83bab56

Please sign in to comment.