From 0216efe874ddc6a1f58624f98a12b2fea244c36a Mon Sep 17 00:00:00 2001 From: W0rma Date: Fri, 6 Oct 2023 11:58:47 +0200 Subject: [PATCH 1/3] Remove obsolete version check since this package requires PHPUnit 8 or higher --- src/Stub.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Stub.php b/src/Stub.php index d3a3fcc..e609250 100644 --- a/src/Stub.php +++ b/src/Stub.php @@ -441,18 +441,13 @@ private static function doGenerateMock($args, $isAbstract = false) $generatorClass = new LegacyGenerator(); } - // using PHPUnit 5.4 mocks registration - if (version_compare(PHPUnitVersion::series(), '5.4', '>=') - && $testCase instanceof PHPUnitTestCase - ) { - $mock = call_user_func_array([$generatorClass, $methodName], $args); - $testCase->registerMockObject($mock); - return $mock; - } + $mock = call_user_func_array([$generatorClass, $methodName], $args); + if ($testCase instanceof PHPUnitTestCase) { - $generatorClass = $testCase; + $testCase->registerMockObject($mock); } - return call_user_func_array([$generatorClass, $methodName], $args); + + return $mock; } private static function extractTestCaseFromArgs(&$args) From e7762fd917d42d13de841c3c18b7c82b0d1a7d5f Mon Sep 17 00:00:00 2001 From: W0rma Date: Fri, 6 Oct 2023 12:04:43 +0200 Subject: [PATCH 2/3] Fix method names of Generator when using PHPUnit 10.4 --- src/Stub.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Stub.php b/src/Stub.php index e609250..f3c0634 100644 --- a/src/Stub.php +++ b/src/Stub.php @@ -433,7 +433,14 @@ private static function generateMockForAbstractClass(): object private static function doGenerateMock($args, $isAbstract = false) { $testCase = self::extractTestCaseFromArgs($args); - $methodName = $isAbstract ? 'getMockForAbstractClass' : 'getMock'; + + // PHPUnit 10.4 changed method names + if (version_compare(PHPUnitVersion::series(), '10.4', '>=')) { + $methodName = $isAbstract ? 'mockObjectForAbstractClass' : 'testDouble'; + } else { + $methodName = $isAbstract ? 'getMockForAbstractClass' : 'getMock'; + } + // PHPUnit 10.3 changed the namespace if (version_compare(PHPUnitVersion::series(), '10.3', '>=')) { $generatorClass = new Generator(); From c9963998a3e3f15774b34977d9383527536f9ecf Mon Sep 17 00:00:00 2001 From: W0rma Date: Fri, 6 Oct 2023 12:23:40 +0200 Subject: [PATCH 3/3] Consider new boolean parameter in Generator::testDouble() added in PHPUnit 10.4 --- src/Stub.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Stub.php b/src/Stub.php index f3c0634..aaee8bc 100644 --- a/src/Stub.php +++ b/src/Stub.php @@ -415,7 +415,12 @@ public static function constructEmptyExcept( private static function generateMock() { - return self::doGenerateMock(func_get_args()); + $args = func_get_args(); + if (version_compare(PHPUnitVersion::series(), '10.4', '>=') && !is_bool($args[1])) { + array_splice($args, 1, 0, [true]); + } + + return self::doGenerateMock($args); } /**