diff --git a/src/Framework/MockObject/Generator/Exception/MethodNamedMethodException.php b/src/Framework/MockObject/Generator/Exception/MethodNamedMethodException.php new file mode 100644 index 00000000000..78586fe1067 --- /dev/null +++ b/src/Framework/MockObject/Generator/Exception/MethodNamedMethodException.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Framework\MockObject\Generator; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class MethodNamedMethodException extends \PHPUnit\Framework\Exception implements Exception +{ + public function __construct() + { + parent::__construct('Doubling interfaces (or classes) that have a method named "method" is not supported.'); + } +} diff --git a/src/Framework/MockObject/Generator/Generator.php b/src/Framework/MockObject/Generator/Generator.php index 12a9c789e08..c079962b98a 100644 --- a/src/Framework/MockObject/Generator/Generator.php +++ b/src/Framework/MockObject/Generator/Generator.php @@ -32,9 +32,6 @@ use Exception; use Iterator; use IteratorAggregate; -use PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException; -use PHPUnit\Event\Code\TestMethodBuilder; -use PHPUnit\Event\Facade as EventFacade; use PHPUnit\Framework\MockObject\ConfigurableMethod; use PHPUnit\Framework\MockObject\DoubledCloneMethod; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; @@ -304,6 +301,7 @@ private function getObject(MockType $mockClass, bool $callOriginalConstructor = * @throws ClassIsEnumerationException * @throws ClassIsFinalException * @throws ClassIsReadonlyException + * @throws MethodNamedMethodException * @throws ReflectionException * @throws RuntimeException */ @@ -471,21 +469,10 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject, } if ($mockMethods->hasMethod('method') || (isset($class) && $class->hasMethod('method'))) { - $message = 'Doubling interfaces (or classes) that have a method named "method" is deprecated. Support for this will be removed in PHPUnit 12.'; - - try { - EventFacade::emitter()->testTriggeredPhpunitDeprecation( - TestMethodBuilder::fromCallStack(), - $message, - ); - } catch (NoTestCaseObjectOnCallStackException) { - EventFacade::emitter()->testRunnerTriggeredDeprecation($message); - } + throw new MethodNamedMethodException; } - if (!$mockMethods->hasMethod('method') && (!isset($class) || !$class->hasMethod('method'))) { - $traits[] = Method::class; - } + $traits[] = Method::class; if ($doubledCloneMethod) { $traits[] = DoubledCloneMethod::class; diff --git a/src/Framework/MockObject/Runtime/Interface/MockObject.php b/src/Framework/MockObject/Runtime/Interface/MockObject.php index 4096d73f922..795694dd1f3 100644 --- a/src/Framework/MockObject/Runtime/Interface/MockObject.php +++ b/src/Framework/MockObject/Runtime/Interface/MockObject.php @@ -13,8 +13,6 @@ use PHPUnit\Framework\MockObject\Rule\InvocationOrder; /** - * @method InvocationMocker method($constraint) - * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ interface MockObject extends Stub diff --git a/src/Framework/MockObject/Runtime/Interface/Stub.php b/src/Framework/MockObject/Runtime/Interface/Stub.php index 96f84d23134..bc8e368bea7 100644 --- a/src/Framework/MockObject/Runtime/Interface/Stub.php +++ b/src/Framework/MockObject/Runtime/Interface/Stub.php @@ -12,10 +12,9 @@ use PHPUnit\Framework\MockObject\Builder\InvocationStubber; /** - * @method InvocationStubber method($constraint) - * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ interface Stub { + public function method(): InvocationStubber; } diff --git a/tests/end-to-end/mock-objects/generator/class_with_method_named_method.phpt b/tests/end-to-end/mock-objects/generator/class_with_method_named_method.phpt deleted file mode 100644 index ff506776ec8..00000000000 --- a/tests/end-to-end/mock-objects/generator/class_with_method_named_method.phpt +++ /dev/null @@ -1,73 +0,0 @@ ---TEST-- -\PHPUnit\Framework\MockObject\Generator\Generator::generate('Foo', [], 'MockFoo', true, true) ---FILE-- -generate( - 'Foo', - true, - true, - [], - 'MockFoo', - true, - true -); - -print $mock->classCode(); ---EXPECTF-- -declare(strict_types=1); - -class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal -{ - use PHPUnit\Framework\MockObject\StubApi; - use PHPUnit\Framework\MockObject\MockObjectApi; - use PHPUnit\Framework\MockObject\GeneratedAsMockObject; - use PHPUnit\Framework\MockObject\DoubledCloneMethod; - - public function method() - { - $__phpunit_definedVariables = get_defined_vars(); - $__phpunit_namedVariadicParameters = []; - - foreach ($__phpunit_definedVariables as $__phpunit_definedVariableName => $__phpunit_definedVariableValue) { - if ((new ReflectionParameter([__CLASS__, __FUNCTION__], $__phpunit_definedVariableName))->isVariadic()) { - foreach ($__phpunit_definedVariableValue as $__phpunit_key => $__phpunit_namedValue) { - if (is_string($__phpunit_key)) { - $__phpunit_namedVariadicParameters[$__phpunit_key] = $__phpunit_namedValue; - } - } - } - } - - $__phpunit_arguments = []; - $__phpunit_count = func_num_args(); - - if ($__phpunit_count > 0) { - $__phpunit_arguments_tmp = func_get_args(); - - for ($__phpunit_i = 0; $__phpunit_i < $__phpunit_count; $__phpunit_i++) { - $__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i]; - } - } - - $__phpunit_arguments = array_merge($__phpunit_arguments, $__phpunit_namedVariadicParameters); - - $__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke( - new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'method', $__phpunit_arguments, '', $this - ) - ); - - return $__phpunit_result; - } -}