diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b174a541811..500e3ee466d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,6 +28,7 @@ jobs: - "8.3" - "8.4" - "8.5" + - "8.6" php_invoker: [true, false] coverage: [false] experimental: [false] diff --git a/PHPUnit/Autoload.php b/PHPUnit/Autoload.php index f3b9d051671..f8503c64820 100644 --- a/PHPUnit/Autoload.php +++ b/PHPUnit/Autoload.php @@ -178,6 +178,7 @@ function ($class) 'phpunit_util_getopt' => '/Util/Getopt.php', 'phpunit_util_globalstate' => '/Util/GlobalState.php', 'phpunit_util_invalidargumenthelper' => '/Util/InvalidArgumentHelper.php', + 'phpunit_util_invoker' => '/Util/Invoker.php', 'phpunit_util_log_json' => '/Util/Log/JSON.php', 'phpunit_util_log_junit' => '/Util/Log/JUnit.php', 'phpunit_util_log_tap' => '/Util/Log/TAP.php', diff --git a/PHPUnit/Extensions/RepeatedTest.php b/PHPUnit/Extensions/RepeatedTest.php index 06d35c94c91..3bfcf13ee67 100644 --- a/PHPUnit/Extensions/RepeatedTest.php +++ b/PHPUnit/Extensions/RepeatedTest.php @@ -94,7 +94,7 @@ public function __construct(PHPUnit_Framework_Test $test, $timesRepeat = 1, $fil { parent::__construct($test); - if (is_integer($timesRepeat) && + if (is_int($timesRepeat) && $timesRepeat >= 0) { $this->timesRepeat = $timesRepeat; } else { diff --git a/PHPUnit/Framework/Assert.php b/PHPUnit/Framework/Assert.php index b10af95ea1f..d60ee458c50 100644 --- a/PHPUnit/Framework/Assert.php +++ b/PHPUnit/Framework/Assert.php @@ -71,7 +71,7 @@ abstract class PHPUnit_Framework_Assert */ public static function assertArrayHasKey($key, $array, $message = '') { - if (!(is_integer($key) || is_string($key))) { + if (!(is_int($key) || is_string($key))) { throw PHPUnit_Util_InvalidArgumentHelper::factory( 1, 'integer or string' ); @@ -97,7 +97,7 @@ public static function assertArrayHasKey($key, $array, $message = '') */ public static function assertArrayNotHasKey($key, $array, $message = '') { - if (!(is_integer($key) || is_string($key))) { + if (!(is_int($key) || is_string($key))) { throw PHPUnit_Util_InvalidArgumentHelper::factory( 1, 'integer or string' ); diff --git a/PHPUnit/Framework/Comparator/Double.php b/PHPUnit/Framework/Comparator/Double.php index 91e8146fe30..27202a7f52c 100644 --- a/PHPUnit/Framework/Comparator/Double.php +++ b/PHPUnit/Framework/Comparator/Double.php @@ -72,7 +72,7 @@ class PHPUnit_Framework_Comparator_Double extends PHPUnit_Framework_Comparator_N */ public function accepts($expected, $actual) { - return (is_double($expected) || is_double($actual)) && is_numeric($expected) && is_numeric($actual); + return (is_float($expected) || is_float($actual)) && is_numeric($expected) && is_numeric($actual); } /** diff --git a/PHPUnit/Framework/Comparator/Numeric.php b/PHPUnit/Framework/Comparator/Numeric.php index 4e922ec07be..dd3fb018e1e 100644 --- a/PHPUnit/Framework/Comparator/Numeric.php +++ b/PHPUnit/Framework/Comparator/Numeric.php @@ -67,7 +67,7 @@ class PHPUnit_Framework_Comparator_Numeric extends PHPUnit_Framework_Comparator_ public function accepts($expected, $actual) { // all numerical values, but not if one of them is a double - return is_numeric($expected) && is_numeric($actual) && !(is_double($expected) || is_double($actual)); + return is_numeric($expected) && is_numeric($actual) && !(is_float($expected) || is_float($actual)); } /** diff --git a/PHPUnit/Framework/Constraint/IsIdentical.php b/PHPUnit/Framework/Constraint/IsIdentical.php index 0cc12235542..5dc836ee067 100644 --- a/PHPUnit/Framework/Constraint/IsIdentical.php +++ b/PHPUnit/Framework/Constraint/IsIdentical.php @@ -102,7 +102,7 @@ public function __construct($value) */ public function evaluate($other, $description = '', $returnResult = FALSE) { - if (is_double($this->value) && is_double($other) && + if (is_float($this->value) && is_float($other) && !is_infinite($this->value) && !is_infinite($other) && !is_nan($this->value) && !is_nan($other)) { $success = abs($this->value - $other) < self::EPSILON; diff --git a/PHPUnit/Framework/Constraint/IsType.php b/PHPUnit/Framework/Constraint/IsType.php index 658811a6683..0a53505fe8b 100644 --- a/PHPUnit/Framework/Constraint/IsType.php +++ b/PHPUnit/Framework/Constraint/IsType.php @@ -132,7 +132,7 @@ protected function matches($other) case 'integer': case 'int': { - return is_integer($other); + return is_int($other); } case 'float': { diff --git a/PHPUnit/Framework/TestResult.php b/PHPUnit/Framework/TestResult.php index 35602c7ba8e..88f106d6d58 100644 --- a/PHPUnit/Framework/TestResult.php +++ b/PHPUnit/Framework/TestResult.php @@ -646,7 +646,7 @@ public function run(PHPUnit_Framework_Test $test) break; } - $invoker = new PHP_Invoker; + $invoker = new PHPUnit_Util_Invoker; $invoker->invoke(array($test, 'runBare'), array(), $_timeout); } else { $test->runBare(); @@ -920,7 +920,7 @@ public function wasSuccessful() */ public function setTimeoutForSmallTests($timeout) { - if (is_integer($timeout)) { + if (is_int($timeout)) { $this->timeoutForSmallTests = $timeout; } else { throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer'); @@ -936,7 +936,7 @@ public function setTimeoutForSmallTests($timeout) */ public function setTimeoutForMediumTests($timeout) { - if (is_integer($timeout)) { + if (is_int($timeout)) { $this->timeoutForMediumTests = $timeout; } else { throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer'); @@ -952,7 +952,7 @@ public function setTimeoutForMediumTests($timeout) */ public function setTimeoutForLargeTests($timeout) { - if (is_integer($timeout)) { + if (is_int($timeout)) { $this->timeoutForLargeTests = $timeout; } else { throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer'); diff --git a/PHPUnit/TextUI/TestRunner.php b/PHPUnit/TextUI/TestRunner.php index 22f8beb20de..93348ddf365 100644 --- a/PHPUnit/TextUI/TestRunner.php +++ b/PHPUnit/TextUI/TestRunner.php @@ -157,7 +157,7 @@ public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) $suite->setBackupStaticAttributes(TRUE); } - if (is_integer($arguments['repeat'])) { + if (is_int($arguments['repeat'])) { $test = new PHPUnit_Extensions_RepeatedTest( $suite, $arguments['repeat'], diff --git a/PHPUnit/Util/Invoker.php b/PHPUnit/Util/Invoker.php new file mode 100644 index 00000000000..2154b11a55c --- /dev/null +++ b/PHPUnit/Util/Invoker.php @@ -0,0 +1,106 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @package PHPUnit + * @subpackage Util + * @author Sebastian Bergmann + * @copyright 2001-2014 Sebastian Bergmann + * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License + * @link http://www.phpunit.de/ + * @since File available since Release 3.7.45 + */ + +declare(ticks = 1); + +// php-invoker is optional, so the class is only declared when it is installed - including this file +// without it (e.g. code coverage with processUncoveredFilesFromWhitelist) must not fail +if (class_exists('PHP_Invoker')) { + /** + * PHP_Invoker from the optional php-invoker 1.1 package, with invoke() using is_int() + * instead of is_integer(), which is deprecated since PHP 8.6. php-invoker 1.1 is no longer maintained. + * + * Only instantiated after class_exists('PHP_Invoker'), so php-invoker stays optional. + * + * @package PHPUnit + * @subpackage Util + * @author Sebastian Bergmann + * @copyright 2001-2014 Sebastian Bergmann + * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License + * @link http://www.phpunit.de/ + * @since Class available since Release 3.7.45 + */ + class PHPUnit_Util_Invoker extends PHP_Invoker + { + /** + * Invokes a callable and raises an exception when the execution does not + * finish before the specified timeout. + * + * @param callable $callable + * @param array $arguments + * @param int $timeout in seconds + * @return mixed + * @throws InvalidArgumentException + */ + public function invoke($callable, array $arguments, $timeout) + { + if (!is_callable($callable)) { + throw new InvalidArgumentException; + } + + if (!is_int($timeout)) { + throw new InvalidArgumentException; + } + + pcntl_signal(SIGALRM, array($this, 'callback'), TRUE); + pcntl_alarm($timeout); + + $this->timeout = $timeout; + + try { + $result = call_user_func_array($callable, $arguments); + } + + catch (Exception $e) { + pcntl_alarm(0); + throw $e; + } + + pcntl_alarm(0); + + return $result; + } + } +} diff --git a/PHPUnit/Util/Type.php b/PHPUnit/Util/Type.php index cd63fad7a61..bd6f62342d0 100644 --- a/PHPUnit/Util/Type.php +++ b/PHPUnit/Util/Type.php @@ -283,7 +283,11 @@ public static function toArray($object) // Format the output similarly to print_r() in this case if ($object instanceof SplObjectStorage) { foreach ($object as $key => $value) { - $array[spl_object_hash($value)] = array( + // same value as spl_object_hash(), which is deprecated since PHP 8.6 + $hash = PHP_VERSION_ID >= 80600 + ? sprintf('%016x%016x', spl_object_id($value), 0) + : spl_object_hash($value); + $array[$hash] = array( 'obj' => $value, 'inf' => $object->getInfo(), ); diff --git a/PHPUnit/Util/Type/ExportContext.php b/PHPUnit/Util/Type/ExportContext.php index 3e0b4cfa535..cfe0033032e 100644 --- a/PHPUnit/Util/Type/ExportContext.php +++ b/PHPUnit/Util/Type/ExportContext.php @@ -145,7 +145,10 @@ protected function addObject($value) $this->objects->offsetSet($value, null); } - return spl_object_hash($value); + // same value as spl_object_hash(), which is deprecated since PHP 8.6 + return PHP_VERSION_ID >= 80600 + ? sprintf('%016x%016x', spl_object_id($value), 0) + : spl_object_hash($value); } /** @@ -181,7 +184,10 @@ protected function containsArray(array &$value) protected function containsObject($value) { if ($this->objects->offsetExists($value)) { - return spl_object_hash($value); + // same value as spl_object_hash(), which is deprecated since PHP 8.6 + return PHP_VERSION_ID >= 80600 + ? sprintf('%016x%016x', spl_object_id($value), 0) + : spl_object_hash($value); } return false; diff --git a/README.md b/README.md index 108f9b03d1e..381ec270fe1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# PHPUnit 3.7.x php 5.3-8.5 compatible +# PHPUnit 3.7.x php 5.3-8.6 compatible -This version of PHPUnit bases on release 3.7.38 and is adjusted for compatibility with PHP 5.3-8.5. +This version of PHPUnit bases on release 3.7.38 and is adjusted for compatibility with PHP 5.3-8.6. The package was created especially for testing https://github.com/zf1s packages. All credits go to original PHPUnit author and contributors. diff --git a/Tests/Framework/ConstraintTest.php b/Tests/Framework/ConstraintTest.php index 46de9a26bbf..ffa984f19d5 100644 --- a/Tests/Framework/ConstraintTest.php +++ b/Tests/Framework/ConstraintTest.php @@ -712,8 +712,9 @@ public function isEqualProvider() $a = new stdClass; $a->foo = 'bar'; $b = new stdClass; - $ahash = spl_object_hash($a); - $bhash = spl_object_hash($b); + // same values as spl_object_hash(), which is deprecated since PHP 8.6 + $ahash = PHP_VERSION_ID >= 80600 ? sprintf('%016x%016x', spl_object_id($a), 0) : spl_object_hash($a); + $bhash = PHP_VERSION_ID >= 80600 ? sprintf('%016x%016x', spl_object_id($b), 0) : spl_object_hash($b); $c = new stdClass; $c->foo = 'bar'; @@ -737,8 +738,13 @@ public function isEqualProvider() $storage1->offsetSet($b); $storage2 = new SplObjectStorage; $storage2->offsetSet($b); - $storage1hash = spl_object_hash($storage1); - $storage2hash = spl_object_hash($storage2); + // same values as spl_object_hash(), which is deprecated since PHP 8.6 + $storage1hash = PHP_VERSION_ID >= 80600 + ? sprintf('%016x%016x', spl_object_id($storage1), 0) + : spl_object_hash($storage1); + $storage2hash = PHP_VERSION_ID >= 80600 + ? sprintf('%016x%016x', spl_object_id($storage2), 0) + : spl_object_hash($storage2); $dom1 = new DOMDocument; $dom1->preserveWhiteSpace = FALSE; diff --git a/deps/phpunit-mock-objects/PHPUnit/Framework/MockObject/Generator.php b/deps/phpunit-mock-objects/PHPUnit/Framework/MockObject/Generator.php index a3a0bf82987..b0c2bda49cd 100644 --- a/deps/phpunit-mock-objects/PHPUnit/Framework/MockObject/Generator.php +++ b/deps/phpunit-mock-objects/PHPUnit/Framework/MockObject/Generator.php @@ -789,7 +789,9 @@ protected static function generateMockedMethodDefinition($templateDir, $classNam 'method_name' => $methodName, 'modifier' => $modifier, 'reference' => $reference, - 'clone_arguments' => $cloneArguments ? 'TRUE' : 'FALSE' + 'clone_arguments' => $cloneArguments ? 'TRUE' : 'FALSE', + // returning a value from a destructor is deprecated since PHP 8.6 + 'return_result' => strtolower($methodName) == '__destruct' ? '' : 'return $result;' ) ); diff --git a/deps/phpunit-mock-objects/PHPUnit/Framework/MockObject/Generator/mocked_object_method.tpl.dist b/deps/phpunit-mock-objects/PHPUnit/Framework/MockObject/Generator/mocked_object_method.tpl.dist index adb7f4bc774..293a8ef0cce 100644 --- a/deps/phpunit-mock-objects/PHPUnit/Framework/MockObject/Generator/mocked_object_method.tpl.dist +++ b/deps/phpunit-mock-objects/PHPUnit/Framework/MockObject/Generator/mocked_object_method.tpl.dist @@ -19,5 +19,5 @@ ) ); - return $result; + {return_result} }