From 6482956d963a91a8644777188b7a3ab519bae2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Tue, 11 Aug 2020 09:41:04 -0700 Subject: [PATCH] patch tests Taken from: https://github.com/yiisoft/yii/pull/4306 by @samdark --- composer.json | 17 +++++++-- tests/phpunit_mock_objects.patch | 38 ++++++++++++++++++++ tests/phpunit_php7.patch | 60 ++++++++++++++++++++++++++++++++ tests/phpunit_php8.patch | 39 +++++++++++++++++++++ 4 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit_mock_objects.patch create mode 100644 tests/phpunit_php7.patch create mode 100644 tests/phpunit_php8.patch diff --git a/composer.json b/composer.json index bde6c741..48c05e56 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ } ], "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "cweagans/composer-patches": "^1.6" }, "require-dev": { "phpunit/phpunit": "~4.8" @@ -27,5 +28,17 @@ }, "autoload": { "psr-4": {"Predis\\": "src/"} - } + }, + "extra": { + "composer-exit-on-patch-failure": true, + "patches": { + "phpunit/phpunit-mock-objects": { + "Fix PHP 7 and 8 compatibility": "./tests/phpunit_mock_objects.patch" + }, + "phpunit/phpunit": { + "Fix PHP 7 compatibility": "./tests/phpunit_php7.patch", + "Fix PHP 8 compatibility": "./tests/phpunit_php8.patch" + } + } + } } diff --git a/tests/phpunit_mock_objects.patch b/tests/phpunit_mock_objects.patch new file mode 100644 index 00000000..b3dd0f29 --- /dev/null +++ b/tests/phpunit_mock_objects.patch @@ -0,0 +1,38 @@ +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 new file mode 100644 index 00000000..e3f13ffb --- /dev/null +++ b/tests/phpunit_php7.patch @@ -0,0 +1,60 @@ +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 new file mode 100644 index 00000000..ded4d3fc --- /dev/null +++ b/tests/phpunit_php8.patch @@ -0,0 +1,39 @@ +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; + }