From 716ebe0e6089db35276c4576596791f01accadc8 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 17:05:43 +0200 Subject: [PATCH 1/8] Run CI on 5.6-8.4. --- .github/workflows/ci.yml | 2 +- bin/update-tests | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c312bc..3784ff0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] name: PHP ${{ matrix.php-version }} on ${{ matrix.os }} steps: diff --git a/bin/update-tests b/bin/update-tests index d1f7145..5a4ce79 100644 --- a/bin/update-tests +++ b/bin/update-tests @@ -2,7 +2,7 @@ # This file updates tests according to the phpunit library used for current php version, or php version in 1st argument. # Usage: # update-tests - to update tests according to the phpunit library used for current php version. -# update-tests x.x - to update tests according to the phpunit library used for specific php version x.x, where x.x = 5.6|7.0|7.1|7.2|7.3|7.4|8.0. +# update-tests x.x - to update tests according to the phpunit library used for specific php version x.x, where x.x = 5.6|7.0|7.1|7.2|7.3|7.4|8.0|8.1|8.2|8.3|8.4. # Directory with phpunit tests. TEST_DIR="tests" @@ -14,7 +14,7 @@ else fi if [[ $1 == '' && $DEV_MODE != '1' ]]; then - echo "Script works with composer in dev mode only." +# Script works with composer in dev mode only. exit 0 fi @@ -52,7 +52,7 @@ elif [[ $PHP_VERSION == '7.1' ]]; then PHP_UNIT='7.5' elif [[ $PHP_VERSION == '7.2' ]]; then PHP_UNIT='8.5' -elif [[ $PHP_VERSION == '7.3' || $PHP_VERSION == '7.4' || $PHP_VERSION == '8.0' ]]; then +elif [[ $PHP_VERSION == '7.3' || $PHP_VERSION == '7.4' || $PHP_VERSION == '8.0' || $PHP_VERSION == '8.1' || $PHP_VERSION == '8.2' || $PHP_VERSION == '8.3' || $PHP_VERSION == '8.4' ]]; then PHP_UNIT='9.5' fi @@ -73,7 +73,7 @@ git checkout -- $TEST_DIR if [[ $PHP_UNIT == '5.7' || $PHP_UNIT == '6.5' || $PHP_UNIT == '7.5' ]]; then echo "Preparing tests for phpunit-$PHP_UNIT" - find $TEST_DIR -type f -exec sed -i "s/: void//g" {} \; + find $TEST_DIR -type f -exec sed -i "s/: void / /g" {} \; fi exit 0 From 27501b0cf9db53b5fabecab468caabf41efd4bca Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 17:11:54 +0200 Subject: [PATCH 2/8] Fix PHP 8.2 deprecation. --- src/tad/FunctionMocker/MockWrapper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tad/FunctionMocker/MockWrapper.php b/src/tad/FunctionMocker/MockWrapper.php index 3bf1133..4d566a0 100644 --- a/src/tad/FunctionMocker/MockWrapper.php +++ b/src/tad/FunctionMocker/MockWrapper.php @@ -29,7 +29,12 @@ class MockWrapper */ protected $classTemplate; - public function __construct($originalClassName = '', ClassTemplateInterface $classTemplate = null, MethodCodeInterface $methodCode = null) + /** + * @var MethodCode|MethodCodeInterface + */ + private $methodCode; + + public function __construct($originalClassName = '', ClassTemplateInterface $classTemplate = null, MethodCodeInterface $methodCode = null) { $this->originalClassName = $originalClassName; $this->classTemplate = $classTemplate ?: new ClassTemplate(); From 321bc0d2bfae9b316c26864ae3a9e937f7ca33bc Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 17:39:39 +0200 Subject: [PATCH 3/8] Fix update-tests. --- bin/update-tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/update-tests b/bin/update-tests index 5a4ce79..f1e3f48 100644 --- a/bin/update-tests +++ b/bin/update-tests @@ -73,7 +73,7 @@ git checkout -- $TEST_DIR if [[ $PHP_UNIT == '5.7' || $PHP_UNIT == '6.5' || $PHP_UNIT == '7.5' ]]; then echo "Preparing tests for phpunit-$PHP_UNIT" - find $TEST_DIR -type f -exec sed -i "s/: void / /g" {} \; + find $TEST_DIR -type f -exec sed -i "s/: void//g" {} \; fi exit 0 From 0fa8d46f868dc0b2e110eed2c3badfc82b478785 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 21:07:55 +0200 Subject: [PATCH 4/8] Fix typo in changelog.md. --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 805344f..21e942d 100644 --- a/changelog.md +++ b/changelog.md @@ -21,7 +21,7 @@ All notable changes to this project will be documented in this file. This projec ## [1.3.7] ### Fixed -- issue that would generate en excpetion when providing an empty configuration to the `FunctionMocker::init` method +- issue that would generate en exception when providing an empty configuration to the `FunctionMocker::init` method ## [1.3.6] ### Fixed From a66cd4c9cdab130e2500f3c1773429950e0c4c63 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 21:10:15 +0200 Subject: [PATCH 5/8] Set min PHP version to 7.1. --- .github/workflows/ci.yml | 2 +- composer.json | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3784ff0..1d1267d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] + php-version: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] name: PHP ${{ matrix.php-version }} on ${{ matrix.os }} steps: diff --git a/composer.json b/composer.json index cf652f0..c3b9b3a 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,10 @@ ], "minimum-stability": "stable", "require": { - "phpunit/phpunit": "5.7 - 9.5", - "antecedent/patchwork": "^2.0", - "lucatume/args": "^1.0" + "php": ">=7.1", + "phpunit/phpunit": "7.5 - 11.4", + "antecedent/patchwork": "^2.2.0", + "lucatume/args": "^1.0.1" }, "autoload": { "psr-0": { From 30eeae867567a7b7dcfb48a47c8d35f4b42a183b Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 21:23:55 +0200 Subject: [PATCH 6/8] Fix PHP 8.4 deprecation. --- composer.json | 2 +- src/functions.php | 2 +- src/tad/FunctionMocker/Call/Logger/LoggerInterface.php | 2 +- src/tad/FunctionMocker/Call/Logger/SpyCallLogger.php | 4 ++-- .../Call/Verifier/InstanceMethodCallVerifier.php | 2 +- src/tad/FunctionMocker/CallTrace.php | 2 +- src/tad/FunctionMocker/FunctionMocker.php | 6 +++--- src/tad/FunctionMocker/Method/Verifier.php | 2 +- src/tad/FunctionMocker/MockWrapper.php | 4 ++-- src/tad/FunctionMocker/PHPUnitFrameworkAssertWrapper.php | 2 +- src/tad/FunctionMocker/Replacers/InstanceForger.php | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index c3b9b3a..bf30b6c 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "minimum-stability": "stable", "require": { "php": ">=7.1", - "phpunit/phpunit": "7.5 - 11.4", + "phpunit/phpunit": "7.5 - 9.6", "antecedent/patchwork": "^2.2.0", "lucatume/args": "^1.0.1" }, diff --git a/src/functions.php b/src/functions.php index b6864d4..a0ca3f0 100644 --- a/src/functions.php +++ b/src/functions.php @@ -14,7 +14,7 @@ * @see \Patchwork\configure() * */ -function init(array $options = null) { +function init(?array $options = null) { FunctionMocker::init($options); } diff --git a/src/tad/FunctionMocker/Call/Logger/LoggerInterface.php b/src/tad/FunctionMocker/Call/Logger/LoggerInterface.php index f795afa..f59bed0 100644 --- a/src/tad/FunctionMocker/Call/Logger/LoggerInterface.php +++ b/src/tad/FunctionMocker/Call/Logger/LoggerInterface.php @@ -5,5 +5,5 @@ interface LoggerInterface { - public function called(array $args = null); + public function called(?array $args = null); } diff --git a/src/tad/FunctionMocker/Call/Logger/SpyCallLogger.php b/src/tad/FunctionMocker/Call/Logger/SpyCallLogger.php index b34bdbb..e4b1d62 100644 --- a/src/tad/FunctionMocker/Call/Logger/SpyCallLogger.php +++ b/src/tad/FunctionMocker/Call/Logger/SpyCallLogger.php @@ -22,12 +22,12 @@ public function __construct() : '\\PHPUnit\\Framework\\Constraint\\Constraint'; } - public function called(array $args = null) + public function called(?array $args = null) { $this->calls[] = CallTrace::fromArguments($args); } - public function getCallTimes(array $args = null) + public function getCallTimes(?array $args = null) { $calls = $this->calls; if ($args) { diff --git a/src/tad/FunctionMocker/Call/Verifier/InstanceMethodCallVerifier.php b/src/tad/FunctionMocker/Call/Verifier/InstanceMethodCallVerifier.php index 701ef42..7fc19ea 100644 --- a/src/tad/FunctionMocker/Call/Verifier/InstanceMethodCallVerifier.php +++ b/src/tad/FunctionMocker/Call/Verifier/InstanceMethodCallVerifier.php @@ -43,7 +43,7 @@ private function realWasCalledTimes( $times ) { * * @return array */ - protected function getCallTimesWithArgs( $methodName, array $args = null ) { + protected function getCallTimesWithArgs( $methodName, ?array $args = null ) { $invocations = $this->getInvocations(); $callTimes = 0; array_map( function ( $invocation ) use ( &$callTimes, $args, $methodName ) { diff --git a/src/tad/FunctionMocker/CallTrace.php b/src/tad/FunctionMocker/CallTrace.php index 2636eb8..91e09d1 100644 --- a/src/tad/FunctionMocker/CallTrace.php +++ b/src/tad/FunctionMocker/CallTrace.php @@ -7,7 +7,7 @@ class CallTrace protected $args; - public static function fromArguments(array $args = null) + public static function fromArguments(?array $args = null) { $instance = new self; $instance->args = $args ? $args : array(); diff --git a/src/tad/FunctionMocker/FunctionMocker.php b/src/tad/FunctionMocker/FunctionMocker.php index 387b21f..1066703 100644 --- a/src/tad/FunctionMocker/FunctionMocker.php +++ b/src/tad/FunctionMocker/FunctionMocker.php @@ -54,7 +54,7 @@ public static function setUp() { * * @see \Patchwork\configure() */ - public static function init(array $options = null, $forceReinit = false) { + public static function init(?array $options = null, $forceReinit = false) { if (!$forceReinit && self::$didInit) { return; } @@ -300,7 +300,7 @@ private static function getIndexedReplacements($return) { * * @return mixed */ - public static function callOriginal(array $args = null) { + public static function callOriginal(?array $args = null) { return \Patchwork\relay($args); } @@ -367,7 +367,7 @@ public static function forge($class) { * * @throws \RuntimeException If the Patchwork configuration file or the checksum file could not be written. */ - public static function writePatchworkConfig(array $options = null, $destinationFolder) { + public static function writePatchworkConfig(?array $options = null, $destinationFolder) { $options = self::getPatchworkConfiguration($options, $destinationFolder); $configFileContents = json_encode($options); diff --git a/src/tad/FunctionMocker/Method/Verifier.php b/src/tad/FunctionMocker/Method/Verifier.php index 3458a06..cc35c88 100644 --- a/src/tad/FunctionMocker/Method/Verifier.php +++ b/src/tad/FunctionMocker/Method/Verifier.php @@ -27,7 +27,7 @@ public function __construct() { } - public function __call($name, array $args = null) + public function __call($name, ?array $args = null) { return InstanceMethodCallVerifier::from($this->returnValue, $this->callLogger); } diff --git a/src/tad/FunctionMocker/MockWrapper.php b/src/tad/FunctionMocker/MockWrapper.php index 4d566a0..8376491 100644 --- a/src/tad/FunctionMocker/MockWrapper.php +++ b/src/tad/FunctionMocker/MockWrapper.php @@ -34,7 +34,7 @@ class MockWrapper */ private $methodCode; - public function __construct($originalClassName = '', ClassTemplateInterface $classTemplate = null, MethodCodeInterface $methodCode = null) + public function __construct($originalClassName = '', ?ClassTemplateInterface $classTemplate = null, ?MethodCodeInterface $methodCode = null) { $this->originalClassName = $originalClassName; $this->classTemplate = $classTemplate ?: new ClassTemplate(); @@ -71,7 +71,7 @@ public function wrap($mockObject, $invokedRecorder, ReplacementRequest $request) * @throws \Exception * */ - protected function getWrappedInstance($object, ExtenderInterface $extender, $invokedRecorder = null, ReplacementRequest $request = null) + protected function getWrappedInstance($object, ExtenderInterface $extender, $invokedRecorder = null, ?ReplacementRequest $request = null) { $mockClassName = get_class($object); $extendClassName = sprintf('%s_%s', uniqid('Extended_'), $mockClassName); diff --git a/src/tad/FunctionMocker/PHPUnitFrameworkAssertWrapper.php b/src/tad/FunctionMocker/PHPUnitFrameworkAssertWrapper.php index 764ee28..1e01340 100644 --- a/src/tad/FunctionMocker/PHPUnitFrameworkAssertWrapper.php +++ b/src/tad/FunctionMocker/PHPUnitFrameworkAssertWrapper.php @@ -32,7 +32,7 @@ public static function getTestCase() * @param array $args * @return mixed */ - public static function __callStatic($name, array $args = null) + public static function __callStatic($name, ?array $args = null) { return call_user_func_array([self::getTestCase(), $name], $args); } diff --git a/src/tad/FunctionMocker/Replacers/InstanceForger.php b/src/tad/FunctionMocker/Replacers/InstanceForger.php index 78a24d6..34ee417 100644 --- a/src/tad/FunctionMocker/Replacers/InstanceForger.php +++ b/src/tad/FunctionMocker/Replacers/InstanceForger.php @@ -90,7 +90,7 @@ public function getPHPUnitMockObjectFor($className, array $methods) * @param $methodName * @param ReturnValue|null $returnValue */ - public function setMockObjectExpectation(&$mockObject, $methodName, ReturnValue $returnValue = null) + public function setMockObjectExpectation(&$mockObject, $methodName, ?ReturnValue $returnValue = null) { if ($returnValue->isCallable()) { // callback From 45b4893e653326a17717cf41d0cc7e1a240d54fb Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 21:30:58 +0200 Subject: [PATCH 7/8] Update changelog.md. --- changelog.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/changelog.md b/changelog.md index 21e942d..6805cd1 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. This projec ## [Unreleased][unreleased] +## [1.5.0] +### Added +- Support for PHP 8.4. + +### Changed +- The minimum required PHP version is now 7.2. + ## [1.4.0] ### Added - PHP 8 compatibility and test coverage (thanks @kagg-design) From 09bbea66ec7a776cd740ca34a7630345c3795700 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 21:40:18 +0200 Subject: [PATCH 8/8] Fix PHP 8.0 deprecation. --- src/tad/FunctionMocker/FunctionMocker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tad/FunctionMocker/FunctionMocker.php b/src/tad/FunctionMocker/FunctionMocker.php index 1066703..4b9a4a2 100644 --- a/src/tad/FunctionMocker/FunctionMocker.php +++ b/src/tad/FunctionMocker/FunctionMocker.php @@ -367,7 +367,7 @@ public static function forge($class) { * * @throws \RuntimeException If the Patchwork configuration file or the checksum file could not be written. */ - public static function writePatchworkConfig(?array $options = null, $destinationFolder) { + public static function writePatchworkConfig(?array $options = null, $destinationFolder = '') { $options = self::getPatchworkConfiguration($options, $destinationFolder); $configFileContents = json_encode($options);