From 5dab0d4b2ac99ab22b447b615fdfdc10ec4af3d5 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 1 Jan 2019 14:42:07 +0100 Subject: [PATCH 01/49] update year in license files --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 15fc1c88..cf8b3ebe 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014-2018 Fabien Potencier +Copyright (c) 2014-2019 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 23c29c4a4eeaf4a0b81fc6cc50915f7ea1d065c3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 16 Jan 2019 10:39:14 +0100 Subject: [PATCH 02/49] switched array() to [] --- ClockMock.php | 2 +- DeprecationErrorHandler.php | 52 +++++++-------- 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/DnsMockTest.php | 98 ++++++++++++++-------------- 12 files changed, 115 insertions(+), 115 deletions(-) diff --git a/ClockMock.php b/ClockMock.php index 4c5432f2..a29edd90 100644 --- a/ClockMock.php +++ b/ClockMock.php @@ -73,7 +73,7 @@ public static function register($class) { $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, '\\')); diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index b81eff52..2f275a10 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 (DeprecationErrorHandler::MODE_DISABLED !== $mode - && DeprecationErrorHandler::MODE_WEAK !== $mode - && DeprecationErrorHandler::MODE_WEAK_VENDORS !== $mode + if (self::MODE_DISABLED !== $mode + && self::MODE_WEAK !== $mode + && self::MODE_WEAK_VENDORS !== $mode && (!isset($mode[0]) || '/' !== $mode[0]) ) { $mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0; @@ -92,21 +92,21 @@ public static function register($mode = 0) return false; }; - $deprecations = array( + $deprecations = [ 'unsilencedCount' => 0, 'remainingCount' => 0, 'legacyCount' => 0, 'otherCount' => 0, 'remaining vendorCount' => 0, - 'unsilenced' => array(), - 'remaining' => array(), - 'legacy' => array(), - 'other' => array(), - 'remaining vendor' => array(), - ); - $deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, $getMode, $UtilPrefix, $inVendors) { + 'unsilenced' => [], + 'remaining' => [], + 'legacy' => [], + 'other' => [], + 'remaining vendor' => [], + ]; + $deprecationHandler = function ($type, $msg, $file, $line, $context = []) use (&$deprecations, $getMode, $UtilPrefix, $inVendors) { $mode = $getMode(); - if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || DeprecationErrorHandler::MODE_DISABLED === $mode) { + if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || self::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 = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $inVendors($file); + $isVendor = self::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 = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && isset($parsedMsg['triggering_file']) && $inVendors($parsedMsg['triggering_file']); + $isVendor = self::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 && DeprecationErrorHandler::MODE_WEAK !== $mode) { + if ('legacy' !== $group && self::MODE_WEAK !== $mode) { $ref = &$deprecations[$group][$msg]['count']; ++$ref; $ref = &$deprecations[$group][$msg][$class.'::'.$method]; ++$ref; } - } elseif (DeprecationErrorHandler::MODE_WEAK !== $mode) { + } elseif (self::MODE_WEAK !== $mode) { $ref = &$deprecations[$group][$msg]['count']; ++$ref; } @@ -184,7 +184,7 @@ public static function register($mode = 0) if (null !== $oldErrorHandler) { restore_error_handler(); - if (array($UtilPrefix.'ErrorHandler', 'handleError') === $oldErrorHandler) { + if ([$UtilPrefix.'ErrorHandler', 'handleError'] === $oldErrorHandler) { restore_error_handler(); self::register($mode); } @@ -207,7 +207,7 @@ public static function register($mode = 0) $currErrorHandler = set_error_handler('var_dump'); restore_error_handler(); - if (DeprecationErrorHandler::MODE_WEAK === $mode) { + if (self::MODE_WEAK === $mode) { $colorize = function ($str) { return $str; }; } if ($currErrorHandler !== $deprecationHandler) { @@ -218,8 +218,8 @@ public static function register($mode = 0) return $b['count'] - $a['count']; }; - $groups = array('unsilenced', 'remaining'); - if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode) { + $groups = ['unsilenced', 'remaining']; + if (self::MODE_WEAK_VENDORS === $mode) { $groups[] = 'remaining vendor'; } array_push($groups, 'legacy', 'other'); @@ -255,11 +255,11 @@ public static function register($mode = 0) $displayDeprecations($deprecations); // store failing status - $isFailing = DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']; + $isFailing = self::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']; // reset deprecations array foreach ($deprecations as $group => $arrayOrInt) { - $deprecations[$group] = \is_int($arrayOrInt) ? 0 : array(); + $deprecations[$group] = \is_int($arrayOrInt) ? 0 : []; } register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) { @@ -270,7 +270,7 @@ public static function register($mode = 0) } } $displayDeprecations($deprecations); - if ($isFailing || DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) { + if ($isFailing || self::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) { exit(1); } }); @@ -280,8 +280,8 @@ public static function register($mode = 0) public static function collectDeprecations($outputFile) { - $deprecations = array(); - $previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, &$previousErrorHandler) { + $deprecations = []; + $previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) 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[] = array(error_reporting(), $msg, $file); + $deprecations[] = [error_reporting(), $msg, $file]; }); register_shutdown_function(function () use ($outputFile, &$deprecations) { diff --git a/DnsMock.php b/DnsMock.php index 790cfa91..a58bf2ef 100644 --- a/DnsMock.php +++ b/DnsMock.php @@ -16,8 +16,8 @@ */ 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 @@ public static function getmxrr($hostname, &$mxhosts, &$weight = null) 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 @@ public static function gethostbynamel($hostname) $ips = false; if (isset(self::$hosts[$hostname])) { - $ips = array(); + $ips = []; 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 = 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 @@ public static function register($class) { $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, '\\')); diff --git a/Legacy/CoverageListenerTrait.php b/Legacy/CoverageListenerTrait.php index 8e9bdbe9..07a9679d 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 = array(); + $this->warnings = []; } public function startTest($test) @@ -42,7 +42,7 @@ public function startTest($test) $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])) { @@ -74,11 +74,11 @@ public function startTest($test) $r->setAccessible(true); $cache = $r->getValue(); - $cache = array_replace_recursive($cache, array( - \get_class($test) => array( - 'covers' => array($sutFqcn), - ), - )); + $cache = array_replace_recursive($cache, [ + \get_class($test) => [ + 'covers' => [$sutFqcn], + ], + ]); $r->setValue($testClass, $cache); } diff --git a/Legacy/SymfonyTestsListenerForV5.php b/Legacy/SymfonyTestsListenerForV5.php index 2da40f2c..c825a8dd 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 = array()) + public function __construct(array $mockedNamespaces = []) { $this->trait = new SymfonyTestsListenerTrait($mockedNamespaces); } diff --git a/Legacy/SymfonyTestsListenerForV6.php b/Legacy/SymfonyTestsListenerForV6.php index 5b864bfe..0c0b5708 100644 --- a/Legacy/SymfonyTestsListenerForV6.php +++ b/Legacy/SymfonyTestsListenerForV6.php @@ -27,7 +27,7 @@ class SymfonyTestsListenerForV6 extends BaseTestListener { private $trait; - public function __construct(array $mockedNamespaces = array()) + public function __construct(array $mockedNamespaces = []) { $this->trait = new SymfonyTestsListenerTrait($mockedNamespaces); } diff --git a/Legacy/SymfonyTestsListenerForV7.php b/Legacy/SymfonyTestsListenerForV7.php index 18bbdbeb..25ad718a 100644 --- a/Legacy/SymfonyTestsListenerForV7.php +++ b/Legacy/SymfonyTestsListenerForV7.php @@ -30,7 +30,7 @@ class SymfonyTestsListenerForV7 implements TestListener private $trait; - public function __construct(array $mockedNamespaces = array()) + public function __construct(array $mockedNamespaces = []) { $this->trait = new SymfonyTestsListenerTrait($mockedNamespaces); } diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 6333c4fd..14043442 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 = array(); - private $isSkipped = array(); - private $expectedDeprecations = array(); - private $gatheredDeprecations = array(); + private $wasSkipped = []; + private $isSkipped = []; + private $expectedDeprecations = []; + private $gatheredDeprecations = []; 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 = array()) + public function __construct(array $mockedNamespaces = []) { 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 = array()) $warn = false; foreach ($mockedNamespaces as $type => $namespaces) { if (!\is_array($namespaces)) { - $namespaces = array($namespaces); + $namespaces = [$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 = array(); + $this->testsWithWarnings = []; 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(array()); + $suite->setTests([]); } } } - $testSuites = array($suite); + $testSuites = [$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 = array(); + $skipped = []; 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(array($this, 'handleError')); + $this->previousErrorHandler = set_error_handler([$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) : 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]) { @trigger_error($error, E_USER_DEPRECATED); } else { @@ -283,13 +283,13 @@ public function endTest($test, $time) } 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"); @@ -300,7 +300,7 @@ public function endTest($test, $time) } } - $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)) { @@ -308,7 +308,7 @@ public function endTest($test, $time) ClockMock::withClockMock(false); } if (\in_array('dns-sensitive', $groups, true)) { - DnsMock::withMockedHosts(array()); + DnsMock::withMockedHosts([]); } } @@ -329,7 +329,7 @@ public function endTest($test, $time) } } - 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; diff --git a/Legacy/TestRunnerForV5.php b/Legacy/TestRunnerForV5.php index 7897861c..1a89019f 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'] : array(); + $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : []; $registeredLocally = false; diff --git a/Legacy/TestRunnerForV6.php b/Legacy/TestRunnerForV6.php index 6da7c654..8489a586 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'] : array(); + $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : []; $registeredLocally = false; diff --git a/Legacy/TestRunnerForV7.php b/Legacy/TestRunnerForV7.php index a175fb65..bc5fff95 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'] : array(); + $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : []; $registeredLocally = false; diff --git a/Tests/DnsMockTest.php b/Tests/DnsMockTest.php index a178ac7e..ebbc87a7 100644 --- a/Tests/DnsMockTest.php +++ b/Tests/DnsMockTest.php @@ -18,15 +18,15 @@ class DnsMockTest extends TestCase { protected function tearDown() { - DnsMock::withMockedHosts(array()); + DnsMock::withMockedHosts([]); } public function testCheckdnsrr() { - DnsMock::withMockedHosts(array('example.com' => array(array('type' => 'MX')))); + DnsMock::withMockedHosts(['example.com' => [['type' => 'MX']]]); $this->assertTrue(DnsMock::checkdnsrr('example.com')); - DnsMock::withMockedHosts(array('example.com' => array(array('type' => 'A')))); + DnsMock::withMockedHosts(['example.com' => [['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(array( - 'example.com' => array(array( + DnsMock::withMockedHosts([ + 'example.com' => [[ '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(array('mx.example.com'), $mxhosts); - $this->assertSame(array(10), $weight); + $this->assertSame(['mx.example.com'], $mxhosts); + $this->assertSame([10], $weight); } public function testGethostbyaddr() { - DnsMock::withMockedHosts(array( - 'example.com' => array( - array( + DnsMock::withMockedHosts([ + 'example.com' => [ + [ '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(array( - 'example.com' => array( - array( + DnsMock::withMockedHosts([ + 'example.com' => [ + [ '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(array( - 'example.com' => array( - array( + DnsMock::withMockedHosts([ + 'example.com' => [ + [ 'type' => 'A', 'ip' => '1.2.3.4', - ), - array( + ], + [ 'type' => 'A', 'ip' => '2.3.4.5', - ), - ), - )); + ], + ], + ]); $this->assertFalse(DnsMock::gethostbynamel('foobar.com')); - $this->assertSame(array('1.2.3.4', '2.3.4.5'), DnsMock::gethostbynamel('example.com')); + $this->assertSame(['1.2.3.4', '2.3.4.5'], DnsMock::gethostbynamel('example.com')); } public function testDnsGetRecord() { - DnsMock::withMockedHosts(array( - 'example.com' => array( - array( + DnsMock::withMockedHosts([ + 'example.com' => [ + [ 'type' => 'A', 'ip' => '1.2.3.4', - ), - array( + ], + [ 'type' => 'PTR', 'ip' => '2.3.4.5', - ), - ), - )); + ], + ], + ]); - $records = array( - array( + $records = [ + [ 'host' => 'example.com', 'class' => 'IN', 'ttl' => 1, 'type' => 'A', 'ip' => '1.2.3.4', - ), - $ptr = array( + ], + $ptr = [ '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(array($ptr), DnsMock::dns_get_record('example.com', DNS_PTR)); + $this->assertSame([$ptr], DnsMock::dns_get_record('example.com', DNS_PTR)); } } From c99a6b42d7a351e3c992db4939fb97f231e97b76 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 16 Jan 2019 13:47:19 +0100 Subject: [PATCH 03/49] fixed CS in generated files --- Tests/DeprecationErrorHandler/default.phpt | 2 +- Tests/DeprecationErrorHandler/shutdown_deprecations.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/DeprecationErrorHandler/default.phpt b/Tests/DeprecationErrorHandler/default.phpt index 7a0595a7..1070b19a 100644 --- a/Tests/DeprecationErrorHandler/default.phpt +++ b/Tests/DeprecationErrorHandler/default.phpt @@ -35,7 +35,7 @@ class PHPUnit_Util_Test { public static function getGroups() { - return array(); + return []; } } diff --git a/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt b/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt index fddeed60..a0bf3e2b 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 array(); + return []; } } From d61ec438634e0f234c6bda1c6ee97016bbb0e7a1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 16 Jan 2019 14:03:22 +0100 Subject: [PATCH 04/49] fixed short array CS in comments --- Tests/DeprecationErrorHandler/default.phpt | 2 +- .../acme/lib/deprecation_riddled.php | 2 +- .../shutdown_deprecations.phpt | 2 +- .../weak_vendors_on_non_vendor.phpt | 2 +- bin/simple-phpunit | 18 +++++++++--------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Tests/DeprecationErrorHandler/default.phpt b/Tests/DeprecationErrorHandler/default.phpt index 1070b19a..9bc155a7 100644 --- a/Tests/DeprecationErrorHandler/default.phpt +++ b/Tests/DeprecationErrorHandler/default.phpt @@ -25,7 +25,7 @@ class Test { public static function getGroups() { - return array(); + return []; } } EOPHP diff --git a/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php b/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php index 16a58246..5229a7a7 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 array(); + return []; } } EOPHP diff --git a/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt b/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt index a0bf3e2b..703db6fd 100644 --- a/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt +++ b/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt @@ -25,7 +25,7 @@ class Test { public static function getGroups() { - return array(); + return []; } } EOPHP diff --git a/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt b/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt index e20c7adf..b37b623c 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 array(); + return []; } } EOPHP diff --git a/bin/simple-phpunit b/bin/simple-phpunit index af60eb0f..a8528d73 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -83,7 +83,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", array(), $p, getcwd(), null, array('bypass_shell' => true))); + $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-progress --ansi", [], $p, getcwd(), null, ['bypass_shell' => true])); putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : '')); if ($exit) { exit($exit); @@ -116,9 +116,9 @@ EOPHP } global $argv, $argc; -$argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); +$argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : []; $argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0; -$components = array(); +$components = []; $cmd = array_map('escapeshellarg', $argv); $exit = 0; @@ -153,7 +153,7 @@ if ('\\' === DIRECTORY_SEPARATOR) { if ($components) { $skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false; - $runningProcs = array(); + $runningProcs = []; foreach ($components as $component) { // Run phpunit tests in parallel @@ -164,7 +164,7 @@ if ($components) { $c = escapeshellarg($component); - if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) { + if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), [], $pipes)) { $runningProcs[$component] = $proc; } else { $exit = 1; @@ -174,7 +174,7 @@ if ($components) { while ($runningProcs) { usleep(300000); - $terminatedProcs = array(); + $terminatedProcs = []; foreach ($runningProcs as $component => $proc) { $procStatus = proc_get_status($proc); if (!$procStatus['running']) { @@ -185,7 +185,7 @@ if ($components) { } foreach ($terminatedProcs as $component => $procStatus) { - foreach (array('out', 'err') as $file) { + foreach (['out', 'err'] as $file) { $file = "$component/phpunit.std$file"; readfile($file); unlink($file); @@ -195,7 +195,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, array(-1073740791, -1073741819, -1073740940)))) { + if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN) || !in_array($procStatus, [-1073740791, -1073741819, -1073740940]))) { $exit = $procStatus; echo "\033[41mKO\033[0m $component\n\n"; } else { @@ -207,7 +207,7 @@ if ($components) { if (!class_exists('SymfonyBlacklistSimplePhpunit', false)) { class SymfonyBlacklistSimplePhpunit {} } - array_splice($argv, 1, 0, array('--colors=always')); + array_splice($argv, 1, 0, ['--colors=always']); $_SERVER['argv'] = $argv; $_SERVER['argc'] = ++$argc; include "$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"; From 60080cd9a5e6209339becb01f32671a9f5f1c09a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 24 Jan 2019 22:26:46 +0100 Subject: [PATCH 05/49] [appveyor] fix create-project phpunit --- bin/simple-phpunit | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index a8528d73..ff6ce806 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -61,7 +61,9 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ @mkdir($PHPUNIT_DIR, 0777, true); chdir($PHPUNIT_DIR); if (file_exists("phpunit-$PHPUNIT_VERSION")) { - passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION")); + passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s > NUL': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old")); + rename("phpunit-$PHPUNIT_VERSION", "phpunit-$PHPUNIT_VERSION.old"); + passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old")); } passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\""); chdir("phpunit-$PHPUNIT_VERSION"); From 6a2148bfc6ca0016846a32bdc55a317274283709 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 30 Jan 2019 14:15:47 +0100 Subject: [PATCH 06/49] 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 07/49] [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 08/49] 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" From b539f37134c10edbf85dc0567be4151c56870f5e Mon Sep 17 00:00:00 2001 From: Gocha Ossinkine Date: Thu, 14 Feb 2019 21:08:19 +0500 Subject: [PATCH 09/49] Don't resolve the Deprecation error handler mode until a deprecation is triggered --- DeprecationErrorHandler.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index b81eff52..fc60cbd4 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -105,8 +105,7 @@ public static function register($mode = 0) '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) || DeprecationErrorHandler::MODE_DISABLED === $mode) { + if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || DeprecationErrorHandler::MODE_DISABLED === $mode = $getMode()) { $ErrorHandler = $UtilPrefix.'ErrorHandler'; return $ErrorHandler::handleError($type, $msg, $file, $line, $context); From 292b4248a5694b4891148e7df9aad7b6811ae63d Mon Sep 17 00:00:00 2001 From: nicoweb Date: Fri, 8 Mar 2019 22:50:51 +0100 Subject: [PATCH 10/49] [PHPUnit-Bridge] override some environment variables --- bin/simple-phpunit | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 2e23aa89..5d203730 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -26,10 +26,7 @@ if (PHP_VERSION_ID >= 70200) { $PHPUNIT_VERSION = '4.8'; } -if ('composer.json' !== $COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json') { - putenv('COMPOSER=composer.json'); - $_SERVER['COMPOSER'] = $_ENV['COMPOSER'] = 'composer.json'; -} +$COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json'; $root = __DIR__; while (!file_exists($root.'/'.$COMPOSER_JSON) || file_exists($root.'/DeprecationErrorHandler.php')) { @@ -47,6 +44,19 @@ if ('phpdbg' === PHP_SAPI) { $PHP .= ' -qrr'; } +$defaultEnvs = [ + 'COMPOSER' => 'composer.json', + 'COMPOSER_VENDOR_DIR' => 'vendor', + 'COMPOSER_BIN_DIR' => 'bin', +]; + +foreach ($defaultEnvs as $envName => $envValue) { + if ($envValue !== getenv($envName)) { + putenv("$envName=$envValue"); + $_SERVER[$envName] = $_ENV[$envName] = $envValue; + } +} + $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`)) ? $PHP.' '.escapeshellarg($COMPOSER) : 'composer'; From bf7ca5d4d7eb1758a1f7bed11111f630ac2d4f57 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 22 Mar 2019 09:11:54 +0100 Subject: [PATCH 11/49] [Phpunit] fixed support for PHP 5.3 --- bin/simple-phpunit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 5d203730..c81dcd26 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -44,11 +44,11 @@ if ('phpdbg' === PHP_SAPI) { $PHP .= ' -qrr'; } -$defaultEnvs = [ +$defaultEnvs = array( 'COMPOSER' => 'composer.json', 'COMPOSER_VENDOR_DIR' => 'vendor', 'COMPOSER_BIN_DIR' => 'bin', -]; +); foreach ($defaultEnvs as $envName => $envValue) { if ($envValue !== getenv($envName)) { From ae40e4d07de588029cd06f0fce6cdc878de7d926 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 2 Apr 2019 17:51:53 +0200 Subject: [PATCH 12/49] Prevent destructors with side-effects from being unserialized --- Legacy/SymfonyTestsListenerTrait.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 6333c4fd..2c7391a0 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -83,6 +83,16 @@ public function __construct(array $mockedNamespaces = array()) } } + public function __sleep() + { + throw new \BadMethodCallException('Cannot serialize '.__CLASS__); + } + + public function __wakeup() + { + throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); + } + public function __destruct() { if (0 < $this->state) { From 71fb02e83f0bdf9e83f4a557eec64abaf236284c Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 6 Feb 2019 00:57:29 +0100 Subject: [PATCH 13/49] Fix TestRunner compatibility to PhpUnit 8 --- Legacy/CommandForV5.php | 20 +++++++++++++++- Legacy/CommandForV6.php | 22 +++++++++++++++-- Legacy/TestRunnerForV5.php | 48 ------------------------------------- Legacy/TestRunnerForV6.php | 49 -------------------------------------- Legacy/TestRunnerForV7.php | 49 -------------------------------------- TextUI/TestRunner.php | 26 -------------------- 6 files changed, 39 insertions(+), 175 deletions(-) delete mode 100644 Legacy/TestRunnerForV5.php delete mode 100644 Legacy/TestRunnerForV6.php delete mode 100644 Legacy/TestRunnerForV7.php delete mode 100644 TextUI/TestRunner.php diff --git a/Legacy/CommandForV5.php b/Legacy/CommandForV5.php index d4b5ea26..95dcb1e5 100644 --- a/Legacy/CommandForV5.php +++ b/Legacy/CommandForV5.php @@ -23,6 +23,24 @@ class CommandForV5 extends \PHPUnit_TextUI_Command */ protected function createRunner() { - return new TestRunnerForV5($this->arguments['loader']); + $listener = new SymfonyTestsListenerForV5(); + + $this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : array(); + + $registeredLocally = false; + + foreach ($this->arguments['listeners'] as $registeredListener) { + if ($registeredListener instanceof SymfonyTestsListenerForV5) { + $registeredListener->globalListenerDisabled(); + $registeredLocally = true; + break; + } + } + + if (!$registeredLocally) { + $this->arguments['listeners'][] = $listener; + } + + return parent::createRunner(); } } diff --git a/Legacy/CommandForV6.php b/Legacy/CommandForV6.php index fc717ef4..f8f75bb0 100644 --- a/Legacy/CommandForV6.php +++ b/Legacy/CommandForV6.php @@ -13,7 +13,7 @@ use PHPUnit\TextUI\Command as BaseCommand; use PHPUnit\TextUI\TestRunner as BaseRunner; -use Symfony\Bridge\PhpUnit\TextUI\TestRunner; +use Symfony\Bridge\PhpUnit\SymfonyTestsListener; /** * {@inheritdoc} @@ -27,6 +27,24 @@ class CommandForV6 extends BaseCommand */ protected function createRunner(): BaseRunner { - return new TestRunner($this->arguments['loader']); + $listener = new SymfonyTestsListener(); + + $this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : []; + + $registeredLocally = false; + + foreach ($this->arguments['listeners'] as $registeredListener) { + if ($registeredListener instanceof SymfonyTestsListener) { + $registeredListener->globalListenerDisabled(); + $registeredLocally = true; + break; + } + } + + if (!$registeredLocally) { + $this->arguments['listeners'][] = $listener; + } + + return parent::createRunner(); } } diff --git a/Legacy/TestRunnerForV5.php b/Legacy/TestRunnerForV5.php deleted file mode 100644 index 7897861c..00000000 --- a/Legacy/TestRunnerForV5.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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 TestRunnerForV5 extends \PHPUnit_TextUI_TestRunner -{ - /** - * {@inheritdoc} - */ - protected function handleConfiguration(array &$arguments) - { - $listener = new SymfonyTestsListenerForV5(); - - $result = parent::handleConfiguration($arguments); - - $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array(); - - $registeredLocally = false; - - foreach ($arguments['listeners'] as $registeredListener) { - if ($registeredListener instanceof SymfonyTestsListenerForV5) { - $registeredListener->globalListenerDisabled(); - $registeredLocally = true; - break; - } - } - - if (!$registeredLocally) { - $arguments['listeners'][] = $listener; - } - - return $result; - } -} diff --git a/Legacy/TestRunnerForV6.php b/Legacy/TestRunnerForV6.php deleted file mode 100644 index 6da7c654..00000000 --- a/Legacy/TestRunnerForV6.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * 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\TextUI\TestRunner as BaseRunner; -use Symfony\Bridge\PhpUnit\SymfonyTestsListener; - -/** - * {@inheritdoc} - * - * @internal - */ -class TestRunnerForV6 extends BaseRunner -{ - /** - * {@inheritdoc} - */ - protected function handleConfiguration(array &$arguments) - { - $listener = new SymfonyTestsListener(); - - parent::handleConfiguration($arguments); - - $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array(); - - $registeredLocally = false; - - foreach ($arguments['listeners'] as $registeredListener) { - if ($registeredListener instanceof SymfonyTestsListener) { - $registeredListener->globalListenerDisabled(); - $registeredLocally = true; - break; - } - } - - if (!$registeredLocally) { - $arguments['listeners'][] = $listener; - } - } -} diff --git a/Legacy/TestRunnerForV7.php b/Legacy/TestRunnerForV7.php deleted file mode 100644 index a175fb65..00000000 --- a/Legacy/TestRunnerForV7.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * 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\TextUI\TestRunner as BaseRunner; -use Symfony\Bridge\PhpUnit\SymfonyTestsListener; - -/** - * {@inheritdoc} - * - * @internal - */ -class TestRunnerForV7 extends BaseRunner -{ - /** - * {@inheritdoc} - */ - protected function handleConfiguration(array &$arguments): void - { - $listener = new SymfonyTestsListener(); - - parent::handleConfiguration($arguments); - - $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array(); - - $registeredLocally = false; - - foreach ($arguments['listeners'] as $registeredListener) { - if ($registeredListener instanceof SymfonyTestsListener) { - $registeredListener->globalListenerDisabled(); - $registeredLocally = true; - break; - } - } - - if (!$registeredLocally) { - $arguments['listeners'][] = $listener; - } - } -} diff --git a/TextUI/TestRunner.php b/TextUI/TestRunner.php deleted file mode 100644 index cda59209..00000000 --- a/TextUI/TestRunner.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bridge\PhpUnit\TextUI; - -if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) { - class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunnerForV5', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner'); -} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '<')) { - class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunnerForV6', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner'); -} else { - class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunnerForV7', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner'); -} - -if (false) { - class TestRunner - { - } -} From 520ecf1a05d7bb9dc6f91bb4e408d797bc598041 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 9 Jun 2019 16:27:26 +0200 Subject: [PATCH 14/49] Fix reporting unsilenced deprecations from insulated tests --- Legacy/SymfonyTestsListenerTrait.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 2c7391a0..481a860a 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -284,7 +284,8 @@ public function endTest($test, $time) 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); + // unsilenced on purpose + trigger_error($error, E_USER_DEPRECATED); } else { @trigger_error($error, E_USER_DEPRECATED); } From 521489968e58dcdb8df153436cc18349737e49e3 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 26 Jun 2019 12:03:25 +0200 Subject: [PATCH 15/49] Bump phpunit-bridge --- bin/simple-phpunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index c81dcd26..c0f4b782 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -11,7 +11,7 @@ */ // Please update when phpunit needs to be reinstalled with fresh deps: -// Cache-Id-Version: 2018-11-20 15:30 UTC +// Cache-Id-Version: 2019-06-26 11:00 UTC error_reporting(-1); From bff3272369c714cfdcbc698ac3e53c8da665b97b Mon Sep 17 00:00:00 2001 From: misterx <216417+misterx@users.noreply.github.com> Date: Wed, 26 Jun 2019 14:51:54 +0300 Subject: [PATCH 16/49] Fixes windows error --- bin/simple-phpunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index c0f4b782..3f5d1457 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -95,7 +95,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", array(), $p, getcwd(), null, array('bypass_shell' => true))); + $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-progress --ansi", array(), $p)); putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : '')); if ($exit) { exit($exit); From 27b93ee75a3a3c40a2ea26105f09159db0d0d53b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 4 Jul 2019 18:09:01 +0200 Subject: [PATCH 17/49] [Bridge/PhpUnit] fix running composer to install phpunit --- bin/simple-phpunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 3f5d1457..04e0ed46 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -95,7 +95,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", array(), $p)); + $exit = proc_close(proc_open("$COMPOSER install --no-dev --prefer-dist --no-progress --ansi", array(), $p, getcwd())); putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : '')); if ($exit) { exit($exit); From 740128a831a16f36c822e2329ee29e8d015ee75a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 4 Jul 2019 19:06:26 +0200 Subject: [PATCH 18/49] bump phpunit-bridge cache ids --- bin/simple-phpunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 04e0ed46..49b88ed9 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -11,7 +11,7 @@ */ // Please update when phpunit needs to be reinstalled with fresh deps: -// Cache-Id-Version: 2019-06-26 11:00 UTC +// Cache-Id-Version: 2019-07-04 18:00 UTC error_reporting(-1); From 8f1f27c186496128b861810809c27d956d342417 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 5 Jul 2019 08:33:15 +0200 Subject: [PATCH 19/49] [PhpUnitBridge] fix running simple-phpunit on Windows --- bin/simple-phpunit | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 49b88ed9..7afcbeed 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -94,8 +94,9 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ } $prevRoot = getenv('COMPOSER_ROOT_VERSION'); putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99"); + $q = '\\' === DIRECTORY_SEPARATOR ? '"' : ''; // --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", array(), $p, getcwd())); + $exit = proc_close(proc_open("$q$COMPOSER install --no-dev --prefer-dist --no-progress --ansi$q", array(), $p, getcwd())); putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : '')); if ($exit) { exit($exit); From 29581411a7740da0d5f0851c8b0ac83b89f2493f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 31 Jul 2019 21:19:25 +0200 Subject: [PATCH 20/49] Make tests support phpunit 8 --- ForwardCompatTestTrait.php | 28 +++++++++ Legacy/ForwardCompatTestTraitForV5.php | 82 ++++++++++++++++++++++++++ Legacy/ForwardCompatTestTraitForV8.php | 58 ++++++++++++++++++ Tests/ClockMockTest.php | 7 ++- Tests/DnsMockTest.php | 5 +- 5 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 ForwardCompatTestTrait.php create mode 100644 Legacy/ForwardCompatTestTraitForV5.php create mode 100644 Legacy/ForwardCompatTestTraitForV8.php diff --git a/ForwardCompatTestTrait.php b/ForwardCompatTestTrait.php new file mode 100644 index 00000000..bdff8c18 --- /dev/null +++ b/ForwardCompatTestTrait.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\PhpUnit; + +use PHPUnit\Framework\TestCase; + +// A trait to provide forward compatibility with newest PHPUnit versions + +if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) { + trait ForwardCompatTestTrait + { + use Legacy\ForwardCompatTestTraitForV8; + } +} else { + trait ForwardCompatTestTrait + { + use Legacy\ForwardCompatTestTraitForV5; + } +} diff --git a/Legacy/ForwardCompatTestTraitForV5.php b/Legacy/ForwardCompatTestTraitForV5.php new file mode 100644 index 00000000..5b35e801 --- /dev/null +++ b/Legacy/ForwardCompatTestTraitForV5.php @@ -0,0 +1,82 @@ + + * + * 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 ForwardCompatTestTraitForV5 +{ + /** + * @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(); + } + + /** + * @return void + */ + private static function doSetUpBeforeClass() + { + parent::setUpBeforeClass(); + } + + /** + * @return void + */ + private static function doTearDownAfterClass() + { + parent::tearDownAfterClass(); + } + + /** + * @return void + */ + private function doSetUp() + { + parent::setUp(); + } + + /** + * @return void + */ + private function doTearDown() + { + parent::tearDown(); + } +} diff --git a/Legacy/ForwardCompatTestTraitForV8.php b/Legacy/ForwardCompatTestTraitForV8.php new file mode 100644 index 00000000..4963ed9e --- /dev/null +++ b/Legacy/ForwardCompatTestTraitForV8.php @@ -0,0 +1,58 @@ + + * + * 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 ForwardCompatTestTraitForV8 +{ + public static function setUpBeforeClass(): void + { + self::doSetUpBeforeClass(); + } + + public static function tearDownAfterClass(): void + { + self::doTearDownAfterClass(); + } + + protected function setUp(): void + { + self::doSetUp(); + } + + protected function tearDown(): void + { + self::doTearDown(); + } + + private static function doSetUpBeforeClass(): void + { + parent::setUpBeforeClass(); + } + + private static function doTearDownAfterClass(): void + { + parent::tearDownAfterClass(); + } + + private function doSetUp(): void + { + parent::setUp(); + } + + private function doTearDown(): void + { + parent::tearDown(); + } +} diff --git a/Tests/ClockMockTest.php b/Tests/ClockMockTest.php index 82cfb6f5..75a494db 100644 --- a/Tests/ClockMockTest.php +++ b/Tests/ClockMockTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ClockMock; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; /** * @author Dominic Tubach @@ -21,12 +22,14 @@ */ class ClockMockTest extends TestCase { - public static function setUpBeforeClass() + use ForwardCompatTestTrait; + + private static function doSetUpBeforeClass() { ClockMock::register(__CLASS__); } - protected function setUp() + private function doSetUp() { ClockMock::withClockMock(1234567890.125); } diff --git a/Tests/DnsMockTest.php b/Tests/DnsMockTest.php index a178ac7e..4ef2d75b 100644 --- a/Tests/DnsMockTest.php +++ b/Tests/DnsMockTest.php @@ -13,10 +13,13 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\DnsMock; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; class DnsMockTest extends TestCase { - protected function tearDown() + use ForwardCompatTestTrait; + + private function doTearDown() { DnsMock::withMockedHosts(array()); } From 3f52c99d945b058ef81e8ebd40ec18485bf56530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 1 Aug 2019 09:31:22 +0200 Subject: [PATCH 21/49] Fix assertInternalType deprecation in phpunit 9 --- Legacy/ForwardCompatTestTraitForV5.php | 110 +++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/Legacy/ForwardCompatTestTraitForV5.php b/Legacy/ForwardCompatTestTraitForV5.php index 5b35e801..5ef83743 100644 --- a/Legacy/ForwardCompatTestTraitForV5.php +++ b/Legacy/ForwardCompatTestTraitForV5.php @@ -79,4 +79,114 @@ private function doTearDown() { parent::tearDown(); } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsArray($actual, $message = '') + { + static::assertInternalType('array', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsBool($actual, $message = '') + { + static::assertInternalType('bool', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsFloat($actual, $message = '') + { + static::assertInternalType('float', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsInt($actual, $message = '') + { + static::assertInternalType('int', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsNumeric($actual, $message = '') + { + static::assertInternalType('numeric', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsObject($actual, $message = '') + { + static::assertInternalType('object', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsResource($actual, $message = '') + { + static::assertInternalType('resource', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsString($actual, $message = '') + { + static::assertInternalType('string', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsScalar($actual, $message = '') + { + static::assertInternalType('scalar', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsCallable($actual, $message = '') + { + static::assertInternalType('callable', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsIterable($actual, $message = '') + { + static::assertInternalType('iterable', $actual, $message); + } } From 94d4943247a63e4b36568f77ed1a3495288c26c6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Aug 2019 14:45:14 +0200 Subject: [PATCH 22/49] Add polyfill for TestCase::createMock() --- ForwardCompatTestTrait.php | 11 ++++++-- Legacy/ForwardCompatTestTraitForV5.php | 21 ++++++++++++++++ Legacy/ForwardCompatTestTraitForV7.php | 35 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 Legacy/ForwardCompatTestTraitForV7.php diff --git a/ForwardCompatTestTrait.php b/ForwardCompatTestTrait.php index bdff8c18..29597bbe 100644 --- a/ForwardCompatTestTrait.php +++ b/ForwardCompatTestTrait.php @@ -15,7 +15,14 @@ // A trait to provide forward compatibility with newest PHPUnit versions -if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) { +$r = new \ReflectionClass(TestCase::class); + +if (\PHP_VERSION_ID < 70000 || !$r->hasMethod('createMock') || !$r->getMethod('createMock')->hasReturnType()) { + trait ForwardCompatTestTrait + { + use Legacy\ForwardCompatTestTraitForV5; + } +} elseif ($r->getMethod('tearDown')->hasReturnType()) { trait ForwardCompatTestTrait { use Legacy\ForwardCompatTestTraitForV8; @@ -23,6 +30,6 @@ trait ForwardCompatTestTrait } else { trait ForwardCompatTestTrait { - use Legacy\ForwardCompatTestTraitForV5; + use Legacy\ForwardCompatTestTraitForV7; } } diff --git a/Legacy/ForwardCompatTestTraitForV5.php b/Legacy/ForwardCompatTestTraitForV5.php index 5ef83743..36db32e5 100644 --- a/Legacy/ForwardCompatTestTraitForV5.php +++ b/Legacy/ForwardCompatTestTraitForV5.php @@ -11,6 +11,8 @@ namespace Symfony\Bridge\PhpUnit\Legacy; +use PHPUnit\Framework\MockObject\MockObject; + /** * @internal */ @@ -80,6 +82,25 @@ private function doTearDown() parent::tearDown(); } + /** + * @param string $originalClassName + * + * @return MockObject + */ + protected function createMock($originalClassName) + { + $mock = $this->getMockBuilder($originalClassName) + ->disableOriginalConstructor() + ->disableOriginalClone() + ->disableArgumentCloning(); + + if (method_exists($mock, 'disallowMockingUnknownTypes')) { + $mock = $mock->disallowMockingUnknownTypes(); + } + + return $mock->getMock(); + } + /** * @param string $message * diff --git a/Legacy/ForwardCompatTestTraitForV7.php b/Legacy/ForwardCompatTestTraitForV7.php new file mode 100644 index 00000000..84a26fae --- /dev/null +++ b/Legacy/ForwardCompatTestTraitForV7.php @@ -0,0 +1,35 @@ + + * + * 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\MockObject\MockObject; + +/** + * @internal + */ +trait ForwardCompatTestTraitForV7 +{ + use ForwardCompatTestTraitForV5; + + /** + * @param string|string[] $originalClassName + */ + protected function createMock($originalClassName): MockObject + { + return $this->getMockBuilder($originalClassName) + ->disableOriginalConstructor() + ->disableOriginalClone() + ->disableArgumentCloning() + ->disallowMockingUnknownTypes() + ->getMock(); + } +} From bafb78a66beaf264d5b3ecbe21f8c6dbc7aa6193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 1 Aug 2019 16:07:07 +0200 Subject: [PATCH 23/49] Fix symfony/phpunit-bridge not up to date in phpunit 4.8 test suite --- bin/simple-phpunit | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 7afcbeed..85a2cde0 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -83,6 +83,8 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); } + + passthru("$COMPOSER config --unset platform"); if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) { passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\""); passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path))); From 0c35d1e543f692492b3596fd1c4a2de825c79ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 1 Aug 2019 16:27:42 +0200 Subject: [PATCH 24/49] Replace calls to setExpectedException by Pollyfill --- Legacy/ForwardCompatTestTraitForV5.php | 93 ++++++++++++++++++++++++++ Tests/ProcessIsolationTest.php | 11 ++- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/Legacy/ForwardCompatTestTraitForV5.php b/Legacy/ForwardCompatTestTraitForV5.php index 36db32e5..83f7db40 100644 --- a/Legacy/ForwardCompatTestTraitForV5.php +++ b/Legacy/ForwardCompatTestTraitForV5.php @@ -12,12 +12,16 @@ namespace Symfony\Bridge\PhpUnit\Legacy; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** * @internal */ trait ForwardCompatTestTraitForV5 { + private $forwardCompatExpectedExceptionMessage = ''; + private $forwardCompatExpectedExceptionCode = null; + /** * @return void */ @@ -210,4 +214,93 @@ public static function assertIsIterable($actual, $message = '') { static::assertInternalType('iterable', $actual, $message); } + + /** + * @param string $exception + * + * @return void + */ + public function expectException($exception) + { + if (method_exists(TestCase::class, 'expectException')) { + parent::expectException($exception); + + return; + } + + parent::setExpectedException($exception, $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode); + } + + /** + * @return void + */ + public function expectExceptionCode($code) + { + if (method_exists(TestCase::class, 'expectExceptionCode')) { + parent::expectExceptionCode($code); + + return; + } + + $this->forwardCompatExpectedExceptionCode = $code; + parent::setExpectedException(parent::getExpectedException(), $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode); + } + + /** + * @param string $message + * + * @return void + */ + public function expectExceptionMessage($message) + { + if (method_exists(TestCase::class, 'expectExceptionMessage')) { + parent::expectExceptionMessage($message); + + return; + } + + $this->forwardCompatExpectedExceptionMessage = $message; + parent::setExpectedException(parent::getExpectedException(), $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode); + } + + /** + * @param string $messageRegExp + * + * @return void + */ + public function expectExceptionMessageRegExp($messageRegExp) + { + if (method_exists(TestCase::class, 'expectExceptionMessageRegExp')) { + parent::expectExceptionMessageRegExp($messageRegExp); + + return; + } + + parent::setExpectedExceptionRegExp(parent::getExpectedException(), $messageRegExp, $this->forwardCompatExpectedExceptionCode); + } + + /** + * @param string $exceptionMessage + * + * @return void + */ + public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null) + { + $this->forwardCompatExpectedExceptionMessage = $exceptionMessage; + $this->forwardCompatExpectedExceptionCode = $exceptionCode; + + parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode); + } + + /** + * @param string $exceptionMessageRegExp + * + * @return void + */ + public function setExpectedExceptionRegExp($exceptionName, $exceptionMessageRegExp = '', $exceptionCode = null) + { + $this->forwardCompatExpectedExceptionCode = $exceptionCode; + + parent::setExpectedExceptionRegExp($exceptionName, $exceptionMessageRegExp, $exceptionCode); + } } diff --git a/Tests/ProcessIsolationTest.php b/Tests/ProcessIsolationTest.php index ec8f124a..b75ff1cf 100644 --- a/Tests/ProcessIsolationTest.php +++ b/Tests/ProcessIsolationTest.php @@ -3,6 +3,7 @@ namespace Symfony\Bridge\PhpUnit\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; /** * Don't remove this test case, it tests the legacy group. @@ -13,6 +14,8 @@ */ class ProcessIsolationTest extends TestCase { + use ForwardCompatTestTrait; + /** * @expectedDeprecation Test abc */ @@ -25,12 +28,8 @@ public function testIsolation() public function testCallingOtherErrorHandler() { $class = class_exists('PHPUnit\Framework\Exception') ? 'PHPUnit\Framework\Exception' : 'PHPUnit_Framework_Exception'; - if (method_exists($this, 'expectException')) { - $this->expectException($class); - $this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.'); - } else { - $this->setExpectedException($class, 'Test that PHPUnit\'s error handler fires.'); - } + $this->expectException($class); + $this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.'); trigger_error('Test that PHPUnit\'s error handler fires.', E_USER_WARNING); } From 05e3089e153dc54ab9470fed3fd8f8f03a7112e7 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Aug 2019 23:06:09 +0200 Subject: [PATCH 25/49] cs fix --- Legacy/ForwardCompatTestTraitForV7.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Legacy/ForwardCompatTestTraitForV7.php b/Legacy/ForwardCompatTestTraitForV7.php index 84a26fae..f77239ef 100644 --- a/Legacy/ForwardCompatTestTraitForV7.php +++ b/Legacy/ForwardCompatTestTraitForV7.php @@ -30,6 +30,6 @@ protected function createMock($originalClassName): MockObject ->disableOriginalClone() ->disableArgumentCloning() ->disallowMockingUnknownTypes() - ->getMock(); + ->getMock(); } } From 9ea2af322fda3240fb41e0b27620624fe0d2e1b9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 2 Aug 2019 16:07:32 +0200 Subject: [PATCH 26/49] Run the phpunit-bridge from a PR --- ForwardCompatTestTrait.php | 35 --- Legacy/ForwardCompatTestTraitForV5.php | 306 ------------------------- Legacy/ForwardCompatTestTraitForV7.php | 35 --- Legacy/ForwardCompatTestTraitForV8.php | 58 ----- 4 files changed, 434 deletions(-) delete mode 100644 ForwardCompatTestTrait.php delete mode 100644 Legacy/ForwardCompatTestTraitForV5.php delete mode 100644 Legacy/ForwardCompatTestTraitForV7.php delete mode 100644 Legacy/ForwardCompatTestTraitForV8.php diff --git a/ForwardCompatTestTrait.php b/ForwardCompatTestTrait.php deleted file mode 100644 index 29597bbe..00000000 --- a/ForwardCompatTestTrait.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bridge\PhpUnit; - -use PHPUnit\Framework\TestCase; - -// A trait to provide forward compatibility with newest PHPUnit versions - -$r = new \ReflectionClass(TestCase::class); - -if (\PHP_VERSION_ID < 70000 || !$r->hasMethod('createMock') || !$r->getMethod('createMock')->hasReturnType()) { - trait ForwardCompatTestTrait - { - use Legacy\ForwardCompatTestTraitForV5; - } -} elseif ($r->getMethod('tearDown')->hasReturnType()) { - trait ForwardCompatTestTrait - { - use Legacy\ForwardCompatTestTraitForV8; - } -} else { - trait ForwardCompatTestTrait - { - use Legacy\ForwardCompatTestTraitForV7; - } -} diff --git a/Legacy/ForwardCompatTestTraitForV5.php b/Legacy/ForwardCompatTestTraitForV5.php deleted file mode 100644 index 83f7db40..00000000 --- a/Legacy/ForwardCompatTestTraitForV5.php +++ /dev/null @@ -1,306 +0,0 @@ - - * - * 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\MockObject\MockObject; -use PHPUnit\Framework\TestCase; - -/** - * @internal - */ -trait ForwardCompatTestTraitForV5 -{ - private $forwardCompatExpectedExceptionMessage = ''; - private $forwardCompatExpectedExceptionCode = null; - - /** - * @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(); - } - - /** - * @return void - */ - private static function doSetUpBeforeClass() - { - parent::setUpBeforeClass(); - } - - /** - * @return void - */ - private static function doTearDownAfterClass() - { - parent::tearDownAfterClass(); - } - - /** - * @return void - */ - private function doSetUp() - { - parent::setUp(); - } - - /** - * @return void - */ - private function doTearDown() - { - parent::tearDown(); - } - - /** - * @param string $originalClassName - * - * @return MockObject - */ - protected function createMock($originalClassName) - { - $mock = $this->getMockBuilder($originalClassName) - ->disableOriginalConstructor() - ->disableOriginalClone() - ->disableArgumentCloning(); - - if (method_exists($mock, 'disallowMockingUnknownTypes')) { - $mock = $mock->disallowMockingUnknownTypes(); - } - - return $mock->getMock(); - } - - /** - * @param string $message - * - * @return void - */ - public static function assertIsArray($actual, $message = '') - { - static::assertInternalType('array', $actual, $message); - } - - /** - * @param string $message - * - * @return void - */ - public static function assertIsBool($actual, $message = '') - { - static::assertInternalType('bool', $actual, $message); - } - - /** - * @param string $message - * - * @return void - */ - public static function assertIsFloat($actual, $message = '') - { - static::assertInternalType('float', $actual, $message); - } - - /** - * @param string $message - * - * @return void - */ - public static function assertIsInt($actual, $message = '') - { - static::assertInternalType('int', $actual, $message); - } - - /** - * @param string $message - * - * @return void - */ - public static function assertIsNumeric($actual, $message = '') - { - static::assertInternalType('numeric', $actual, $message); - } - - /** - * @param string $message - * - * @return void - */ - public static function assertIsObject($actual, $message = '') - { - static::assertInternalType('object', $actual, $message); - } - - /** - * @param string $message - * - * @return void - */ - public static function assertIsResource($actual, $message = '') - { - static::assertInternalType('resource', $actual, $message); - } - - /** - * @param string $message - * - * @return void - */ - public static function assertIsString($actual, $message = '') - { - static::assertInternalType('string', $actual, $message); - } - - /** - * @param string $message - * - * @return void - */ - public static function assertIsScalar($actual, $message = '') - { - static::assertInternalType('scalar', $actual, $message); - } - - /** - * @param string $message - * - * @return void - */ - public static function assertIsCallable($actual, $message = '') - { - static::assertInternalType('callable', $actual, $message); - } - - /** - * @param string $message - * - * @return void - */ - public static function assertIsIterable($actual, $message = '') - { - static::assertInternalType('iterable', $actual, $message); - } - - /** - * @param string $exception - * - * @return void - */ - public function expectException($exception) - { - if (method_exists(TestCase::class, 'expectException')) { - parent::expectException($exception); - - return; - } - - parent::setExpectedException($exception, $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode); - } - - /** - * @return void - */ - public function expectExceptionCode($code) - { - if (method_exists(TestCase::class, 'expectExceptionCode')) { - parent::expectExceptionCode($code); - - return; - } - - $this->forwardCompatExpectedExceptionCode = $code; - parent::setExpectedException(parent::getExpectedException(), $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode); - } - - /** - * @param string $message - * - * @return void - */ - public function expectExceptionMessage($message) - { - if (method_exists(TestCase::class, 'expectExceptionMessage')) { - parent::expectExceptionMessage($message); - - return; - } - - $this->forwardCompatExpectedExceptionMessage = $message; - parent::setExpectedException(parent::getExpectedException(), $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode); - } - - /** - * @param string $messageRegExp - * - * @return void - */ - public function expectExceptionMessageRegExp($messageRegExp) - { - if (method_exists(TestCase::class, 'expectExceptionMessageRegExp')) { - parent::expectExceptionMessageRegExp($messageRegExp); - - return; - } - - parent::setExpectedExceptionRegExp(parent::getExpectedException(), $messageRegExp, $this->forwardCompatExpectedExceptionCode); - } - - /** - * @param string $exceptionMessage - * - * @return void - */ - public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null) - { - $this->forwardCompatExpectedExceptionMessage = $exceptionMessage; - $this->forwardCompatExpectedExceptionCode = $exceptionCode; - - parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode); - } - - /** - * @param string $exceptionMessageRegExp - * - * @return void - */ - public function setExpectedExceptionRegExp($exceptionName, $exceptionMessageRegExp = '', $exceptionCode = null) - { - $this->forwardCompatExpectedExceptionCode = $exceptionCode; - - parent::setExpectedExceptionRegExp($exceptionName, $exceptionMessageRegExp, $exceptionCode); - } -} diff --git a/Legacy/ForwardCompatTestTraitForV7.php b/Legacy/ForwardCompatTestTraitForV7.php deleted file mode 100644 index f77239ef..00000000 --- a/Legacy/ForwardCompatTestTraitForV7.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * 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\MockObject\MockObject; - -/** - * @internal - */ -trait ForwardCompatTestTraitForV7 -{ - use ForwardCompatTestTraitForV5; - - /** - * @param string|string[] $originalClassName - */ - protected function createMock($originalClassName): MockObject - { - return $this->getMockBuilder($originalClassName) - ->disableOriginalConstructor() - ->disableOriginalClone() - ->disableArgumentCloning() - ->disallowMockingUnknownTypes() - ->getMock(); - } -} diff --git a/Legacy/ForwardCompatTestTraitForV8.php b/Legacy/ForwardCompatTestTraitForV8.php deleted file mode 100644 index 4963ed9e..00000000 --- a/Legacy/ForwardCompatTestTraitForV8.php +++ /dev/null @@ -1,58 +0,0 @@ - - * - * 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 ForwardCompatTestTraitForV8 -{ - public static function setUpBeforeClass(): void - { - self::doSetUpBeforeClass(); - } - - public static function tearDownAfterClass(): void - { - self::doTearDownAfterClass(); - } - - protected function setUp(): void - { - self::doSetUp(); - } - - protected function tearDown(): void - { - self::doTearDown(); - } - - private static function doSetUpBeforeClass(): void - { - parent::setUpBeforeClass(); - } - - private static function doTearDownAfterClass(): void - { - parent::tearDownAfterClass(); - } - - private function doSetUp(): void - { - parent::setUp(); - } - - private function doTearDown(): void - { - parent::tearDown(); - } -} From eee8baa2f638faacdcfe8340395638de2c424c68 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 3 Aug 2019 14:01:57 +0200 Subject: [PATCH 27/49] Allow sutFqcnResolver to return array --- Legacy/CoverageListenerTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Legacy/CoverageListenerTrait.php b/Legacy/CoverageListenerTrait.php index 8e9bdbe9..1f9aabc5 100644 --- a/Legacy/CoverageListenerTrait.php +++ b/Legacy/CoverageListenerTrait.php @@ -76,7 +76,7 @@ public function startTest($test) $cache = $r->getValue(); $cache = array_replace_recursive($cache, array( \get_class($test) => array( - 'covers' => array($sutFqcn), + 'covers' => \is_array($sutFqcn) ? $sutFqcn : array($sutFqcn), ), )); $r->setValue($testClass, $cache); From 43f1d055d6d4d051ea5a9ab8ffa2c8221a7a3b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 2 Aug 2019 19:02:27 +0200 Subject: [PATCH 28/49] Remove use of ForwardCompatTrait --- Tests/ClockMockTest.php | 7 ++----- Tests/DnsMockTest.php | 5 +---- Tests/ProcessIsolationTest.php | 3 --- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Tests/ClockMockTest.php b/Tests/ClockMockTest.php index 75a494db..82cfb6f5 100644 --- a/Tests/ClockMockTest.php +++ b/Tests/ClockMockTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ClockMock; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; /** * @author Dominic Tubach @@ -22,14 +21,12 @@ */ class ClockMockTest extends TestCase { - use ForwardCompatTestTrait; - - private static function doSetUpBeforeClass() + public static function setUpBeforeClass() { ClockMock::register(__CLASS__); } - private function doSetUp() + protected function setUp() { ClockMock::withClockMock(1234567890.125); } diff --git a/Tests/DnsMockTest.php b/Tests/DnsMockTest.php index 4ef2d75b..a178ac7e 100644 --- a/Tests/DnsMockTest.php +++ b/Tests/DnsMockTest.php @@ -13,13 +13,10 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\DnsMock; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; class DnsMockTest extends TestCase { - use ForwardCompatTestTrait; - - private function doTearDown() + protected function tearDown() { DnsMock::withMockedHosts(array()); } diff --git a/Tests/ProcessIsolationTest.php b/Tests/ProcessIsolationTest.php index b75ff1cf..b8125dc5 100644 --- a/Tests/ProcessIsolationTest.php +++ b/Tests/ProcessIsolationTest.php @@ -3,7 +3,6 @@ namespace Symfony\Bridge\PhpUnit\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait; /** * Don't remove this test case, it tests the legacy group. @@ -14,8 +13,6 @@ */ class ProcessIsolationTest extends TestCase { - use ForwardCompatTestTrait; - /** * @expectedDeprecation Test abc */ From 14934c8075809cb6b4c800b2b1ea0919646b8461 Mon Sep 17 00:00:00 2001 From: karser Date: Fri, 2 Aug 2019 22:29:48 +0300 Subject: [PATCH 29/49] [PhpUnitBridge] fixed PHPUnit 8.3 compatibility: method handleError was renamed to __invoke --- DeprecationErrorHandler.php | 40 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index fc60cbd4..8b355c31 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -11,6 +11,9 @@ namespace Symfony\Bridge\PhpUnit; +use PHPUnit\Framework\TestResult; +use PHPUnit\Util\ErrorHandler; + /** * Catch deprecation notices and print a summary report at the end of the test suite. * @@ -23,6 +26,7 @@ class DeprecationErrorHandler const MODE_DISABLED = 'disabled'; private static $isRegistered = false; + private static $isAtLeastPhpUnit83; /** * Registers and configures the deprecation handler. @@ -44,6 +48,7 @@ public static function register($mode = 0) } $UtilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\'; + self::$isAtLeastPhpUnit83 = method_exists('PHPUnit\Util\ErrorHandler', '__invoke'); $getMode = function () use ($mode) { static $memoizedMode = false; @@ -106,9 +111,7 @@ public static function register($mode = 0) ); $deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, $getMode, $UtilPrefix, $inVendors) { if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || DeprecationErrorHandler::MODE_DISABLED === $mode = $getMode()) { - $ErrorHandler = $UtilPrefix.'ErrorHandler'; - - return $ErrorHandler::handleError($type, $msg, $file, $line, $context); + return \call_user_func(DeprecationErrorHandler::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context); } $trace = debug_backtrace(); @@ -183,7 +186,7 @@ public static function register($mode = 0) if (null !== $oldErrorHandler) { restore_error_handler(); - if (array($UtilPrefix.'ErrorHandler', 'handleError') === $oldErrorHandler) { + if ($oldErrorHandler instanceof ErrorHandler || array($UtilPrefix.'ErrorHandler', 'handleError') === $oldErrorHandler) { restore_error_handler(); self::register($mode); } @@ -285,12 +288,8 @@ public static function collectDeprecations($outputFile) if ($previousErrorHandler) { return $previousErrorHandler($type, $msg, $file, $line, $context); } - static $autoload = true; - $ErrorHandler = class_exists('PHPUnit_Util_ErrorHandler', $autoload) ? 'PHPUnit_Util_ErrorHandler' : 'PHPUnit\Util\ErrorHandler'; - $autoload = false; - - return $ErrorHandler::handleError($type, $msg, $file, $line, $context); + return \call_user_func(DeprecationErrorHandler::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context); } $deprecations[] = array(error_reporting(), $msg, $file); }); @@ -300,6 +299,29 @@ public static function collectDeprecations($outputFile) }); } + /** + * @internal + */ + public static function getPhpUnitErrorHandler() + { + if (!self::$isAtLeastPhpUnit83) { + return (class_exists('PHPUnit_Util_ErrorHandler', false) ? 'PHPUnit_Util_' : 'PHPUnit\Util\\').'ErrorHandler::handleError'; + } + + foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) { + if (isset($frame['object']) && $frame['object'] instanceof TestResult) { + return new ErrorHandler( + $frame['object']->getConvertDeprecationsToExceptions(), + $frame['object']->getConvertErrorsToExceptions(), + $frame['object']->getConvertNoticesToExceptions(), + $frame['object']->getConvertWarningsToExceptions() + ); + } + } + + return function () { return false; }; + } + /** * Returns true if STDOUT is defined and supports colorization. * From 1680381947318ca9afc557d596055ad86ba940b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Tue, 6 Aug 2019 00:37:40 +0200 Subject: [PATCH 30/49] Use assertStringContainsString when needed --- Tests/CoverageListenerTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/CoverageListenerTest.php b/Tests/CoverageListenerTest.php index 6674feb9..d69aee70 100644 --- a/Tests/CoverageListenerTest.php +++ b/Tests/CoverageListenerTest.php @@ -33,14 +33,14 @@ public function test() exec("$php $phpunit -c $dir/phpunit-without-listener.xml.dist $dir/tests/ --coverage-text 2> /dev/null", $output); $output = implode("\n", $output); - $this->assertContains('FooCov', $output); + $this->assertStringContainsString('FooCov', $output); exec("$php $phpunit -c $dir/phpunit-with-listener.xml.dist $dir/tests/ --coverage-text 2> /dev/null", $output); $output = implode("\n", $output); - $this->assertNotContains('FooCov', $output); - $this->assertContains("SutNotFoundTest::test\nCould not find the tested class.", $output); - $this->assertNotContains("CoversTest::test\nCould not find the tested class.", $output); - $this->assertNotContains("CoversDefaultClassTest::test\nCould not find the tested class.", $output); - $this->assertNotContains("CoversNothingTest::test\nCould not find the tested class.", $output); + $this->assertStringNotContainsString('FooCov', $output); + $this->assertStringContainsString("SutNotFoundTest::test\nCould not find the tested class.", $output); + $this->assertStringNotContainsString("CoversTest::test\nCould not find the tested class.", $output); + $this->assertStringNotContainsString("CoversDefaultClassTest::test\nCould not find the tested class.", $output); + $this->assertStringNotContainsString("CoversNothingTest::test\nCould not find the tested class.", $output); } } From 1c22660478d4c77e100287b0b4e65e10c9954521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 9 Aug 2019 11:49:26 +0200 Subject: [PATCH 31/49] Fix unitialized variable in DeprecationErrorHandler --- DeprecationErrorHandler.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index 8b355c31..22dbb829 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -48,7 +48,6 @@ public static function register($mode = 0) } $UtilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\'; - self::$isAtLeastPhpUnit83 = method_exists('PHPUnit\Util\ErrorHandler', '__invoke'); $getMode = function () use ($mode) { static $memoizedMode = false; @@ -304,6 +303,9 @@ public static function collectDeprecations($outputFile) */ public static function getPhpUnitErrorHandler() { + if (!isset(self::$isAtLeastPhpUnit83)) { + self::$isAtLeastPhpUnit83 = class_exists(ErrorHandler::class) && method_exists(ErrorHandler::class, '__invoke'); + } if (!self::$isAtLeastPhpUnit83) { return (class_exists('PHPUnit_Util_ErrorHandler', false) ? 'PHPUnit_Util_' : 'PHPUnit\Util\\').'ErrorHandler::handleError'; } From dd2a1ec2793a1453ab14032ef49ff52986bac7ed Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 9 Aug 2019 13:36:44 +0200 Subject: [PATCH 32/49] Fix typo --- bin/simple-phpunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 85a2cde0..54fa1842 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -11,7 +11,7 @@ */ // Please update when phpunit needs to be reinstalled with fresh deps: -// Cache-Id-Version: 2019-07-04 18:00 UTC +// Cache-Id: 2019-08-09 13:00 UTC error_reporting(-1); From d49b6a7984d06913db8a0db054190a773c2f0d98 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 10 Aug 2019 20:54:30 +0200 Subject: [PATCH 33/49] Disable PHPUnit result cache on the CI --- bin/simple-phpunit | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 54fa1842..5209e758 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -133,6 +133,14 @@ EOPHP global $argv, $argc; $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); $argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0; + +if ($PHPUNIT_VERSION < 8.0) { + $argv = array_filter($argv, function ($v) use (&$argc) { if ('--do-not-cache-result' !== $v) return true; --$argc; }); +} elseif (filter_var(getenv('SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE'), FILTER_VALIDATE_BOOLEAN)) { + $argv[] = '--do-not-cache-result'; + ++$argc; +} + $components = array(); $cmd = array_map('escapeshellarg', $argv); $exit = 0; From 028617b04ae19d99d89089626ac969d161244ebc Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 19 Aug 2019 23:30:37 +0200 Subject: [PATCH 34/49] Fix inconsistent return points. --- ClockMock.php | 4 ++++ DeprecationErrorHandler.php | 4 ++++ Legacy/CoverageListenerTrait.php | 6 +----- Legacy/SymfonyTestsListenerTrait.php | 2 ++ bin/simple-phpunit | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ClockMock.php b/ClockMock.php index 4c5432f2..07ce9c3a 100644 --- a/ClockMock.php +++ b/ClockMock.php @@ -25,6 +25,8 @@ public static function withClockMock($enable = null) } self::$now = is_numeric($enable) ? (float) $enable : ($enable ? microtime(true) : null); + + return null; } public static function time() @@ -54,6 +56,8 @@ public static function usleep($us) } self::$now += $us / 1000000; + + return null; } public static function microtime($asFloat = false) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index 22dbb829..39676baf 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -180,6 +180,8 @@ public static function register($mode = 0) ++$ref; } ++$deprecations[$group.'Count']; + + return null; }; $oldErrorHandler = set_error_handler($deprecationHandler); @@ -291,6 +293,8 @@ public static function collectDeprecations($outputFile) return \call_user_func(DeprecationErrorHandler::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context); } $deprecations[] = array(error_reporting(), $msg, $file); + + return null; }); register_shutdown_function(function () use ($outputFile, &$deprecations) { diff --git a/Legacy/CoverageListenerTrait.php b/Legacy/CoverageListenerTrait.php index 1f9aabc5..47486dfb 100644 --- a/Legacy/CoverageListenerTrait.php +++ b/Legacy/CoverageListenerTrait.php @@ -95,11 +95,7 @@ private function findSutFqcn($test) $sutFqcn = str_replace('\\Tests\\', '\\', $class); $sutFqcn = preg_replace('{Test$}', '', $sutFqcn); - if (!class_exists($sutFqcn)) { - return; - } - - return $sutFqcn; + return class_exists($sutFqcn) ? $sutFqcn : null; } public function __destruct() diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 481a860a..4591f67e 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -357,6 +357,8 @@ public function handleError($type, $msg, $file, $line, $context = array()) $msg = 'Unsilenced deprecation: '.$msg; } $this->gatheredDeprecations[] = $msg; + + return null; } /** diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 5209e758..dec8a5e7 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -135,7 +135,7 @@ $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); $argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0; if ($PHPUNIT_VERSION < 8.0) { - $argv = array_filter($argv, function ($v) use (&$argc) { if ('--do-not-cache-result' !== $v) return true; --$argc; }); + $argv = array_filter($argv, function ($v) use (&$argc) { if ('--do-not-cache-result' !== $v) return true; --$argc; return false; }); } elseif (filter_var(getenv('SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE'), FILTER_VALIDATE_BOOLEAN)) { $argv[] = '--do-not-cache-result'; ++$argc; From e13658e119cd3fdb4e5f10def32d8284dc6f44ad Mon Sep 17 00:00:00 2001 From: Kyle Date: Fri, 30 Aug 2019 15:50:48 +0200 Subject: [PATCH 35/49] Fix #33395 PHP 5.3 compatibility --- DeprecationErrorHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index 39676baf..a0271cf3 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -308,7 +308,7 @@ public static function collectDeprecations($outputFile) public static function getPhpUnitErrorHandler() { if (!isset(self::$isAtLeastPhpUnit83)) { - self::$isAtLeastPhpUnit83 = class_exists(ErrorHandler::class) && method_exists(ErrorHandler::class, '__invoke'); + self::$isAtLeastPhpUnit83 = class_exists('PHPUnit\Util\ErrorHandler') && method_exists('PHPUnit\Util\ErrorHandler', '__invoke'); } if (!self::$isAtLeastPhpUnit83) { return (class_exists('PHPUnit_Util_ErrorHandler', false) ? 'PHPUnit_Util_' : 'PHPUnit\Util\\').'ErrorHandler::handleError'; From ca9f40fc51fe9ed743ee10573fc22b27c9d13bb2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Sep 2019 20:32:45 +0200 Subject: [PATCH 36/49] [Bridge/PhpUnit] fix looking for composer --- bin/simple-phpunit | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index dec8a5e7..1b1c4890 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -57,7 +57,9 @@ foreach ($defaultEnvs as $envName => $envValue) { } } -$COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`)) +$COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') + || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`)) + || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer`) : `which composer 2> /dev/null`)) ? $PHP.' '.escapeshellarg($COMPOSER) : 'composer'; From c8dd56cecac1be92e77d65ca29cd1350127edd76 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 28 May 2019 16:21:01 +0100 Subject: [PATCH 37/49] Check phpunit configuration for listeners The bridge listener can be registered via configuration by the user. In that case, we do not want to add it again to the list of listeners. Closes #31649 --- Legacy/CommandForV5.php | 17 ++++++++++++++--- Legacy/CommandForV6.php | 18 +++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Legacy/CommandForV5.php b/Legacy/CommandForV5.php index 95dcb1e5..ed412848 100644 --- a/Legacy/CommandForV5.php +++ b/Legacy/CommandForV5.php @@ -23,8 +23,6 @@ class CommandForV5 extends \PHPUnit_TextUI_Command */ protected function createRunner() { - $listener = new SymfonyTestsListenerForV5(); - $this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : array(); $registeredLocally = false; @@ -37,8 +35,21 @@ protected function createRunner() } } + 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'][] = $listener; + $this->arguments['listeners'][] = new SymfonyTestsListenerForV5(); } return parent::createRunner(); diff --git a/Legacy/CommandForV6.php b/Legacy/CommandForV6.php index f8f75bb0..93e1ad97 100644 --- a/Legacy/CommandForV6.php +++ b/Legacy/CommandForV6.php @@ -13,6 +13,7 @@ use PHPUnit\TextUI\Command as BaseCommand; use PHPUnit\TextUI\TestRunner as BaseRunner; +use PHPUnit\Util\Configuration; use Symfony\Bridge\PhpUnit\SymfonyTestsListener; /** @@ -27,8 +28,6 @@ class CommandForV6 extends BaseCommand */ protected function createRunner(): BaseRunner { - $listener = new SymfonyTestsListener(); - $this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : []; $registeredLocally = false; @@ -41,8 +40,21 @@ protected function createRunner(): BaseRunner } } + if (isset($this->arguments['configuration'])) { + $configuration = $this->arguments['configuration']; + if (!$configuration instanceof Configuration) { + $configuration = 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'][] = $listener; + $this->arguments['listeners'][] = new SymfonyTestsListener(); } return parent::createRunner(); From 1f0970c4437122bf7acd451e0da74f29353cc3c2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 13 Sep 2019 11:27:15 +0200 Subject: [PATCH 38/49] Re-enable previously failing PHP 7.4 test cases --- DeprecationErrorHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index a0271cf3..7cccd8eb 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -109,7 +109,7 @@ public static function register($mode = 0) 'remaining vendor' => array(), ); $deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, $getMode, $UtilPrefix, $inVendors) { - if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || DeprecationErrorHandler::MODE_DISABLED === $mode = $getMode()) { + if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type && (E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) || DeprecationErrorHandler::MODE_DISABLED === $mode = $getMode()) { return \call_user_func(DeprecationErrorHandler::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context); } @@ -285,7 +285,7 @@ public static function collectDeprecations($outputFile) { $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 (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type && (E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) { if ($previousErrorHandler) { return $previousErrorHandler($type, $msg, $file, $line, $context); } From 5a24966441e561e97790488854b17a25fddc0362 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 19 Sep 2019 18:13:23 +0200 Subject: [PATCH 39/49] [PhpUnitBridge] bump cache id --- bin/simple-phpunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 1b1c4890..02fd4de4 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -11,7 +11,7 @@ */ // Please update when phpunit needs to be reinstalled with fresh deps: -// Cache-Id: 2019-08-09 13:00 UTC +// Cache-Id: 2019-09-19 17:00 UTC error_reporting(-1); From f5e48bbfda3ab465ae802a7710ec21ef4aaeda25 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 23 Sep 2019 21:21:37 +0200 Subject: [PATCH 40/49] [PhpUnit] Fix usleep mock return value --- ClockMock.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ClockMock.php b/ClockMock.php index 07ce9c3a..bfc7566a 100644 --- a/ClockMock.php +++ b/ClockMock.php @@ -52,12 +52,10 @@ public static function sleep($s) public static function usleep($us) { if (null === self::$now) { - return \usleep($us); + \usleep($us); + } else { + self::$now += $us / 1000000; } - - self::$now += $us / 1000000; - - return null; } public static function microtime($asFloat = false) @@ -108,7 +106,7 @@ function sleep(\$s) function usleep(\$us) { - return \\$self::usleep(\$us); + \\$self::usleep(\$us); } EOPHP From cbea8818e9f34e4e9d780bd22bdda21b57d4d5c7 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Mon, 30 Sep 2019 22:33:19 +0200 Subject: [PATCH 41/49] Copy phpunit.xsd to a predictable path --- bin/simple-phpunit | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 02fd4de4..262fdd9d 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -78,6 +78,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old")); } passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\""); + @copy("phpunit-$PHPUNIT_VERSION/phpunit.xsd", 'phpunit.xsd'); chdir("phpunit-$PHPUNIT_VERSION"); if ($SYMFONY_PHPUNIT_REMOVE) { passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE); From 3d308cdd3060b4f7e62df61788c45d6019f1f88b Mon Sep 17 00:00:00 2001 From: Jan Rosier Date: Wed, 1 Jan 2020 12:03:25 +0100 Subject: [PATCH 42/49] Update year in license files --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index cf8b3ebe..684fbf94 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014-2019 Fabien Potencier +Copyright (c) 2014-2020 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From e1abdf2abdee6ba95a3334dbd63929c4f5dc0867 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Fri, 3 Jan 2020 12:08:23 +0100 Subject: [PATCH 43/49] [PhpUnitBridge] Add test case for @expectedDeprecation annotation --- Tests/ExpectedDeprecationAnnotationTest.php | 43 +++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Tests/ExpectedDeprecationAnnotationTest.php diff --git a/Tests/ExpectedDeprecationAnnotationTest.php b/Tests/ExpectedDeprecationAnnotationTest.php new file mode 100644 index 00000000..259c9916 --- /dev/null +++ b/Tests/ExpectedDeprecationAnnotationTest.php @@ -0,0 +1,43 @@ + + * + * 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; + +final class ExpectedDeprecationAnnotationTest extends TestCase +{ + /** + * Do not remove this test in the next major versions. + * + * @group legacy + * + * @expectedDeprecation foo + */ + public function testOne() + { + @trigger_error('foo', E_USER_DEPRECATED); + } + + /** + * Do not remove this test in the next major versions. + * + * @group legacy + * + * @expectedDeprecation foo + * @expectedDeprecation bar + */ + public function testMany() + { + @trigger_error('foo', E_USER_DEPRECATED); + @trigger_error('bar', E_USER_DEPRECATED); + } +} From eb1ea840f1b16e89ebddd910c6f666dd3e8cc251 Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Tue, 7 Jan 2020 00:31:32 +0200 Subject: [PATCH 44/49] [PhpUnitBridge] When using phpenv + phpenv-composer plugin, composer executable is wrapped into a bash script --- bin/simple-phpunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 262fdd9d..da99873a 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -60,7 +60,7 @@ foreach ($defaultEnvs as $envName => $envValue) { $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`)) || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer`) : `which composer 2> /dev/null`)) - ? $PHP.' '.escapeshellarg($COMPOSER) + ? (file_get_contents($COMPOSER, null, 0, 18) === '#!/usr/bin/env php' ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang : 'composer'; if (false === $SYMFONY_PHPUNIT_REMOVE = getenv('SYMFONY_PHPUNIT_REMOVE')) { From 2315f6b72c0842a0e73f6b7a214c1ef12f195872 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Wed, 8 Jan 2020 14:37:17 +0100 Subject: [PATCH 45/49] [PHPUnit-Bridge] Fail-fast in simple-phpunit if one of the passthru() commands fails --- bin/simple-phpunit | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index da99873a..2bdd705e 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -15,6 +15,14 @@ error_reporting(-1); +$passthruOrFail = function ($command) { + passthru($command, $status); + + if ($status) { + exit($status); + } +}; + if (PHP_VERSION_ID >= 70200) { // PHPUnit 6 is required for PHP 7.2+ $PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '6.5'; @@ -77,25 +85,25 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ rename("phpunit-$PHPUNIT_VERSION", "phpunit-$PHPUNIT_VERSION.old"); passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old")); } - passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\""); + $passthruOrFail("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\""); @copy("phpunit-$PHPUNIT_VERSION/phpunit.xsd", 'phpunit.xsd'); chdir("phpunit-$PHPUNIT_VERSION"); if ($SYMFONY_PHPUNIT_REMOVE) { - passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE); + $passthruOrFail("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE); } if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { - passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); + $passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); } - passthru("$COMPOSER config --unset platform"); + $passthruOrFail("$COMPOSER config --unset platform"); if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) { - passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\""); - passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path))); + $passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\""); + $passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path))); if ('\\' === DIRECTORY_SEPARATOR) { file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json'))); } } else { - passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\""); + $passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*\""); } $prevRoot = getenv('COMPOSER_ROOT_VERSION'); putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99"); From 86436e216b0aecf2286202dfb4201e49db9da812 Mon Sep 17 00:00:00 2001 From: Pablo Lozano Date: Thu, 9 Jan 2020 09:55:05 +0100 Subject: [PATCH 46/49] [PHPUnitBridge] file_get_contents() expects parameter 3 to be resource --- bin/simple-phpunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index da99873a..0366b07c 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -60,7 +60,7 @@ foreach ($defaultEnvs as $envName => $envValue) { $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`)) || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer`) : `which composer 2> /dev/null`)) - ? (file_get_contents($COMPOSER, null, 0, 18) === '#!/usr/bin/env php' ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang + ? (file_get_contents($COMPOSER, false, null, 0, 18) === '#!/usr/bin/env php' ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang : 'composer'; if (false === $SYMFONY_PHPUNIT_REMOVE = getenv('SYMFONY_PHPUNIT_REMOVE')) { From 4ec4a2399d0a3e2d7e1498053adf0892efb6461d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 9 Jan 2020 13:44:20 +0100 Subject: [PATCH 47/49] fix tests --- bin/simple-phpunit | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index 3fb5d4bf..f726a7cf 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -95,7 +95,9 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ $passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); } - $passthruOrFail("$COMPOSER config --unset platform"); + if (PHP_VERSION_ID >= 70000) { + $passthruOrFail("$COMPOSER config --unset platform"); + } if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) { $passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\""); $passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path))); From 5ef67a3f7a26eb24b9796b5cdfd3df50c3ef7efb Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 9 Jan 2020 14:36:09 +0100 Subject: [PATCH 48/49] [PhpUnitBridge] fix compat with older versions of composer --- bin/simple-phpunit | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/simple-phpunit b/bin/simple-phpunit index f726a7cf..11a40d55 100755 --- a/bin/simple-phpunit +++ b/bin/simple-phpunit @@ -95,9 +95,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ $passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); } - if (PHP_VERSION_ID >= 70000) { - $passthruOrFail("$COMPOSER config --unset platform"); - } + $passthruOrFail("$COMPOSER config --unset platform.php"); if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) { $passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\""); $passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path))); From ebfd1b428ffc14306e843092763f228bfba168d0 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Thu, 2 Jan 2020 19:17:31 +0100 Subject: [PATCH 49/49] [PhpUnitBridge][SymfonyTestsListenerTrait] Remove some unneeded code --- Legacy/SymfonyTestsListenerTrait.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Legacy/SymfonyTestsListenerTrait.php b/Legacy/SymfonyTestsListenerTrait.php index 4591f67e..54c15b67 100644 --- a/Legacy/SymfonyTestsListenerTrait.php +++ b/Legacy/SymfonyTestsListenerTrait.php @@ -37,7 +37,6 @@ class SymfonyTestsListenerTrait private $gatheredDeprecations = array(); private $previousErrorHandler; private $testsWithWarnings; - private $reportUselessTests; private $error; private $runsInSeparateProcess = false; @@ -198,10 +197,6 @@ public function addSkippedTest($test, \Exception $e, $time) public function startTest($test) { if (-2 < $this->state && ($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) { - if (null !== $test->getTestResultObject()) { - $this->reportUselessTests = $test->getTestResultObject()->isStrictAboutTestsThatDoNotTestAnything(); - } - // This event is triggered before the test is re-run in isolation if ($this->willBeIsolated($test)) { $this->runsInSeparateProcess = tempnam(sys_get_temp_dir(), 'deprec'); @@ -267,11 +262,6 @@ public function endTest($test, $time) $classGroups = $Test::getGroups($className); $groups = $Test::getGroups($className, $test->getName(false)); - if (null !== $this->reportUselessTests) { - $test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything($this->reportUselessTests); - $this->reportUselessTests = null; - } - if ($errored = null !== $this->error) { $test->getTestResultObject()->addError($test, $this->error, 0); $this->error = null;