From 6a2148bfc6ca0016846a32bdc55a317274283709 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 30 Jan 2019 14:15:47 +0100 Subject: [PATCH 1/3] PHPUnit Bridge: Rollback to traditional array syntax. --- ClockMock.php | 2 +- DeprecationErrorHandler.php | 28 +++--- DnsMock.php | 16 +-- Legacy/CoverageListenerTrait.php | 14 +-- Legacy/SymfonyTestsListenerForV5.php | 2 +- Legacy/SymfonyTestsListenerForV6.php | 2 +- Legacy/SymfonyTestsListenerForV7.php | 2 +- Legacy/SymfonyTestsListenerTrait.php | 36 +++---- Legacy/TestRunnerForV5.php | 2 +- Legacy/TestRunnerForV6.php | 2 +- Legacy/TestRunnerForV7.php | 2 +- Tests/DeprecationErrorHandler/default.phpt | 2 +- .../shutdown_deprecations.phpt | 2 +- Tests/DnsMockTest.php | 98 +++++++++---------- bin/simple-phpunit | 18 ++-- 15 files changed, 114 insertions(+), 114 deletions(-) diff --git a/ClockMock.php b/ClockMock.php index a29edd90..4c5432f2 100644 --- a/ClockMock.php +++ b/ClockMock.php @@ -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, '\\')); diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index 2f275a10..3b444d5d 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -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'; @@ -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); } @@ -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'; } @@ -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) { @@ -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); @@ -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) { diff --git a/DnsMock.php b/DnsMock.php index a58bf2ef..790cfa91 100644 --- a/DnsMock.php +++ b/DnsMock.php @@ -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, @@ -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 @@ 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) { @@ -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']) { @@ -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); } } } @@ -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, '\\')); diff --git a/Legacy/CoverageListenerTrait.php b/Legacy/CoverageListenerTrait.php index 07a9679d..8e9bdbe9 100644 --- a/Legacy/CoverageListenerTrait.php +++ b/Legacy/CoverageListenerTrait.php @@ -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) @@ -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])) { @@ -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); } diff --git a/Legacy/SymfonyTestsListenerForV5.php b/Legacy/SymfonyTestsListenerForV5.php index c825a8dd..2da40f2c 100644 --- a/Legacy/SymfonyTestsListenerForV5.php +++ b/Legacy/SymfonyTestsListenerForV5.php @@ -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); } diff --git a/Legacy/SymfonyTestsListenerForV6.php b/Legacy/SymfonyTestsListenerForV6.php index 0c0b5708..5b864bfe 100644 --- a/Legacy/SymfonyTestsListenerForV6.php +++ b/Legacy/SymfonyTestsListenerForV6.php @@ -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); } diff --git a/Legacy/SymfonyTestsListenerForV7.php b/Legacy/SymfonyTestsListenerForV7.php index 25ad718a..18bbdbeb 100644 --- a/Legacy/SymfonyTestsListenerForV7.php +++ b/Legacy/SymfonyTestsListenerForV7.php @@ -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); } diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 14043442..6333c4fd 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -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; @@ -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; @@ -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 @@ -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)) { @@ -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) { @@ -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]['*']) @@ -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')); } } } @@ -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 { @@ -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"); @@ -300,7 +300,7 @@ 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)) { @@ -308,7 +308,7 @@ public function endTest($test, $time) ClockMock::withClockMock(false); } if (\in_array('dns-sensitive', $groups, true)) { - DnsMock::withMockedHosts([]); + DnsMock::withMockedHosts(array()); } } @@ -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; diff --git a/Legacy/TestRunnerForV5.php b/Legacy/TestRunnerForV5.php index 1a89019f..7897861c 100644 --- a/Legacy/TestRunnerForV5.php +++ b/Legacy/TestRunnerForV5.php @@ -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; diff --git a/Legacy/TestRunnerForV6.php b/Legacy/TestRunnerForV6.php index 8489a586..6da7c654 100644 --- a/Legacy/TestRunnerForV6.php +++ b/Legacy/TestRunnerForV6.php @@ -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; diff --git a/Legacy/TestRunnerForV7.php b/Legacy/TestRunnerForV7.php index bc5fff95..a175fb65 100644 --- a/Legacy/TestRunnerForV7.php +++ b/Legacy/TestRunnerForV7.php @@ -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; diff --git a/Tests/DeprecationErrorHandler/default.phpt b/Tests/DeprecationErrorHandler/default.phpt index 9bc155a7..e06e9bd8 100644 --- a/Tests/DeprecationErrorHandler/default.phpt +++ b/Tests/DeprecationErrorHandler/default.phpt @@ -35,7 +35,7 @@ class PHPUnit_Util_Test { public static function getGroups() { - return []; + return array(); } } diff --git a/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt b/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt index 703db6fd..1bb15516 100644 --- a/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt +++ b/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt @@ -35,7 +35,7 @@ class PHPUnit_Util_Test { public static function getGroups() { - return []; + return array(); } } diff --git a/Tests/DnsMockTest.php b/Tests/DnsMockTest.php index ebbc87a7..a178ac7e 100644 --- a/Tests/DnsMockTest.php +++ b/Tests/DnsMockTest.php @@ -18,15 +18,15 @@ class DnsMockTest extends TestCase { protected function tearDown() { - DnsMock::withMockedHosts([]); + DnsMock::withMockedHosts(array()); } public function testCheckdnsrr() { - DnsMock::withMockedHosts(['example.com' => [['type' => 'MX']]]); + DnsMock::withMockedHosts(array('example.com' => array(array('type' => 'MX')))); $this->assertTrue(DnsMock::checkdnsrr('example.com')); - DnsMock::withMockedHosts(['example.com' => [['type' => 'A']]]); + DnsMock::withMockedHosts(array('example.com' => array(array('type' => 'A')))); $this->assertFalse(DnsMock::checkdnsrr('example.com')); $this->assertTrue(DnsMock::checkdnsrr('example.com', 'a')); $this->assertTrue(DnsMock::checkdnsrr('example.com', 'any')); @@ -35,34 +35,34 @@ public function testCheckdnsrr() public function testGetmxrr() { - DnsMock::withMockedHosts([ - 'example.com' => [[ + DnsMock::withMockedHosts(array( + 'example.com' => array(array( 'type' => 'MX', 'host' => 'mx.example.com', 'pri' => 10, - ]], - ]); + )), + )); $this->assertFalse(DnsMock::getmxrr('foobar.com', $mxhosts, $weight)); $this->assertTrue(DnsMock::getmxrr('example.com', $mxhosts, $weight)); - $this->assertSame(['mx.example.com'], $mxhosts); - $this->assertSame([10], $weight); + $this->assertSame(array('mx.example.com'), $mxhosts); + $this->assertSame(array(10), $weight); } public function testGethostbyaddr() { - DnsMock::withMockedHosts([ - 'example.com' => [ - [ + DnsMock::withMockedHosts(array( + 'example.com' => array( + array( 'type' => 'A', 'ip' => '1.2.3.4', - ], - [ + ), + array( 'type' => 'AAAA', 'ipv6' => '::12', - ], - ], - ]); + ), + ), + )); $this->assertSame('::21', DnsMock::gethostbyaddr('::21')); $this->assertSame('example.com', DnsMock::gethostbyaddr('::12')); @@ -71,18 +71,18 @@ public function testGethostbyaddr() public function testGethostbyname() { - DnsMock::withMockedHosts([ - 'example.com' => [ - [ + DnsMock::withMockedHosts(array( + 'example.com' => array( + array( 'type' => 'AAAA', 'ipv6' => '::12', - ], - [ + ), + array( 'type' => 'A', 'ip' => '1.2.3.4', - ], - ], - ]); + ), + ), + )); $this->assertSame('foobar.com', DnsMock::gethostbyname('foobar.com')); $this->assertSame('1.2.3.4', DnsMock::gethostbyname('example.com')); @@ -90,59 +90,59 @@ public function testGethostbyname() public function testGethostbynamel() { - DnsMock::withMockedHosts([ - 'example.com' => [ - [ + DnsMock::withMockedHosts(array( + 'example.com' => array( + array( 'type' => 'A', 'ip' => '1.2.3.4', - ], - [ + ), + array( 'type' => 'A', 'ip' => '2.3.4.5', - ], - ], - ]); + ), + ), + )); $this->assertFalse(DnsMock::gethostbynamel('foobar.com')); - $this->assertSame(['1.2.3.4', '2.3.4.5'], DnsMock::gethostbynamel('example.com')); + $this->assertSame(array('1.2.3.4', '2.3.4.5'), DnsMock::gethostbynamel('example.com')); } public function testDnsGetRecord() { - DnsMock::withMockedHosts([ - 'example.com' => [ - [ + DnsMock::withMockedHosts(array( + 'example.com' => array( + array( 'type' => 'A', 'ip' => '1.2.3.4', - ], - [ + ), + array( 'type' => 'PTR', 'ip' => '2.3.4.5', - ], - ], - ]); + ), + ), + )); - $records = [ - [ + $records = array( + array( 'host' => 'example.com', 'class' => 'IN', 'ttl' => 1, 'type' => 'A', 'ip' => '1.2.3.4', - ], - $ptr = [ + ), + $ptr = array( 'host' => 'example.com', 'class' => 'IN', 'ttl' => 1, 'type' => 'PTR', 'ip' => '2.3.4.5', - ], - ]; + ), + ); $this->assertFalse(DnsMock::dns_get_record('foobar.com')); $this->assertSame($records, DnsMock::dns_get_record('example.com')); $this->assertSame($records, DnsMock::dns_get_record('example.com', DNS_ALL)); $this->assertSame($records, DnsMock::dns_get_record('example.com', DNS_A | DNS_PTR)); - $this->assertSame([$ptr], DnsMock::dns_get_record('example.com', DNS_PTR)); + $this->assertSame(array($ptr), DnsMock::dns_get_record('example.com', DNS_PTR)); } } diff --git a/bin/simple-phpunit b/bin/simple-phpunit index ff6ce806..2e23aa89 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -85,7 +85,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ $prevRoot = getenv('COMPOSER_ROOT_VERSION'); putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99"); // --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS - $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-progress --ansi", [], $p, getcwd(), null, ['bypass_shell' => true])); + $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-progress --ansi", array(), $p, getcwd(), null, array('bypass_shell' => true))); putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : '')); if ($exit) { exit($exit); @@ -118,9 +118,9 @@ EOPHP } global $argv, $argc; -$argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : []; +$argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); $argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0; -$components = []; +$components = array(); $cmd = array_map('escapeshellarg', $argv); $exit = 0; @@ -155,7 +155,7 @@ if ('\\' === DIRECTORY_SEPARATOR) { if ($components) { $skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false; - $runningProcs = []; + $runningProcs = array(); foreach ($components as $component) { // Run phpunit tests in parallel @@ -166,7 +166,7 @@ if ($components) { $c = escapeshellarg($component); - if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), [], $pipes)) { + if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) { $runningProcs[$component] = $proc; } else { $exit = 1; @@ -176,7 +176,7 @@ if ($components) { while ($runningProcs) { usleep(300000); - $terminatedProcs = []; + $terminatedProcs = array(); foreach ($runningProcs as $component => $proc) { $procStatus = proc_get_status($proc); if (!$procStatus['running']) { @@ -187,7 +187,7 @@ if ($components) { } foreach ($terminatedProcs as $component => $procStatus) { - foreach (['out', 'err'] as $file) { + foreach (array('out', 'err') as $file) { $file = "$component/phpunit.std$file"; readfile($file); unlink($file); @@ -197,7 +197,7 @@ if ($components) { // STATUS_STACK_BUFFER_OVERRUN (-1073740791/0xC0000409) // STATUS_ACCESS_VIOLATION (-1073741819/0xC0000005) // STATUS_HEAP_CORRUPTION (-1073740940/0xC0000374) - if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN) || !in_array($procStatus, [-1073740791, -1073741819, -1073740940]))) { + if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN) || !in_array($procStatus, array(-1073740791, -1073741819, -1073740940)))) { $exit = $procStatus; echo "\033[41mKO\033[0m $component\n\n"; } else { @@ -209,7 +209,7 @@ if ($components) { if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) { class SymfonyBlacklistSimplePhpunit {} } - array_splice($argv, 1, 0, ['--colors=always']); + array_splice($argv, 1, 0, array('--colors=always')); $_SERVER['argv'] = $argv; $_SERVER['argc'] = ++$argc; include "$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"; From 017d445033c79bcf4d88e6dd8823e9d483ff9ac8 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 6 Feb 2019 09:03:17 +0100 Subject: [PATCH 2/3] [PhpUnitBridge] fix PHP 5.3 compat --- DeprecationErrorHandler.php | 24 +++++++++---------- Tests/DeprecationErrorHandler/default.phpt | 2 +- .../acme/lib/deprecation_riddled.php | 2 +- .../shutdown_deprecations.phpt | 2 +- .../weak_vendors_on_non_vendor.phpt | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index 3b444d5d..b81eff52 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -54,9 +54,9 @@ public static function register($mode = 0) if (false === $mode) { $mode = getenv('SYMFONY_DEPRECATIONS_HELPER'); } - if (self::MODE_DISABLED !== $mode - && self::MODE_WEAK !== $mode - && self::MODE_WEAK_VENDORS !== $mode + if (DeprecationErrorHandler::MODE_DISABLED !== $mode + && DeprecationErrorHandler::MODE_WEAK !== $mode + && DeprecationErrorHandler::MODE_WEAK_VENDORS !== $mode && (!isset($mode[0]) || '/' !== $mode[0]) ) { $mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0; @@ -106,7 +106,7 @@ public static function register($mode = 0) ); $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) { + if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || DeprecationErrorHandler::MODE_DISABLED === $mode) { $ErrorHandler = $UtilPrefix.'ErrorHandler'; return $ErrorHandler::handleError($type, $msg, $file, $line, $context); @@ -114,7 +114,7 @@ public static function register($mode = 0) $trace = debug_backtrace(); $group = 'other'; - $isVendor = self::MODE_WEAK_VENDORS === $mode && $inVendors($file); + $isVendor = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $inVendors($file); $i = \count($trace); while (1 < $i && (!isset($trace[--$i]['class']) || ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_') || 0 === strpos($trace[$i]['class'], 'PHPUnit\\')))) { @@ -131,7 +131,7 @@ public static function register($mode = 0) // \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest() // then we need to use the serialized information to determine // if the error has been triggered from vendor code. - $isVendor = self::MODE_WEAK_VENDORS === $mode && isset($parsedMsg['triggering_file']) && $inVendors($parsedMsg['triggering_file']); + $isVendor = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && isset($parsedMsg['triggering_file']) && $inVendors($parsedMsg['triggering_file']); } else { $class = isset($trace[$i]['object']) ? \get_class($trace[$i]['object']) : $trace[$i]['class']; $method = $trace[$i]['function']; @@ -168,13 +168,13 @@ public static function register($mode = 0) exit(1); } - if ('legacy' !== $group && self::MODE_WEAK !== $mode) { + if ('legacy' !== $group && DeprecationErrorHandler::MODE_WEAK !== $mode) { $ref = &$deprecations[$group][$msg]['count']; ++$ref; $ref = &$deprecations[$group][$msg][$class.'::'.$method]; ++$ref; } - } elseif (self::MODE_WEAK !== $mode) { + } elseif (DeprecationErrorHandler::MODE_WEAK !== $mode) { $ref = &$deprecations[$group][$msg]['count']; ++$ref; } @@ -207,7 +207,7 @@ public static function register($mode = 0) $currErrorHandler = set_error_handler('var_dump'); restore_error_handler(); - if (self::MODE_WEAK === $mode) { + if (DeprecationErrorHandler::MODE_WEAK === $mode) { $colorize = function ($str) { return $str; }; } if ($currErrorHandler !== $deprecationHandler) { @@ -219,7 +219,7 @@ public static function register($mode = 0) }; $groups = array('unsilenced', 'remaining'); - if (self::MODE_WEAK_VENDORS === $mode) { + if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode) { $groups[] = 'remaining vendor'; } array_push($groups, 'legacy', 'other'); @@ -255,7 +255,7 @@ public static function register($mode = 0) $displayDeprecations($deprecations); // store failing status - $isFailing = self::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']; + $isFailing = DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']; // reset deprecations array foreach ($deprecations as $group => $arrayOrInt) { @@ -270,7 +270,7 @@ public static function register($mode = 0) } } $displayDeprecations($deprecations); - if ($isFailing || self::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) { + if ($isFailing || DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) { exit(1); } }); diff --git a/Tests/DeprecationErrorHandler/default.phpt b/Tests/DeprecationErrorHandler/default.phpt index e06e9bd8..7a0595a7 100644 --- a/Tests/DeprecationErrorHandler/default.phpt +++ b/Tests/DeprecationErrorHandler/default.phpt @@ -25,7 +25,7 @@ class Test { public static function getGroups() { - return []; + return array(); } } EOPHP diff --git a/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php b/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php index 5229a7a7..16a58246 100644 --- a/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php +++ b/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php @@ -7,7 +7,7 @@ class Test { public static function getGroups() { - return []; + return array(); } } EOPHP diff --git a/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt b/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt index 1bb15516..fddeed60 100644 --- a/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt +++ b/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt @@ -25,7 +25,7 @@ class Test { public static function getGroups() { - return []; + return array(); } } EOPHP diff --git a/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt b/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt index b37b623c..e20c7adf 100644 --- a/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt +++ b/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt @@ -25,7 +25,7 @@ class Test { public static function getGroups() { - return []; + return array(); } } EOPHP From 014bb9e86bdd8d95e546ffe083c48b3640326d47 Mon Sep 17 00:00:00 2001 From: Patrick Landolt Date: Mon, 11 Feb 2019 18:30:33 +0100 Subject: [PATCH 3/3] Update composer.json --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 24a48b60..25dcb0cd 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,7 @@ "php": ">=5.3.3" }, "suggest": { - "symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader", - "ext-zip": "Zip support is required when using bin/simple-phpunit" + "symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" }, "conflict": { "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0"