From 7d25dc72a98f6c6b2d72e6e5f2cbe77bb3b6b0c9 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 30 Oct 2020 22:21:20 +0300 Subject: [PATCH] Apply PHPUnit patches from URL (#18356) --- composer.json | 8 ++--- tests/phpunit_mock_objects.patch | 38 -------------------- tests/phpunit_php7.patch | 60 -------------------------------- tests/phpunit_php8.patch | 39 --------------------- 4 files changed, 4 insertions(+), 141 deletions(-) delete mode 100644 tests/phpunit_mock_objects.patch delete mode 100644 tests/phpunit_php7.patch delete mode 100644 tests/phpunit_php8.patch diff --git a/composer.json b/composer.json index b2ffcd1241..ced9703ef4 100644 --- a/composer.json +++ b/composer.json @@ -81,7 +81,7 @@ "bower-asset/yii2-pjax": "~2.0.1" }, "require-dev": { - "cweagans/composer-patches": "^1.6", + "cweagans/composer-patches": "^1.7", "phpunit/phpunit": "4.8.34", "cebe/indent": "~1.0.2", "friendsofphp/php-cs-fixer": "~2.2.3", @@ -115,11 +115,11 @@ "composer-exit-on-patch-failure": true, "patches": { "phpunit/phpunit-mock-objects": { - "Fix PHP 7 and 8 compatibility": "./tests/phpunit_mock_objects.patch" + "Fix PHP 7 and 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_mock_objects.patch" }, "phpunit/phpunit": { - "Fix PHP 7 compatibility": "./tests/phpunit_php7.patch", - "Fix PHP 8 compatibility": "./tests/phpunit_php8.patch" + "Fix PHP 7 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php7.patch", + "Fix PHP 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php8.patch" } } } diff --git a/tests/phpunit_mock_objects.patch b/tests/phpunit_mock_objects.patch deleted file mode 100644 index b3dd0f29c7..0000000000 --- a/tests/phpunit_mock_objects.patch +++ /dev/null @@ -1,38 +0,0 @@ -diff --git a/src/Framework/MockObject/Generator.php b/src/Framework/MockObject/Generator.php -index 3df3abb..fc76d5d 100644 ---- a/src/Framework/MockObject/Generator.php -+++ b/src/Framework/MockObject/Generator.php -@@ -1031,16 +1031,29 @@ protected function getMethodParameters(ReflectionMethod $method, $forCall = fals - $typeDeclaration = ''; - - if (!$forCall) { -+ if (PHP_VERSION_ID >= 80000) { -+ $isArray = $parameter->getType() && $parameter->getType()->getName() === 'array'; -+ $isCallable = $parameter->getType() && $parameter->getType()->getName() === 'callable'; -+ } else { -+ $isArray = $parameter->isArray(); -+ $isCallable = version_compare(PHP_VERSION, '5.4.0', '>=') ? $parameter->isCallable() : false; -+ } -+ - if ($this->hasType($parameter)) { -- $typeDeclaration = (string) $parameter->getType() . ' '; -- } elseif ($parameter->isArray()) { -+ $type = $parameter->getType(); -+ $typeDeclaration = (PHP_VERSION_ID >= 70100 ? $type->getName() : (string) $type) . ' '; -+ } elseif ($isArray) { - $typeDeclaration = 'array '; - } elseif ((defined('HHVM_VERSION') || version_compare(PHP_VERSION, '5.4.0', '>=')) -- && $parameter->isCallable()) { -+ && $isCallable) { - $typeDeclaration = 'callable '; - } else { - try { -- $class = $parameter->getClass(); -+ if (PHP_VERSION_ID >= 80000) { -+ $class = $parameter->getType(); -+ } else { -+ $class = $parameter->getClass(); -+ } - } catch (ReflectionException $e) { - throw new PHPUnit_Framework_MockObject_RuntimeException( - sprintf( diff --git a/tests/phpunit_php7.patch b/tests/phpunit_php7.patch deleted file mode 100644 index e3f13ffb5a..0000000000 --- a/tests/phpunit_php7.patch +++ /dev/null @@ -1,60 +0,0 @@ -diff --git a/src/Util/Getopt.php b/src/Util/Getopt.php -index ba21be3..96931a3 100644 ---- a/src/Util/Getopt.php -+++ b/src/Util/Getopt.php -@@ -35,7 +35,15 @@ class PHPUnit_Util_Getopt - reset($args); - array_map('trim', $args); - -- while (list($i, $arg) = each($args)) { -+ while (true) { -+ $arg = current($args); -+ $i = key($args); -+ next($args); -+ -+ if ($arg === false) { -+ break; -+ } -+ - if ($arg == '') { - continue; - } -@@ -94,11 +102,14 @@ class PHPUnit_Util_Getopt - if ($i + 1 < $argLen) { - $opts[] = array($opt, substr($arg, $i + 1)); - break; -- } elseif (list(, $opt_arg) = each($args)) { - } else { -- throw new PHPUnit_Framework_Exception( -- "option requires an argument -- $opt" -- ); -+ $opt_arg = current($args); -+ next($args); -+ if ($opt_arg === false) { -+ throw new PHPUnit_Framework_Exception( -+ "option requires an argument -- $opt" -+ ); -+ } - } - } - } -@@ -139,11 +150,14 @@ class PHPUnit_Util_Getopt - - if (substr($long_opt, -1) == '=') { - if (substr($long_opt, -2) != '==') { -- if (!strlen($opt_arg) && -- !(list(, $opt_arg) = each($args))) { -- throw new PHPUnit_Framework_Exception( -- "option --$opt requires an argument" -- ); -+ if (!strlen($opt_arg)) { -+ $opt_arg = current($args); -+ next($args); -+ if ($opt_arg === false) { -+ throw new PHPUnit_Framework_Exception( -+ "option --$opt requires an argument" -+ ); -+ } - } - } - } elseif ($opt_arg) { diff --git a/tests/phpunit_php8.patch b/tests/phpunit_php8.patch deleted file mode 100644 index ded4d3fc34..0000000000 --- a/tests/phpunit_php8.patch +++ /dev/null @@ -1,39 +0,0 @@ -diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php -index 638f42513..b4c7d3a5e 100644 ---- a/src/Framework/TestCase.php -+++ b/src/Framework/TestCase.php -@@ -905,7 +905,7 @@ protected function runTest() - try { - $testResult = $method->invokeArgs( - $this, -- array_merge($this->data, $this->dependencyInput) -+ array_values(array_merge($this->data, $this->dependencyInput)) - ); - } catch (Throwable $_e) { - $e = $_e; -diff --git a/src/Util/Configuration.php b/src/Util/Configuration.php -index 5c1041608..b2f7a7bd0 100644 ---- a/src/Util/Configuration.php -+++ b/src/Util/Configuration.php -@@ -162,7 +162,7 @@ protected function __construct($filename) - /** - * @since Method available since Release 3.4.0 - */ -- final private function __clone() -+ private function __clone() - { - } - -diff --git a/src/Util/PHP/Template/TestCaseMethod.tpl.dist b/src/Util/PHP/Template/TestCaseMethod.tpl.dist -index b48f354cd..d59cdeea7 100644 ---- a/src/Util/PHP/Template/TestCaseMethod.tpl.dist -+++ b/src/Util/PHP/Template/TestCaseMethod.tpl.dist -@@ -78,7 +78,7 @@ if ('' !== $configurationFilePath) { - unset($configuration); - } - --function __phpunit_error_handler($errno, $errstr, $errfile, $errline, $errcontext) -+function __phpunit_error_handler($errno, $errstr, $errfile, $errline, $errcontext = null) - { - return true; - }