diff --git a/src/Stub.php b/src/Stub.php index d3a3fcc..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); } /** @@ -433,7 +438,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(); @@ -441,18 +453,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)