From 85e760ea1b0c425d4f14d8c2348fb64a28e32a3a Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 7 Apr 2024 15:03:04 +0200 Subject: [PATCH 01/15] Make it explicit that the embedding class must provide __phpunit_getInvocationHandler() --- src/Framework/MockObject/Runtime/Api/Method.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Framework/MockObject/Runtime/Api/Method.php b/src/Framework/MockObject/Runtime/Api/Method.php index 2112fb3edbb..28fd87424bd 100644 --- a/src/Framework/MockObject/Runtime/Api/Method.php +++ b/src/Framework/MockObject/Runtime/Api/Method.php @@ -28,4 +28,6 @@ public function method(): InvocationMocker func_get_args(), ); } + + abstract public function __phpunit_getInvocationHandler(): InvocationHandler; } From f419f51395e5e82a8f4de33de0024e99a371c9e3 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 7 Apr 2024 15:05:35 +0200 Subject: [PATCH 02/15] Initial work on storing internal state of test doubles in readonly property --- .../MockObject/Generator/Generator.php | 27 ++++-- .../MockObject/Generator/MockClass.php | 17 ++-- .../Generator/templates/proxied_method.tpl | 2 +- .../Runtime/Api/DoubledCloneMethod.php | 4 +- .../MockObject/Runtime/Api/Method.php | 4 +- .../MockObject/Runtime/Api/MockObjectApi.php | 15 +--- .../Runtime/Api/ProxiedCloneMethod.php | 4 +- .../MockObject/Runtime/Api/StubApi.php | 29 ++----- .../Runtime/Api/TestDoubleState.php | 87 +++++++++++++++++++ .../Runtime/Interface/MockObjectInternal.php | 2 - .../Runtime/Interface/StubInternal.php | 4 +- .../mock-objects/generator/proxy.phpt | 4 +- .../mock-method/call_original.phpt | 2 +- .../call_original_with_argument.phpt | 2 +- .../call_original_with_argument_variadic.phpt | 2 +- .../call_original_with_return_type_void.phpt | 2 +- 16 files changed, 141 insertions(+), 66 deletions(-) create mode 100644 src/Framework/MockObject/Runtime/Api/TestDoubleState.php diff --git a/src/Framework/MockObject/Generator/Generator.php b/src/Framework/MockObject/Generator/Generator.php index 526415dd972..63ebe86f95f 100644 --- a/src/Framework/MockObject/Generator/Generator.php +++ b/src/Framework/MockObject/Generator/Generator.php @@ -58,8 +58,10 @@ use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\StubApi; use PHPUnit\Framework\MockObject\StubInternal; +use PHPUnit\Framework\MockObject\TestDoubleState; use ReflectionClass; use ReflectionMethod; +use ReflectionObject; use SoapClient; use SoapFault; use Throwable; @@ -580,12 +582,20 @@ private function getObject(MockType $mockClass, string $type = '', bool $callOri $className = $mockClass->generate(); $object = $this->instantiate($className, $callOriginalConstructor, $arguments); - if ($callOriginalMethods) { - $this->instantiateProxyTarget($proxyTarget, $object, $type, $arguments); - } + if ($object instanceof StubInternal && $mockClass instanceof MockClass) { + /** + * @psalm-suppress MissingThrowsDocblock + * + * @noinspection PhpUnhandledExceptionInspection + */ + (new ReflectionObject($object))->getProperty('__phpunit_state')->setValue( + $object, + new TestDoubleState($mockClass->configurableMethods(), $returnValueGeneration), + ); - if ($object instanceof StubInternal) { - $object->__phpunit_setReturnValueGeneration($returnValueGeneration); + if ($callOriginalMethods) { + $this->instantiateProxyTarget($proxyTarget, $object, $type, $arguments); + } } return $object; @@ -1041,7 +1051,12 @@ private function instantiateProxyTarget(?object $proxyTarget, object $object, st } } - $object->__phpunit_setOriginalObject($proxyTarget); + /** + * @psalm-suppress MissingThrowsDocblock + * + * @noinspection PhpUnhandledExceptionInspection + */ + (new ReflectionObject($object))->getProperty('__phpunit_state')->getValue($object)->setProxyTarget($proxyTarget); } /** diff --git a/src/Framework/MockObject/Generator/MockClass.php b/src/Framework/MockObject/Generator/MockClass.php index 99bfe3ca749..9edd9067398 100644 --- a/src/Framework/MockObject/Generator/MockClass.php +++ b/src/Framework/MockObject/Generator/MockClass.php @@ -9,7 +9,6 @@ */ namespace PHPUnit\Framework\MockObject\Generator; -use function call_user_func; use function class_exists; use PHPUnit\Framework\MockObject\ConfigurableMethod; @@ -48,14 +47,6 @@ public function generate(): string { if (!class_exists($this->mockName, false)) { eval($this->classCode); - - call_user_func( - [ - $this->mockName, - '__phpunit_initConfigurableMethods', - ], - ...$this->configurableMethods, - ); } return $this->mockName; @@ -65,4 +56,12 @@ public function classCode(): string { return $this->classCode; } + + /** + * @psalm-return list + */ + public function configurableMethods(): array + { + return $this->configurableMethods; + } } diff --git a/src/Framework/MockObject/Generator/templates/proxied_method.tpl b/src/Framework/MockObject/Generator/templates/proxied_method.tpl index 94db4665e83..c971b9ba1bc 100644 --- a/src/Framework/MockObject/Generator/templates/proxied_method.tpl +++ b/src/Framework/MockObject/Generator/templates/proxied_method.tpl @@ -33,5 +33,5 @@ ) ); - $__phpunit_result = call_user_func_array([$this->__phpunit_originalObject, "{method_name}"], $__phpunit_arguments);{return_result} + $__phpunit_result = call_user_func_array([$this->__phpunit_state()->proxyTarget(), "{method_name}"], $__phpunit_arguments);{return_result} } diff --git a/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php b/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php index bb02daf8743..c6c16f2403c 100644 --- a/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php +++ b/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php @@ -16,6 +16,8 @@ trait DoubledCloneMethod { public function __clone(): void { - $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationHandler(); + $this->__phpunit_state()->cloneInvocationHandler(); } + + abstract public function __phpunit_state(): TestDoubleState; } diff --git a/src/Framework/MockObject/Runtime/Api/Method.php b/src/Framework/MockObject/Runtime/Api/Method.php index 28fd87424bd..ebb28a74022 100644 --- a/src/Framework/MockObject/Runtime/Api/Method.php +++ b/src/Framework/MockObject/Runtime/Api/Method.php @@ -19,6 +19,8 @@ */ trait Method { + abstract public function __phpunit_getInvocationHandler(): InvocationHandler; + public function method(): InvocationMocker { $expects = $this->__phpunit_getInvocationHandler()->expects(new AnyInvokedCount); @@ -28,6 +30,4 @@ public function method(): InvocationMocker func_get_args(), ); } - - abstract public function __phpunit_getInvocationHandler(): InvocationHandler; } diff --git a/src/Framework/MockObject/Runtime/Api/MockObjectApi.php b/src/Framework/MockObject/Runtime/Api/MockObjectApi.php index 25fb4b9c6a1..192908db93b 100644 --- a/src/Framework/MockObject/Runtime/Api/MockObjectApi.php +++ b/src/Framework/MockObject/Runtime/Api/MockObjectApi.php @@ -21,21 +21,12 @@ */ trait MockObjectApi { - private static array $__phpunit_deprecation_emitted_for_test = []; - private object $__phpunit_originalObject; - /** @noinspection MagicMethodsValidityInspection */ public function __phpunit_hasMatchers(): bool { return $this->__phpunit_getInvocationHandler()->hasMatchers(); } - /** @noinspection MagicMethodsValidityInspection */ - public function __phpunit_setOriginalObject(object $originalObject): void - { - $this->__phpunit_originalObject = $originalObject; - } - /** @noinspection MagicMethodsValidityInspection */ public function __phpunit_verify(bool $unsetInvocationMocker = true): void { @@ -46,6 +37,8 @@ public function __phpunit_verify(bool $unsetInvocationMocker = true): void } } + abstract public function __phpunit_state(): TestDoubleState; + abstract public function __phpunit_getInvocationHandler(): InvocationHandler; abstract public function __phpunit_unsetInvocationMocker(): void; @@ -60,13 +53,13 @@ public function expects(InvocationOrder $matcher): InvocationMockerBuilder try { $test = TestMethodBuilder::fromCallStack(); - if (!isset(self::$__phpunit_deprecation_emitted_for_test[$test->id()])) { + if (!$this->__phpunit_state()->wasDeprecationAlreadyEmittedFor($test->id())) { EventFacade::emitter()->testTriggeredPhpunitDeprecation( $test, $message, ); - self::$__phpunit_deprecation_emitted_for_test[$test->id()] = true; + $this->__phpunit_state()->deprecationWasEmittedFor($test->id()); } } catch (NoTestCaseObjectOnCallStackException) { EventFacade::emitter()->testRunnerTriggeredDeprecation($message); diff --git a/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php b/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php index ae0dbc78c08..657bdb61c7e 100644 --- a/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php +++ b/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php @@ -16,8 +16,10 @@ trait ProxiedCloneMethod { public function __clone(): void { - $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationHandler(); + $this->__phpunit_state()->cloneInvocationHandler(); parent::__clone(); } + + abstract public function __phpunit_state(): TestDoubleState; } diff --git a/src/Framework/MockObject/Runtime/Api/StubApi.php b/src/Framework/MockObject/Runtime/Api/StubApi.php index 64bed690164..5e39fecbc1f 100644 --- a/src/Framework/MockObject/Runtime/Api/StubApi.php +++ b/src/Framework/MockObject/Runtime/Api/StubApi.php @@ -14,41 +14,22 @@ */ trait StubApi { - /** - * @psalm-var list - */ - private static array $__phpunit_configurableMethods; - private bool $__phpunit_returnValueGeneration = true; - private ?InvocationHandler $__phpunit_invocationMocker = null; + private readonly TestDoubleState $__phpunit_state; - /** @noinspection MagicMethodsValidityInspection */ - public static function __phpunit_initConfigurableMethods(ConfigurableMethod ...$configurableMethods): void - { - static::$__phpunit_configurableMethods = $configurableMethods; - } - - /** @noinspection MagicMethodsValidityInspection */ - public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration): void + public function __phpunit_state(): TestDoubleState { - $this->__phpunit_returnValueGeneration = $returnValueGeneration; + return $this->__phpunit_state; } /** @noinspection MagicMethodsValidityInspection */ public function __phpunit_getInvocationHandler(): InvocationHandler { - if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new InvocationHandler( - static::$__phpunit_configurableMethods, - $this->__phpunit_returnValueGeneration, - ); - } - - return $this->__phpunit_invocationMocker; + return $this->__phpunit_state->invocationHandler(); } /** @noinspection MagicMethodsValidityInspection */ public function __phpunit_unsetInvocationMocker(): void { - $this->__phpunit_invocationMocker = null; + $this->__phpunit_state->unsetInvocationHandler(); } } diff --git a/src/Framework/MockObject/Runtime/Api/TestDoubleState.php b/src/Framework/MockObject/Runtime/Api/TestDoubleState.php new file mode 100644 index 00000000000..43396b27abe --- /dev/null +++ b/src/Framework/MockObject/Runtime/Api/TestDoubleState.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Framework\MockObject; + +use function assert; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TestDoubleState +{ + private static array $deprecationEmittedForTest = []; + + /** + * @psalm-var list + */ + private readonly array $configurableMethods; + private readonly bool $generateReturnValues; + private ?InvocationHandler $invocationHandler = null; + private ?object $proxyTarget = null; + + /** + * @psalm-param list $configurableMethods + */ + public function __construct(array $configurableMethods, bool $generateReturnValues) + { + $this->configurableMethods = $configurableMethods; + $this->generateReturnValues = $generateReturnValues; + } + + public function invocationHandler(): InvocationHandler + { + if ($this->invocationHandler !== null) { + return $this->invocationHandler; + } + + $this->invocationHandler = new InvocationHandler( + $this->configurableMethods, + $this->generateReturnValues, + ); + + return $this->invocationHandler; + } + + public function cloneInvocationHandler(): void + { + if ($this->invocationHandler === null) { + return; + } + + $this->invocationHandler = clone $this->invocationHandler; + } + + public function unsetInvocationHandler(): void + { + $this->invocationHandler = null; + } + + public function setProxyTarget(object $proxyTarget): void + { + $this->proxyTarget = $proxyTarget; + } + + public function proxyTarget(): object + { + assert($this->proxyTarget !== null); + + return $this->proxyTarget; + } + + public function deprecationWasEmittedFor(string $testId): void + { + self::$deprecationEmittedForTest[$testId] = true; + } + + public function wasDeprecationAlreadyEmittedFor(string $testId): bool + { + return isset(self::$deprecationEmittedForTest[$testId]); + } +} diff --git a/src/Framework/MockObject/Runtime/Interface/MockObjectInternal.php b/src/Framework/MockObject/Runtime/Interface/MockObjectInternal.php index bb84ffaccb6..0952566774a 100644 --- a/src/Framework/MockObject/Runtime/Interface/MockObjectInternal.php +++ b/src/Framework/MockObject/Runtime/Interface/MockObjectInternal.php @@ -16,7 +16,5 @@ interface MockObjectInternal extends MockObject, StubInternal { public function __phpunit_hasMatchers(): bool; - public function __phpunit_setOriginalObject(object $originalObject): void; - public function __phpunit_verify(bool $unsetInvocationMocker = true): void; } diff --git a/src/Framework/MockObject/Runtime/Interface/StubInternal.php b/src/Framework/MockObject/Runtime/Interface/StubInternal.php index 10445265ada..57e46f3df09 100644 --- a/src/Framework/MockObject/Runtime/Interface/StubInternal.php +++ b/src/Framework/MockObject/Runtime/Interface/StubInternal.php @@ -14,12 +14,10 @@ */ interface StubInternal extends Stub { - public static function __phpunit_initConfigurableMethods(ConfigurableMethod ...$configurableMethods): void; + public function __phpunit_state(): TestDoubleState; public function __phpunit_getInvocationHandler(): InvocationHandler; - public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration): void; - public function __phpunit_unsetInvocationMocker(): void; public function __phpunit_wasGeneratedAsMockObject(): bool; diff --git a/tests/end-to-end/mock-objects/generator/proxy.phpt b/tests/end-to-end/mock-objects/generator/proxy.phpt index c2cb97cf7b6..360f0b62421 100644 --- a/tests/end-to-end/mock-objects/generator/proxy.phpt +++ b/tests/end-to-end/mock-objects/generator/proxy.phpt @@ -67,7 +67,7 @@ class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInt ) ); - $__phpunit_result = call_user_func_array([$this->__phpunit_originalObject, "bar"], $__phpunit_arguments); + $__phpunit_result = call_user_func_array([$this->__phpunit_state()->proxyTarget(), "bar"], $__phpunit_arguments); return $__phpunit_result; } @@ -106,7 +106,7 @@ class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInt ) ); - $__phpunit_result = call_user_func_array([$this->__phpunit_originalObject, "baz"], $__phpunit_arguments); + $__phpunit_result = call_user_func_array([$this->__phpunit_state()->proxyTarget(), "baz"], $__phpunit_arguments); return $__phpunit_result; } diff --git a/tests/end-to-end/mock-objects/mock-method/call_original.phpt b/tests/end-to-end/mock-objects/mock-method/call_original.phpt index 4beb2faabfb..bbc67bd6dd0 100644 --- a/tests/end-to-end/mock-objects/mock-method/call_original.phpt +++ b/tests/end-to-end/mock-objects/mock-method/call_original.phpt @@ -55,7 +55,7 @@ print $code; ) ); - $__phpunit_result = call_user_func_array([$this->__phpunit_originalObject, "bar"], $__phpunit_arguments); + $__phpunit_result = call_user_func_array([$this->__phpunit_state()->proxyTarget(), "bar"], $__phpunit_arguments); return $__phpunit_result; } diff --git a/tests/end-to-end/mock-objects/mock-method/call_original_with_argument.phpt b/tests/end-to-end/mock-objects/mock-method/call_original_with_argument.phpt index 8dfab7f39ae..1ef50e1080a 100644 --- a/tests/end-to-end/mock-objects/mock-method/call_original_with_argument.phpt +++ b/tests/end-to-end/mock-objects/mock-method/call_original_with_argument.phpt @@ -55,7 +55,7 @@ private function bar($arg) ) ); - $__phpunit_result = call_user_func_array([$this->__phpunit_originalObject, "bar"], $__phpunit_arguments); + $__phpunit_result = call_user_func_array([$this->__phpunit_state()->proxyTarget(), "bar"], $__phpunit_arguments); return $__phpunit_result; } diff --git a/tests/end-to-end/mock-objects/mock-method/call_original_with_argument_variadic.phpt b/tests/end-to-end/mock-objects/mock-method/call_original_with_argument_variadic.phpt index bf99664c952..bc31d806e7a 100644 --- a/tests/end-to-end/mock-objects/mock-method/call_original_with_argument_variadic.phpt +++ b/tests/end-to-end/mock-objects/mock-method/call_original_with_argument_variadic.phpt @@ -55,7 +55,7 @@ private function bar(...$args) ) ); - $__phpunit_result = call_user_func_array([$this->__phpunit_originalObject, "bar"], $__phpunit_arguments); + $__phpunit_result = call_user_func_array([$this->__phpunit_state()->proxyTarget(), "bar"], $__phpunit_arguments); return $__phpunit_result; } diff --git a/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt b/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt index f92156737e6..f3bf9c7c7fb 100644 --- a/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt +++ b/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt @@ -55,5 +55,5 @@ print $code; ) ); - $__phpunit_result = call_user_func_array([$this->__phpunit_originalObject, "bar"], $__phpunit_arguments); + $__phpunit_result = call_user_func_array([$this->__phpunit_state()->proxyTarget(), "bar"], $__phpunit_arguments); } From 83bbb81547363307a07fec8b5a322fc39c9f4448 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 8 Apr 2024 07:55:11 +0200 Subject: [PATCH 03/15] Also assert that we have a MockObject instance --- tests/unit/Framework/MockObject/Creation/CreateMockTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/Framework/MockObject/Creation/CreateMockTest.php b/tests/unit/Framework/MockObject/Creation/CreateMockTest.php index 0c29c46fcf2..04e21e88f12 100644 --- a/tests/unit/Framework/MockObject/Creation/CreateMockTest.php +++ b/tests/unit/Framework/MockObject/Creation/CreateMockTest.php @@ -36,6 +36,7 @@ public function testCreatesMockObjectForInterface(): void $this->assertInstanceOf(AnInterface::class, $double); $this->assertInstanceOf(Stub::class, $double); + $this->assertInstanceOf(MockObject::class, $double); } public function testCreatesMockObjectForExtendableClass(): void @@ -44,6 +45,7 @@ public function testCreatesMockObjectForExtendableClass(): void $this->assertInstanceOf(ExtendableClass::class, $double); $this->assertInstanceOf(Stub::class, $double); + $this->assertInstanceOf(MockObject::class, $double); } public function testReturnValueGenerationIsEnabledByDefault(): void From b972208bcf086665d79e9f118d5f4912f4523d12 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 8 Apr 2024 07:57:12 +0200 Subject: [PATCH 04/15] Allow doubling of readonly classes --- .psalm/baseline.xml | 1 - .../Exception/ClassIsReadonlyException.php | 28 ------------------- .../MockObject/Generator/Generator.php | 18 ++++++------ src/Framework/MockObject/MockBuilder.php | 2 -- .../MockObject/Creation/CreateMockTest.php | 17 +++++------ .../MockObject/Creation/CreateStubTest.php | 16 +++++------ 6 files changed, 27 insertions(+), 55 deletions(-) delete mode 100644 src/Framework/MockObject/Generator/Exception/ClassIsReadonlyException.php diff --git a/.psalm/baseline.xml b/.psalm/baseline.xml index 5874f62456b..8959e902162 100644 --- a/.psalm/baseline.xml +++ b/.psalm/baseline.xml @@ -255,7 +255,6 @@ - __getFunctions()]]> diff --git a/src/Framework/MockObject/Generator/Exception/ClassIsReadonlyException.php b/src/Framework/MockObject/Generator/Exception/ClassIsReadonlyException.php deleted file mode 100644 index 7cf07fe9c79..00000000000 --- a/src/Framework/MockObject/Generator/Exception/ClassIsReadonlyException.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace PHPUnit\Framework\MockObject\Generator; - -use function sprintf; - -/** - * @internal This class is not covered by the backward compatibility promise for PHPUnit - */ -final class ClassIsReadonlyException extends \PHPUnit\Framework\Exception implements Exception -{ - public function __construct(string $className) - { - parent::__construct( - sprintf( - 'Class "%s" is declared "readonly" and cannot be doubled', - $className, - ), - ); - } -} diff --git a/src/Framework/MockObject/Generator/Generator.php b/src/Framework/MockObject/Generator/Generator.php index 63ebe86f95f..1ecf8551066 100644 --- a/src/Framework/MockObject/Generator/Generator.php +++ b/src/Framework/MockObject/Generator/Generator.php @@ -101,7 +101,6 @@ final class Generator * @throws ClassAlreadyExistsException * @throws ClassIsEnumerationException * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws InvalidMethodNameException * @throws OriginalConstructorInvocationRequiredException @@ -234,7 +233,6 @@ public function testDoubleForInterfaceIntersection(array $interfaces, bool $mock * @throws ClassAlreadyExistsException * @throws ClassIsEnumerationException * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws InvalidArgumentException * @throws InvalidMethodNameException @@ -295,7 +293,6 @@ interface_exists($originalClassName, $callAutoload)) { * @throws ClassAlreadyExistsException * @throws ClassIsEnumerationException * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws InvalidArgumentException * @throws InvalidMethodNameException @@ -383,7 +380,6 @@ public function objectForTrait(string $traitName, string $traitClassName = '', b /** * @throws ClassIsEnumerationException * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ReflectionException * @throws RuntimeException * @@ -604,7 +600,6 @@ private function getObject(MockType $mockClass, string $type = '', bool $callOri /** * @throws ClassIsEnumerationException * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ReflectionException * @throws RuntimeException */ @@ -615,6 +610,7 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject, $doubledCloneMethod = false; $proxiedCloneMethod = false; $isClass = false; + $isReadonly = false; $isInterface = false; $class = null; $mockMethods = new MockMethodSet; @@ -656,7 +652,7 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject, } if ($class->isReadOnly()) { - throw new ClassIsReadonlyException($_mockClassName['fullClassName']); + $isReadonly = true; } // @see https://github.com/sebastianbergmann/phpunit/issues/2995 @@ -826,6 +822,7 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject, $_mockClassName, $isInterface, $additionalInterfaces, + $isReadonly, ), 'use_statements' => $useStatements, 'mock_class_name' => $_mockClassName['className'], @@ -872,7 +869,7 @@ private function generateClassName(string $type, string $className, string $pref ]; } - private function generateTestDoubleClassDeclaration(bool $mockObject, array $mockClassName, bool $isInterface, array $additionalInterfaces = []): string + private function generateTestDoubleClassDeclaration(bool $mockObject, array $mockClassName, bool $isInterface, array $additionalInterfaces, bool $isReadonly): string { if ($mockObject) { $additionalInterfaces[] = MockObjectInternal::class; @@ -880,7 +877,12 @@ private function generateTestDoubleClassDeclaration(bool $mockObject, array $moc $additionalInterfaces[] = StubInternal::class; } - $buffer = 'class '; + if ($isReadonly) { + $buffer = 'readonly class '; + } else { + $buffer = 'class '; + } + $interfaces = implode(', ', $additionalInterfaces); if ($isInterface) { diff --git a/src/Framework/MockObject/MockBuilder.php b/src/Framework/MockObject/MockBuilder.php index ecb9d7afff1..e1e3dfc5068 100644 --- a/src/Framework/MockObject/MockBuilder.php +++ b/src/Framework/MockObject/MockBuilder.php @@ -19,7 +19,6 @@ use PHPUnit\Framework\MockObject\Generator\ClassAlreadyExistsException; use PHPUnit\Framework\MockObject\Generator\ClassIsEnumerationException; use PHPUnit\Framework\MockObject\Generator\ClassIsFinalException; -use PHPUnit\Framework\MockObject\Generator\ClassIsReadonlyException; use PHPUnit\Framework\MockObject\Generator\DuplicateMethodException; use PHPUnit\Framework\MockObject\Generator\Generator; use PHPUnit\Framework\MockObject\Generator\InvalidMethodNameException; @@ -81,7 +80,6 @@ public function __construct(TestCase $testCase, string $type) * @throws ClassAlreadyExistsException * @throws ClassIsEnumerationException * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws InvalidArgumentException * @throws InvalidMethodNameException diff --git a/tests/unit/Framework/MockObject/Creation/CreateMockTest.php b/tests/unit/Framework/MockObject/Creation/CreateMockTest.php index 04e21e88f12..5c480b94d9f 100644 --- a/tests/unit/Framework/MockObject/Creation/CreateMockTest.php +++ b/tests/unit/Framework/MockObject/Creation/CreateMockTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\MockObject\Generator\ClassIsEnumerationException; use PHPUnit\Framework\MockObject\Generator\ClassIsFinalException; -use PHPUnit\Framework\MockObject\Generator\ClassIsReadonlyException; use PHPUnit\Framework\MockObject\Generator\UnknownTypeException; use PHPUnit\Framework\TestCase; use PHPUnit\TestFixture\MockObject\AnInterface; @@ -48,6 +47,15 @@ public function testCreatesMockObjectForExtendableClass(): void $this->assertInstanceOf(MockObject::class, $double); } + public function testCreatesMockObjectForReadonlyClass(): void + { + $double = $this->createMock(ReadonlyClass::class); + + $this->assertInstanceOf(ReadonlyClass::class, $double); + $this->assertInstanceOf(Stub::class, $double); + $this->assertInstanceOf(MockObject::class, $double); + } + public function testReturnValueGenerationIsEnabledByDefault(): void { $double = $this->createMock(AnInterface::class); @@ -62,13 +70,6 @@ public function testCannotCreateMockObjectForFinalClass(): void $this->createMock(FinalClass::class); } - public function testCannotCreateMockObjectForReadonlyClass(): void - { - $this->expectException(ClassIsReadonlyException::class); - - $this->createMock(ReadonlyClass::class); - } - public function testCannotCreateMockObjectForEnumeration(): void { $this->expectException(ClassIsEnumerationException::class); diff --git a/tests/unit/Framework/MockObject/Creation/CreateStubTest.php b/tests/unit/Framework/MockObject/Creation/CreateStubTest.php index 085ee03a4ac..631300236dd 100644 --- a/tests/unit/Framework/MockObject/Creation/CreateStubTest.php +++ b/tests/unit/Framework/MockObject/Creation/CreateStubTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\MockObject\Generator\ClassIsEnumerationException; use PHPUnit\Framework\MockObject\Generator\ClassIsFinalException; -use PHPUnit\Framework\MockObject\Generator\ClassIsReadonlyException; use PHPUnit\Framework\MockObject\Generator\UnknownTypeException; use PHPUnit\Framework\TestCase; use PHPUnit\TestFixture\MockObject\AnInterface; @@ -46,6 +45,14 @@ public function testCreatesTestStubForExtendableClass(): void $this->assertInstanceOf(Stub::class, $double); } + public function testCreatesTestStubForReadonlyClass(): void + { + $double = $this->createStub(ReadonlyClass::class); + + $this->assertInstanceOf(ReadonlyClass::class, $double); + $this->assertInstanceOf(Stub::class, $double); + } + public function testReturnValueGenerationIsEnabledByDefault(): void { $double = $this->createStub(AnInterface::class); @@ -60,13 +67,6 @@ public function testCannotCreateTestStubForFinalClass(): void $this->createStub(FinalClass::class); } - public function testCannotCreateTestStubForReadonlyClass(): void - { - $this->expectException(ClassIsReadonlyException::class); - - $this->createStub(ReadonlyClass::class); - } - public function testCannotCreateTestStubForEnumeration(): void { $this->expectException(ClassIsEnumerationException::class); From bebb3d84a21c6a1615a919e958fa65f264c05a6c Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 8 Apr 2024 08:12:51 +0200 Subject: [PATCH 05/15] Simplify --- src/Framework/MockObject/Generator/Generator.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Framework/MockObject/Generator/Generator.php b/src/Framework/MockObject/Generator/Generator.php index 1ecf8551066..9d0e2dff776 100644 --- a/src/Framework/MockObject/Generator/Generator.php +++ b/src/Framework/MockObject/Generator/Generator.php @@ -1053,12 +1053,7 @@ private function instantiateProxyTarget(?object $proxyTarget, object $object, st } } - /** - * @psalm-suppress MissingThrowsDocblock - * - * @noinspection PhpUnhandledExceptionInspection - */ - (new ReflectionObject($object))->getProperty('__phpunit_state')->getValue($object)->setProxyTarget($proxyTarget); + $object->__phpunit_state()->setProxyTarget($proxyTarget); } /** From 4adbc2fec11e87418d742f2525eb299b224f5d6c Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Tue, 9 Apr 2024 07:44:49 +0200 Subject: [PATCH 06/15] Clone TestDoubleState object --- src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php | 2 ++ src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php b/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php index c6c16f2403c..c1aae784b53 100644 --- a/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php +++ b/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php @@ -16,6 +16,8 @@ trait DoubledCloneMethod { public function __clone(): void { + $this->__phpunit_state = clone $this->__phpunit_state; + $this->__phpunit_state()->cloneInvocationHandler(); } diff --git a/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php b/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php index 657bdb61c7e..e573031f4ac 100644 --- a/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php +++ b/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php @@ -16,6 +16,8 @@ trait ProxiedCloneMethod { public function __clone(): void { + $this->__phpunit_state = clone $this->__phpunit_state; + $this->__phpunit_state()->cloneInvocationHandler(); parent::__clone(); From 4628535743ea47e80caca0f6bd7c8b5e47f9aca4 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Tue, 9 Apr 2024 07:45:29 +0200 Subject: [PATCH 07/15] Cloning readonly properties does not work in PHP 8.2 --- .../MockObject/Runtime/Api/DoubledCloneMethod.php | 13 +++++++++++++ .../MockObject/Runtime/Api/ProxiedCloneMethod.php | 13 +++++++++++++ tests/unit/Framework/MockObject/MockObjectTest.php | 2 ++ .../Framework/MockObject/TestDoubleTestCase.php | 3 +++ 4 files changed, 31 insertions(+) diff --git a/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php b/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php index c1aae784b53..2c131d51057 100644 --- a/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php +++ b/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php @@ -9,6 +9,10 @@ */ namespace PHPUnit\Framework\MockObject; +use function version_compare; +use PHPUnit\Event\Code\TestMethodBuilder; +use PHPUnit\Event\Facade as EventFacade; + /** * @internal This trait is not covered by the backward compatibility promise for PHPUnit */ @@ -16,6 +20,15 @@ trait DoubledCloneMethod { public function __clone(): void { + if (version_compare('8.3.0', PHP_VERSION, '>')) { + EventFacade::emitter()->testTriggeredPhpunitError( + TestMethodBuilder::fromCallStack(), + 'Cloning test double objects requires PHP 8.3', + ); + + return; + } + $this->__phpunit_state = clone $this->__phpunit_state; $this->__phpunit_state()->cloneInvocationHandler(); diff --git a/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php b/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php index e573031f4ac..4e37fc7209c 100644 --- a/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php +++ b/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php @@ -9,6 +9,10 @@ */ namespace PHPUnit\Framework\MockObject; +use function version_compare; +use PHPUnit\Event\Code\TestMethodBuilder; +use PHPUnit\Event\Facade as EventFacade; + /** * @internal This trait is not covered by the backward compatibility promise for PHPUnit */ @@ -16,6 +20,15 @@ trait ProxiedCloneMethod { public function __clone(): void { + if (version_compare('8.3.0', PHP_VERSION, '>')) { + EventFacade::emitter()->testTriggeredPhpunitError( + TestMethodBuilder::fromCallStack(), + 'Cloning test double objects requires PHP 8.3', + ); + + return; + } + $this->__phpunit_state = clone $this->__phpunit_state; $this->__phpunit_state()->cloneInvocationHandler(); diff --git a/tests/unit/Framework/MockObject/MockObjectTest.php b/tests/unit/Framework/MockObject/MockObjectTest.php index 14a16b33957..f0a1c484d59 100644 --- a/tests/unit/Framework/MockObject/MockObjectTest.php +++ b/tests/unit/Framework/MockObject/MockObjectTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations; use PHPUnit\Framework\Attributes\Medium; +use PHPUnit\Framework\Attributes\RequiresPhp; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; @@ -443,6 +444,7 @@ public function testWillReturnCallbackWithVariadicVariables(): void $this->assertSame($testData, $actual); } + #[RequiresPhp('8.3')] public function testExpectationsAreClonedWhenTestDoubleIsCloned(): void { $double = $this->createMock(InterfaceWithReturnTypeDeclaration::class); diff --git a/tests/unit/Framework/MockObject/TestDoubleTestCase.php b/tests/unit/Framework/MockObject/TestDoubleTestCase.php index aa4142ab3ac..00e775acdc7 100644 --- a/tests/unit/Framework/MockObject/TestDoubleTestCase.php +++ b/tests/unit/Framework/MockObject/TestDoubleTestCase.php @@ -11,6 +11,7 @@ use Exception; use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations; +use PHPUnit\Framework\Attributes\RequiresPhp; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; use PHPUnit\TestFixture\MockObject\ExtendableClassWithCloneMethod; @@ -240,6 +241,7 @@ final public function testMethodWithNeverReturnTypeDeclarationThrowsException(): } #[TestDox('Original __clone() method is not called by default when test double object is cloned')] + #[RequiresPhp('8.3')] final public function testOriginalCloneMethodIsNotCalledByDefaultWhenTestDoubleObjectIsCloned(): void { $double = clone $this->createTestDouble(ExtendableClassWithCloneMethod::class); @@ -248,6 +250,7 @@ final public function testOriginalCloneMethodIsNotCalledByDefaultWhenTestDoubleO } #[TestDox('Original __clone() method can optionally be called when test double object is cloned')] + #[RequiresPhp('8.3')] final public function testOriginalCloneMethodCanOptionallyBeCalledWhenTestDoubleObjectIsCloned(): void { $double = $this->getMockBuilder(ExtendableClassWithCloneMethod::class)->enableOriginalClone()->getMock(); From d660f268d48b8e67652b56f136766e8994d7b419 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 10 Apr 2024 18:03:09 +0200 Subject: [PATCH 08/15] Restore clone-ability of test doubles for non-readonly classes with PHP 8.2 --- .../MockObject/Generator/Generator.php | 10 +++++- .../Runtime/Api/DoubledCloneMethod.php | 13 ------- .../MockObject/Runtime/Api/MutableStubApi.php | 35 +++++++++++++++++++ .../Runtime/Api/ProxiedCloneMethod.php | 13 ------- .../mock-objects/generator/232.phpt | 2 +- .../3154_namespaced_constant_resolving.phpt | 2 +- .../mock-objects/generator/3967.phpt | 4 +-- .../mock-objects/generator/397.phpt | 2 +- .../mock-objects/generator/4139.phpt | 2 +- .../generator/abstract_class.phpt | 2 +- .../mock-objects/generator/class.phpt | 2 +- .../generator/class_call_parent_clone.phpt | 2 +- .../class_call_parent_constructor.phpt | 2 +- .../class_dont_call_parent_clone.phpt | 2 +- .../class_dont_call_parent_constructor.phpt | 2 +- ...ing_interface_call_parent_constructor.phpt | 2 +- ...nterface_dont_call_parent_constructor.phpt | 2 +- .../generator/class_nonexistent_method.phpt | 2 +- .../mock-objects/generator/class_partial.phpt | 2 +- .../class_with_deprecated_method.phpt | 2 +- .../generator/class_with_final_method.phpt | 2 +- .../class_with_method_named_method.phpt | 2 +- ...ullable_typehinted_variadic_arguments.phpt | 2 +- ...od_with_typehinted_variadic_arguments.phpt | 2 +- ...s_with_method_with_variadic_arguments.phpt | 2 +- .../constant_as_parameter_default_value.phpt | 2 +- .../mock-objects/generator/interface.phpt | 2 +- .../invocation_object_clone_object.phpt | 2 +- .../generator/namespaced_class.phpt | 2 +- .../namespaced_class_call_parent_clone.phpt | 2 +- ...espaced_class_call_parent_constructor.phpt | 2 +- ...mespaced_class_dont_call_parent_clone.phpt | 2 +- ...ed_class_dont_call_parent_constructor.phpt | 2 +- ...ing_interface_call_parent_constructor.phpt | 2 +- ...nterface_dont_call_parent_constructor.phpt | 2 +- .../generator/namespaced_class_partial.phpt | 2 +- .../generator/namespaced_interface.phpt | 2 +- .../generator/nonexistent_class.phpt | 2 +- .../nonexistent_class_with_namespace.phpt | 2 +- ...ith_namespace_starting_with_separator.phpt | 2 +- .../generator/nullable_types.phpt | 2 +- .../nullable_union_type_parameter.phpt | 2 +- .../generator/nullable_union_type_return.phpt | 2 +- .../mock-objects/generator/parameter_dnf.phpt | 2 +- .../generator/parameter_false.phpt | 2 +- .../generator/parameter_intersection.phpt | 2 +- .../generator/parameter_null.phpt | 2 +- .../generator/parameter_true.phpt | 2 +- .../generator/parameter_union.phpt | 2 +- .../mock-objects/generator/proxy.phpt | 2 +- .../return_type_declarations_closure.phpt | 2 +- .../return_type_declarations_dnf.phpt | 2 +- .../return_type_declarations_false.phpt | 2 +- .../return_type_declarations_final.phpt | 2 +- .../return_type_declarations_generator.phpt | 2 +- ...return_type_declarations_intersection.phpt | 2 +- .../return_type_declarations_never.phpt | 2 +- .../return_type_declarations_null.phpt | 2 +- .../return_type_declarations_nullable.phpt | 2 +- ...eturn_type_declarations_object_method.phpt | 2 +- .../return_type_declarations_parent.phpt | 2 +- .../return_type_declarations_self.phpt | 2 +- .../return_type_declarations_static.phpt | 2 +- ...eturn_type_declarations_static_method.phpt | 2 +- .../return_type_declarations_true.phpt | 2 +- .../return_type_declarations_union.phpt | 2 +- .../return_type_declarations_void.phpt | 2 +- .../generator/scalar_type_declarations.phpt | 2 +- .../Framework/MockObject/MockObjectTest.php | 2 -- .../MockObject/TestDoubleTestCase.php | 3 -- 70 files changed, 109 insertions(+), 97 deletions(-) create mode 100644 src/Framework/MockObject/Runtime/Api/MutableStubApi.php diff --git a/src/Framework/MockObject/Generator/Generator.php b/src/Framework/MockObject/Generator/Generator.php index 9d0e2dff776..c5cd923e825 100644 --- a/src/Framework/MockObject/Generator/Generator.php +++ b/src/Framework/MockObject/Generator/Generator.php @@ -39,6 +39,7 @@ use function strpos; use function substr; use function trait_exists; +use function version_compare; use Exception; use Iterator; use IteratorAggregate; @@ -54,6 +55,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\MockObjectInternal; +use PHPUnit\Framework\MockObject\MutableStubApi; use PHPUnit\Framework\MockObject\ProxiedCloneMethod; use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\StubApi; @@ -760,7 +762,13 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject, } /** @psalm-var trait-string[] $traits */ - $traits = [StubApi::class]; + $traits = []; + + if (!$isReadonly && version_compare('8.3.0', PHP_VERSION, '>')) { + $traits[] = MutableStubApi::class; + } else { + $traits[] = StubApi::class; + } if ($mockObject) { $traits[] = MockObjectApi::class; diff --git a/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php b/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php index 2c131d51057..c1aae784b53 100644 --- a/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php +++ b/src/Framework/MockObject/Runtime/Api/DoubledCloneMethod.php @@ -9,10 +9,6 @@ */ namespace PHPUnit\Framework\MockObject; -use function version_compare; -use PHPUnit\Event\Code\TestMethodBuilder; -use PHPUnit\Event\Facade as EventFacade; - /** * @internal This trait is not covered by the backward compatibility promise for PHPUnit */ @@ -20,15 +16,6 @@ trait DoubledCloneMethod { public function __clone(): void { - if (version_compare('8.3.0', PHP_VERSION, '>')) { - EventFacade::emitter()->testTriggeredPhpunitError( - TestMethodBuilder::fromCallStack(), - 'Cloning test double objects requires PHP 8.3', - ); - - return; - } - $this->__phpunit_state = clone $this->__phpunit_state; $this->__phpunit_state()->cloneInvocationHandler(); diff --git a/src/Framework/MockObject/Runtime/Api/MutableStubApi.php b/src/Framework/MockObject/Runtime/Api/MutableStubApi.php new file mode 100644 index 00000000000..53686f1634e --- /dev/null +++ b/src/Framework/MockObject/Runtime/Api/MutableStubApi.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Framework\MockObject; + +/** + * @internal This trait is not covered by the backward compatibility promise for PHPUnit + */ +trait MutableStubApi +{ + private TestDoubleState $__phpunit_state; + + public function __phpunit_state(): TestDoubleState + { + return $this->__phpunit_state; + } + + /** @noinspection MagicMethodsValidityInspection */ + public function __phpunit_getInvocationHandler(): InvocationHandler + { + return $this->__phpunit_state->invocationHandler(); + } + + /** @noinspection MagicMethodsValidityInspection */ + public function __phpunit_unsetInvocationMocker(): void + { + $this->__phpunit_state->unsetInvocationHandler(); + } +} diff --git a/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php b/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php index 4e37fc7209c..e573031f4ac 100644 --- a/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php +++ b/src/Framework/MockObject/Runtime/Api/ProxiedCloneMethod.php @@ -9,10 +9,6 @@ */ namespace PHPUnit\Framework\MockObject; -use function version_compare; -use PHPUnit\Event\Code\TestMethodBuilder; -use PHPUnit\Event\Facade as EventFacade; - /** * @internal This trait is not covered by the backward compatibility promise for PHPUnit */ @@ -20,15 +16,6 @@ trait ProxiedCloneMethod { public function __clone(): void { - if (version_compare('8.3.0', PHP_VERSION, '>')) { - EventFacade::emitter()->testTriggeredPhpunitError( - TestMethodBuilder::fromCallStack(), - 'Cloning test double objects requires PHP 8.3', - ); - - return; - } - $this->__phpunit_state = clone $this->__phpunit_state; $this->__phpunit_state()->cloneInvocationHandler(); diff --git a/tests/end-to-end/mock-objects/generator/232.phpt b/tests/end-to-end/mock-objects/generator/232.phpt index 03ddde0d92e..d59ae530146 100644 --- a/tests/end-to-end/mock-objects/generator/232.phpt +++ b/tests/end-to-end/mock-objects/generator/232.phpt @@ -58,7 +58,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt b/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt index 090f60f1342..24dfee4fb52 100644 --- a/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt +++ b/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt @@ -43,7 +43,7 @@ declare(strict_types=1); class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/3967.phpt b/tests/end-to-end/mock-objects/generator/3967.phpt index 3348d603590..2ba1339231e 100644 --- a/tests/end-to-end/mock-objects/generator/3967.phpt +++ b/tests/end-to-end/mock-objects/generator/3967.phpt @@ -26,12 +26,12 @@ $mock = $generator->generate( ); print $mock->classCode(); ---EXPECT-- +--EXPECTF-- declare(strict_types=1); class MockBaz extends Exception implements Baz, PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/397.phpt b/tests/end-to-end/mock-objects/generator/397.phpt index 87d169ba8dc..a4c2619700d 100644 --- a/tests/end-to-end/mock-objects/generator/397.phpt +++ b/tests/end-to-end/mock-objects/generator/397.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockC extends C implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/4139.phpt b/tests/end-to-end/mock-objects/generator/4139.phpt index 8698fa306b7..04caf588fba 100644 --- a/tests/end-to-end/mock-objects/generator/4139.phpt +++ b/tests/end-to-end/mock-objects/generator/4139.phpt @@ -18,7 +18,7 @@ declare(strict_types=1); class %s implements PHPUnit\Framework\MockObject\MockObjectInternal, InterfaceWithConstructor { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/abstract_class.phpt b/tests/end-to-end/mock-objects/generator/abstract_class.phpt index 11c84f79e8b..a1856f71419 100644 --- a/tests/end-to-end/mock-objects/generator/abstract_class.phpt +++ b/tests/end-to-end/mock-objects/generator/abstract_class.phpt @@ -33,7 +33,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class.phpt b/tests/end-to-end/mock-objects/generator/class.phpt index 2e2f0d7874b..b855d4ef5ec 100644 --- a/tests/end-to-end/mock-objects/generator/class.phpt +++ b/tests/end-to-end/mock-objects/generator/class.phpt @@ -33,7 +33,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_call_parent_clone.phpt b/tests/end-to-end/mock-objects/generator/class_call_parent_clone.phpt index 21c6e32bf48..bcabe9d2843 100644 --- a/tests/end-to-end/mock-objects/generator/class_call_parent_clone.phpt +++ b/tests/end-to-end/mock-objects/generator/class_call_parent_clone.phpt @@ -28,7 +28,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/class_call_parent_constructor.phpt index 1b9a017a478..48d06d9a8cf 100644 --- a/tests/end-to-end/mock-objects/generator/class_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/class_call_parent_constructor.phpt @@ -28,7 +28,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_dont_call_parent_clone.phpt b/tests/end-to-end/mock-objects/generator/class_dont_call_parent_clone.phpt index f42a165b7db..46ca8c7724d 100644 --- a/tests/end-to-end/mock-objects/generator/class_dont_call_parent_clone.phpt +++ b/tests/end-to-end/mock-objects/generator/class_dont_call_parent_clone.phpt @@ -28,7 +28,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_dont_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/class_dont_call_parent_constructor.phpt index 1b9a017a478..48d06d9a8cf 100644 --- a/tests/end-to-end/mock-objects/generator/class_dont_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/class_dont_call_parent_constructor.phpt @@ -28,7 +28,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_implementing_interface_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/class_implementing_interface_call_parent_constructor.phpt index 8ec3ad96886..9d1281cacc9 100644 --- a/tests/end-to-end/mock-objects/generator/class_implementing_interface_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/class_implementing_interface_call_parent_constructor.phpt @@ -33,7 +33,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_implementing_interface_dont_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/class_implementing_interface_dont_call_parent_constructor.phpt index 8ec3ad96886..9d1281cacc9 100644 --- a/tests/end-to-end/mock-objects/generator/class_implementing_interface_dont_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/class_implementing_interface_dont_call_parent_constructor.phpt @@ -33,7 +33,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_nonexistent_method.phpt b/tests/end-to-end/mock-objects/generator/class_nonexistent_method.phpt index 7b94c8b34ea..0a4b6e22de4 100644 --- a/tests/end-to-end/mock-objects/generator/class_nonexistent_method.phpt +++ b/tests/end-to-end/mock-objects/generator/class_nonexistent_method.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_partial.phpt b/tests/end-to-end/mock-objects/generator/class_partial.phpt index 5b9ebf428eb..9608e262356 100644 --- a/tests/end-to-end/mock-objects/generator/class_partial.phpt +++ b/tests/end-to-end/mock-objects/generator/class_partial.phpt @@ -33,7 +33,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_with_deprecated_method.phpt b/tests/end-to-end/mock-objects/generator/class_with_deprecated_method.phpt index dad53c92112..d6b0d09986c 100644 --- a/tests/end-to-end/mock-objects/generator/class_with_deprecated_method.phpt +++ b/tests/end-to-end/mock-objects/generator/class_with_deprecated_method.phpt @@ -33,7 +33,7 @@ declare(strict_types=1); class MockFoo extends ClassWithDeprecatedMethod implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_with_final_method.phpt b/tests/end-to-end/mock-objects/generator/class_with_final_method.phpt index ed0763c0258..eb77a418efd 100644 --- a/tests/end-to-end/mock-objects/generator/class_with_final_method.phpt +++ b/tests/end-to-end/mock-objects/generator/class_with_final_method.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends ClassWithFinalMethod implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; 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 index dad34aff72a..99fad68c024 100644 --- 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 @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\DoubledCloneMethod; diff --git a/tests/end-to-end/mock-objects/generator/class_with_method_with_nullable_typehinted_variadic_arguments.phpt b/tests/end-to-end/mock-objects/generator/class_with_method_with_nullable_typehinted_variadic_arguments.phpt index 99d946bc091..d689aee8a68 100644 --- a/tests/end-to-end/mock-objects/generator/class_with_method_with_nullable_typehinted_variadic_arguments.phpt +++ b/tests/end-to-end/mock-objects/generator/class_with_method_with_nullable_typehinted_variadic_arguments.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends ClassWithMethodWithNullableTypehintedVariadicArguments implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_with_method_with_typehinted_variadic_arguments.phpt b/tests/end-to-end/mock-objects/generator/class_with_method_with_typehinted_variadic_arguments.phpt index d34502db55f..ef939db74c1 100644 --- a/tests/end-to-end/mock-objects/generator/class_with_method_with_typehinted_variadic_arguments.phpt +++ b/tests/end-to-end/mock-objects/generator/class_with_method_with_typehinted_variadic_arguments.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends ClassWithMethodWithTypehintedVariadicArguments implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/class_with_method_with_variadic_arguments.phpt b/tests/end-to-end/mock-objects/generator/class_with_method_with_variadic_arguments.phpt index 8f661168dd6..a5ad0eeee73 100644 --- a/tests/end-to-end/mock-objects/generator/class_with_method_with_variadic_arguments.phpt +++ b/tests/end-to-end/mock-objects/generator/class_with_method_with_variadic_arguments.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends ClassWithMethodWithVariadicArguments implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt b/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt index 1c3a8b01965..7ddfc743644 100644 --- a/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt +++ b/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/interface.phpt b/tests/end-to-end/mock-objects/generator/interface.phpt index db45055380b..d6e78304899 100644 --- a/tests/end-to-end/mock-objects/generator/interface.phpt +++ b/tests/end-to-end/mock-objects/generator/interface.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/invocation_object_clone_object.phpt b/tests/end-to-end/mock-objects/generator/invocation_object_clone_object.phpt index ec8193536a1..bf75e92a725 100644 --- a/tests/end-to-end/mock-objects/generator/invocation_object_clone_object.phpt +++ b/tests/end-to-end/mock-objects/generator/invocation_object_clone_object.phpt @@ -34,7 +34,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class.phpt index fffce781aeb..80b3f742388 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class.phpt @@ -35,7 +35,7 @@ declare(strict_types=1); class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_clone.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_clone.phpt index 59286197333..56c061bd5dc 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_clone.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_clone.phpt @@ -30,7 +30,7 @@ declare(strict_types=1); class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_constructor.phpt index 11ade685327..5eae28b476e 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_constructor.phpt @@ -30,7 +30,7 @@ declare(strict_types=1); class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_clone.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_clone.phpt index f503112da54..d76a158590e 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_clone.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_clone.phpt @@ -30,7 +30,7 @@ declare(strict_types=1); class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_constructor.phpt index 11ade685327..5eae28b476e 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_constructor.phpt @@ -30,7 +30,7 @@ declare(strict_types=1); class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_call_parent_constructor.phpt index 840f7733d34..1d716858923 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_call_parent_constructor.phpt @@ -35,7 +35,7 @@ declare(strict_types=1); class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_dont_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_dont_call_parent_constructor.phpt index 840f7733d34..1d716858923 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_dont_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_dont_call_parent_constructor.phpt @@ -35,7 +35,7 @@ declare(strict_types=1); class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_partial.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_partial.phpt index 18207efafc8..5849422422c 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_partial.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_partial.phpt @@ -35,7 +35,7 @@ declare(strict_types=1); class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_interface.phpt b/tests/end-to-end/mock-objects/generator/namespaced_interface.phpt index 63a843a56cc..3df7ddab0df 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_interface.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_interface.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, NS\Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/nonexistent_class.phpt b/tests/end-to-end/mock-objects/generator/nonexistent_class.phpt index a674e6697b8..c3589956d97 100644 --- a/tests/end-to-end/mock-objects/generator/nonexistent_class.phpt +++ b/tests/end-to-end/mock-objects/generator/nonexistent_class.phpt @@ -26,7 +26,7 @@ class NonExistentClass class MockFoo extends NonExistentClass implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace.phpt b/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace.phpt index 4c981d9b713..481bbe8440f 100644 --- a/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace.phpt +++ b/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace.phpt @@ -32,7 +32,7 @@ namespace { class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace_starting_with_separator.phpt b/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace_starting_with_separator.phpt index 0a31e9fc572..688be3c2f33 100644 --- a/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace_starting_with_separator.phpt +++ b/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace_starting_with_separator.phpt @@ -32,7 +32,7 @@ namespace { class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/nullable_types.phpt b/tests/end-to-end/mock-objects/generator/nullable_types.phpt index 99b5ead7d13..d831a0d2c67 100644 --- a/tests/end-to-end/mock-objects/generator/nullable_types.phpt +++ b/tests/end-to-end/mock-objects/generator/nullable_types.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/nullable_union_type_parameter.phpt b/tests/end-to-end/mock-objects/generator/nullable_union_type_parameter.phpt index 6665fff142a..bc181a61911 100644 --- a/tests/end-to-end/mock-objects/generator/nullable_union_type_parameter.phpt +++ b/tests/end-to-end/mock-objects/generator/nullable_union_type_parameter.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/nullable_union_type_return.phpt b/tests/end-to-end/mock-objects/generator/nullable_union_type_return.phpt index 026f32a9034..a92cb119eac 100644 --- a/tests/end-to-end/mock-objects/generator/nullable_union_type_return.phpt +++ b/tests/end-to-end/mock-objects/generator/nullable_union_type_return.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/parameter_dnf.phpt b/tests/end-to-end/mock-objects/generator/parameter_dnf.phpt index 1350cd0a66a..35ba79bdc27 100644 --- a/tests/end-to-end/mock-objects/generator/parameter_dnf.phpt +++ b/tests/end-to-end/mock-objects/generator/parameter_dnf.phpt @@ -37,7 +37,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/parameter_false.phpt b/tests/end-to-end/mock-objects/generator/parameter_false.phpt index bcbb03ce2eb..9f76d1dff26 100644 --- a/tests/end-to-end/mock-objects/generator/parameter_false.phpt +++ b/tests/end-to-end/mock-objects/generator/parameter_false.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/parameter_intersection.phpt b/tests/end-to-end/mock-objects/generator/parameter_intersection.phpt index 43bb3f0af11..aff259a262d 100644 --- a/tests/end-to-end/mock-objects/generator/parameter_intersection.phpt +++ b/tests/end-to-end/mock-objects/generator/parameter_intersection.phpt @@ -37,7 +37,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/parameter_null.phpt b/tests/end-to-end/mock-objects/generator/parameter_null.phpt index 75ed0ba9eec..553b12517e1 100644 --- a/tests/end-to-end/mock-objects/generator/parameter_null.phpt +++ b/tests/end-to-end/mock-objects/generator/parameter_null.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/parameter_true.phpt b/tests/end-to-end/mock-objects/generator/parameter_true.phpt index 26613ce0dd0..07f1ae0ab8f 100644 --- a/tests/end-to-end/mock-objects/generator/parameter_true.phpt +++ b/tests/end-to-end/mock-objects/generator/parameter_true.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/parameter_union.phpt b/tests/end-to-end/mock-objects/generator/parameter_union.phpt index 5b084e65686..f716a1b9eb2 100644 --- a/tests/end-to-end/mock-objects/generator/parameter_union.phpt +++ b/tests/end-to-end/mock-objects/generator/parameter_union.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/proxy.phpt b/tests/end-to-end/mock-objects/generator/proxy.phpt index 360f0b62421..291a43b0839 100644 --- a/tests/end-to-end/mock-objects/generator/proxy.phpt +++ b/tests/end-to-end/mock-objects/generator/proxy.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_closure.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_closure.phpt index 404c3d7a92d..e57b53afe96 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_closure.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_closure.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_dnf.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_dnf.phpt index 3e47f127d30..9610d24e23b 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_dnf.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_dnf.phpt @@ -37,7 +37,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_false.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_false.phpt index b2ea6df804c..033cfbcc56c 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_false.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_false.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_final.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_final.phpt index 18ed55d6566..d8cdfbeed45 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_final.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_final.phpt @@ -34,7 +34,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_generator.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_generator.phpt index cd6d6eab6cb..d530707cd2f 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_generator.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_generator.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_intersection.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_intersection.phpt index 51c3e940885..cd3afcad7ba 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_intersection.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_intersection.phpt @@ -37,7 +37,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_never.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_never.phpt index 6df9510fe62..165958536bf 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_never.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_never.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_null.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_null.phpt index a4be09a2ecf..9d248560b2d 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_null.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_null.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_nullable.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_nullable.phpt index f66e816bc50..72c0305dbc0 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_nullable.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_nullable.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_object_method.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_object_method.phpt index b6cacb4359a..00a866b83fb 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_object_method.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_object_method.phpt @@ -30,7 +30,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_parent.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_parent.phpt index ecbdcaf3034..2b66496867e 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_parent.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_parent.phpt @@ -34,7 +34,7 @@ declare(strict_types=1); class MockBar extends Bar implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_self.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_self.phpt index 46c648c5ed2..ac6a40dafee 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_self.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_self.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_static.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_static.phpt index d9d85fe44bd..0df54517b8f 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_static.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_static.phpt @@ -37,7 +37,7 @@ declare(strict_types=1); class MockClassWithStaticReturnTypes extends ClassWithStaticReturnTypes implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_static_method.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_static_method.phpt index 156026a34e7..0ff838193b1 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_static_method.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_static_method.phpt @@ -30,7 +30,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_true.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_true.phpt index 071335c5a17..1e26dca6cfe 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_true.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_true.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_union.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_union.phpt index 99f0fc58e02..461fcfd8110 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_union.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_union.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_void.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_void.phpt index 08932c0d94d..faa46e75cdf 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_void.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_void.phpt @@ -27,7 +27,7 @@ declare(strict_types=1); class MockFoo implements PHPUnit\Framework\MockObject\MockObjectInternal, Foo { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/end-to-end/mock-objects/generator/scalar_type_declarations.phpt b/tests/end-to-end/mock-objects/generator/scalar_type_declarations.phpt index c3daff546a1..154640d91b1 100644 --- a/tests/end-to-end/mock-objects/generator/scalar_type_declarations.phpt +++ b/tests/end-to-end/mock-objects/generator/scalar_type_declarations.phpt @@ -29,7 +29,7 @@ declare(strict_types=1); class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObjectInternal { - use PHPUnit\Framework\MockObject\StubApi; + use PHPUnit\Framework\MockObject\%SStubApi; use PHPUnit\Framework\MockObject\MockObjectApi; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\Method; diff --git a/tests/unit/Framework/MockObject/MockObjectTest.php b/tests/unit/Framework/MockObject/MockObjectTest.php index f0a1c484d59..14a16b33957 100644 --- a/tests/unit/Framework/MockObject/MockObjectTest.php +++ b/tests/unit/Framework/MockObject/MockObjectTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations; use PHPUnit\Framework\Attributes\Medium; -use PHPUnit\Framework\Attributes\RequiresPhp; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; @@ -444,7 +443,6 @@ public function testWillReturnCallbackWithVariadicVariables(): void $this->assertSame($testData, $actual); } - #[RequiresPhp('8.3')] public function testExpectationsAreClonedWhenTestDoubleIsCloned(): void { $double = $this->createMock(InterfaceWithReturnTypeDeclaration::class); diff --git a/tests/unit/Framework/MockObject/TestDoubleTestCase.php b/tests/unit/Framework/MockObject/TestDoubleTestCase.php index 00e775acdc7..aa4142ab3ac 100644 --- a/tests/unit/Framework/MockObject/TestDoubleTestCase.php +++ b/tests/unit/Framework/MockObject/TestDoubleTestCase.php @@ -11,7 +11,6 @@ use Exception; use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations; -use PHPUnit\Framework\Attributes\RequiresPhp; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; use PHPUnit\TestFixture\MockObject\ExtendableClassWithCloneMethod; @@ -241,7 +240,6 @@ final public function testMethodWithNeverReturnTypeDeclarationThrowsException(): } #[TestDox('Original __clone() method is not called by default when test double object is cloned')] - #[RequiresPhp('8.3')] final public function testOriginalCloneMethodIsNotCalledByDefaultWhenTestDoubleObjectIsCloned(): void { $double = clone $this->createTestDouble(ExtendableClassWithCloneMethod::class); @@ -250,7 +248,6 @@ final public function testOriginalCloneMethodIsNotCalledByDefaultWhenTestDoubleO } #[TestDox('Original __clone() method can optionally be called when test double object is cloned')] - #[RequiresPhp('8.3')] final public function testOriginalCloneMethodCanOptionallyBeCalledWhenTestDoubleObjectIsCloned(): void { $double = $this->getMockBuilder(ExtendableClassWithCloneMethod::class)->enableOriginalClone()->getMock(); From 470417718eaa5edcedfadecad4a8089ded4c5d95 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 10 Apr 2024 18:40:12 +0200 Subject: [PATCH 09/15] Ignore code that is only executed on PHP 8.2 from code coverage --- src/Framework/MockObject/Generator/Generator.php | 2 ++ src/Framework/MockObject/Runtime/Api/MutableStubApi.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Framework/MockObject/Generator/Generator.php b/src/Framework/MockObject/Generator/Generator.php index c5cd923e825..d002c75a1cc 100644 --- a/src/Framework/MockObject/Generator/Generator.php +++ b/src/Framework/MockObject/Generator/Generator.php @@ -765,7 +765,9 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject, $traits = []; if (!$isReadonly && version_compare('8.3.0', PHP_VERSION, '>')) { + // @codeCoverageIgnoreStart $traits[] = MutableStubApi::class; + // @codeCoverageIgnoreEnd } else { $traits[] = StubApi::class; } diff --git a/src/Framework/MockObject/Runtime/Api/MutableStubApi.php b/src/Framework/MockObject/Runtime/Api/MutableStubApi.php index 53686f1634e..e88bf7558f0 100644 --- a/src/Framework/MockObject/Runtime/Api/MutableStubApi.php +++ b/src/Framework/MockObject/Runtime/Api/MutableStubApi.php @@ -11,6 +11,8 @@ /** * @internal This trait is not covered by the backward compatibility promise for PHPUnit + * + * @codeCoverageIgnore */ trait MutableStubApi { From f764ea06ba6c531178d8b7d6781b5f1d1061a891 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 11 Apr 2024 08:07:28 +0200 Subject: [PATCH 10/15] Rename test fixture class --- .../{ReadonlyClass.php => ExtendableReadonlyClass.php} | 2 +- tests/unit/Framework/MockObject/Creation/CreateMockTest.php | 6 +++--- tests/unit/Framework/MockObject/Creation/CreateStubTest.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) rename tests/_files/mock-object/{ReadonlyClass.php => ExtendableReadonlyClass.php} (91%) diff --git a/tests/_files/mock-object/ReadonlyClass.php b/tests/_files/mock-object/ExtendableReadonlyClass.php similarity index 91% rename from tests/_files/mock-object/ReadonlyClass.php rename to tests/_files/mock-object/ExtendableReadonlyClass.php index e968645c547..1a1673ba3ee 100644 --- a/tests/_files/mock-object/ReadonlyClass.php +++ b/tests/_files/mock-object/ExtendableReadonlyClass.php @@ -9,7 +9,7 @@ */ namespace PHPUnit\TestFixture\MockObject; -readonly class ReadonlyClass +readonly class ExtendableReadonlyClass { public function __construct(private mixed $value) { diff --git a/tests/unit/Framework/MockObject/Creation/CreateMockTest.php b/tests/unit/Framework/MockObject/Creation/CreateMockTest.php index 5c480b94d9f..a6f2de64020 100644 --- a/tests/unit/Framework/MockObject/Creation/CreateMockTest.php +++ b/tests/unit/Framework/MockObject/Creation/CreateMockTest.php @@ -19,8 +19,8 @@ use PHPUnit\TestFixture\MockObject\AnInterface; use PHPUnit\TestFixture\MockObject\Enumeration; use PHPUnit\TestFixture\MockObject\ExtendableClass; +use PHPUnit\TestFixture\MockObject\ExtendableReadonlyClass; use PHPUnit\TestFixture\MockObject\FinalClass; -use PHPUnit\TestFixture\MockObject\ReadonlyClass; #[Group('test-doubles')] #[Group('test-doubles/creation')] @@ -49,9 +49,9 @@ public function testCreatesMockObjectForExtendableClass(): void public function testCreatesMockObjectForReadonlyClass(): void { - $double = $this->createMock(ReadonlyClass::class); + $double = $this->createMock(ExtendableReadonlyClass::class); - $this->assertInstanceOf(ReadonlyClass::class, $double); + $this->assertInstanceOf(ExtendableReadonlyClass::class, $double); $this->assertInstanceOf(Stub::class, $double); $this->assertInstanceOf(MockObject::class, $double); } diff --git a/tests/unit/Framework/MockObject/Creation/CreateStubTest.php b/tests/unit/Framework/MockObject/Creation/CreateStubTest.php index 631300236dd..71a5b5d1644 100644 --- a/tests/unit/Framework/MockObject/Creation/CreateStubTest.php +++ b/tests/unit/Framework/MockObject/Creation/CreateStubTest.php @@ -19,8 +19,8 @@ use PHPUnit\TestFixture\MockObject\AnInterface; use PHPUnit\TestFixture\MockObject\Enumeration; use PHPUnit\TestFixture\MockObject\ExtendableClass; +use PHPUnit\TestFixture\MockObject\ExtendableReadonlyClass; use PHPUnit\TestFixture\MockObject\FinalClass; -use PHPUnit\TestFixture\MockObject\ReadonlyClass; #[Group('test-doubles')] #[Group('test-doubles/creation')] @@ -47,9 +47,9 @@ public function testCreatesTestStubForExtendableClass(): void public function testCreatesTestStubForReadonlyClass(): void { - $double = $this->createStub(ReadonlyClass::class); + $double = $this->createStub(ExtendableReadonlyClass::class); - $this->assertInstanceOf(ReadonlyClass::class, $double); + $this->assertInstanceOf(ExtendableReadonlyClass::class, $double); $this->assertInstanceOf(Stub::class, $double); } From 28df31bac13f319606e74fed2922ea9778194104 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 11 Apr 2024 08:18:27 +0200 Subject: [PATCH 11/15] Add tests --- ...ExtendableReadonlyClassWithCloneMethod.php | 28 +++++++++++++++++++ .../MockObject/TestDoubleTestCase.php | 23 +++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/_files/mock-object/ExtendableReadonlyClassWithCloneMethod.php diff --git a/tests/_files/mock-object/ExtendableReadonlyClassWithCloneMethod.php b/tests/_files/mock-object/ExtendableReadonlyClassWithCloneMethod.php new file mode 100644 index 00000000000..5f8d9701c03 --- /dev/null +++ b/tests/_files/mock-object/ExtendableReadonlyClassWithCloneMethod.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture\MockObject; + +use Exception; + +readonly class ExtendableReadonlyClassWithCloneMethod +{ + /** + * @throws Exception + */ + public function __clone(): void + { + throw new Exception(__METHOD__); + } + + public function doSomething(): bool + { + return true; + } +} diff --git a/tests/unit/Framework/MockObject/TestDoubleTestCase.php b/tests/unit/Framework/MockObject/TestDoubleTestCase.php index aa4142ab3ac..1284f7f96bb 100644 --- a/tests/unit/Framework/MockObject/TestDoubleTestCase.php +++ b/tests/unit/Framework/MockObject/TestDoubleTestCase.php @@ -11,9 +11,11 @@ use Exception; use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations; +use PHPUnit\Framework\Attributes\RequiresPhp; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; use PHPUnit\TestFixture\MockObject\ExtendableClassWithCloneMethod; +use PHPUnit\TestFixture\MockObject\ExtendableReadonlyClassWithCloneMethod; use PHPUnit\TestFixture\MockObject\InterfaceWithMethodThatExpectsObject; use PHPUnit\TestFixture\MockObject\InterfaceWithMethodThatHasDefaultParameterValues; use PHPUnit\TestFixture\MockObject\InterfaceWithNeverReturningMethod; @@ -258,6 +260,27 @@ final public function testOriginalCloneMethodCanOptionallyBeCalledWhenTestDouble clone $double; } + #[TestDox('Original __clone() method is not called by default when test double object is cloned (readonly class)')] + #[RequiresPhp('8.3')] + final public function testOriginalCloneMethodIsNotCalledByDefaultWhenTestDoubleObjectOfReadonlyClassIsCloned(): void + { + $double = clone $this->createTestDouble(ExtendableReadonlyClassWithCloneMethod::class); + + $this->assertFalse($double->doSomething()); + } + + #[TestDox('Original __clone() method can optionally be called when test double object is cloned (readonly class)')] + #[RequiresPhp('8.3')] + final public function testOriginalCloneMethodCanOptionallyBeCalledWhenTestDoubleObjectOfReadonlyClassIsCloned(): void + { + $double = $this->getMockBuilder(ExtendableReadonlyClassWithCloneMethod::class)->enableOriginalClone()->getMock(); + + $this->expectException(Exception::class); + $this->expectExceptionMessage(ExtendableReadonlyClassWithCloneMethod::class . '::__clone'); + + clone $double; + } + /** * @psalm-template RealInstanceType of object * From 50a0f3d2d373bad80722f6d5a09711fe2b164b46 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 11 Apr 2024 08:21:54 +0200 Subject: [PATCH 12/15] Ignore execution path that is not interesting from code coverage reporting --- src/Framework/MockObject/Runtime/Api/MockObjectApi.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Framework/MockObject/Runtime/Api/MockObjectApi.php b/src/Framework/MockObject/Runtime/Api/MockObjectApi.php index 192908db93b..837c263cef9 100644 --- a/src/Framework/MockObject/Runtime/Api/MockObjectApi.php +++ b/src/Framework/MockObject/Runtime/Api/MockObjectApi.php @@ -61,8 +61,10 @@ public function expects(InvocationOrder $matcher): InvocationMockerBuilder $this->__phpunit_state()->deprecationWasEmittedFor($test->id()); } + // @codeCoverageIgnoreStart } catch (NoTestCaseObjectOnCallStackException) { EventFacade::emitter()->testRunnerTriggeredDeprecation($message); + // @codeCoverageIgnoreEnd } } From a783a02857580b27ed44db802e39585364332717 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 11 Apr 2024 10:25:01 +0200 Subject: [PATCH 13/15] Document through test that cloning test doubles for readonly classes is not supported on PHP 8.2 --- .../Php82CloneReadonlyTestDoubleTest.php | 23 +++++++++++++ .../mock-objects/clone-readonly-php-82.phpt | 34 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/end-to-end/_files/clone-readonly-php-82/Php82CloneReadonlyTestDoubleTest.php create mode 100644 tests/end-to-end/mock-objects/clone-readonly-php-82.phpt diff --git a/tests/end-to-end/_files/clone-readonly-php-82/Php82CloneReadonlyTestDoubleTest.php b/tests/end-to-end/_files/clone-readonly-php-82/Php82CloneReadonlyTestDoubleTest.php new file mode 100644 index 00000000000..6a75c33ca09 --- /dev/null +++ b/tests/end-to-end/_files/clone-readonly-php-82/Php82CloneReadonlyTestDoubleTest.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture; + +use PHPUnit\Framework\TestCase; +use PHPUnit\TestFixture\MockObject\ExtendableReadonlyClass; + +final class Php82CloneReadonlyTestDoubleTest extends TestCase +{ + public function testOne(): void + { + $stub = $this->createStub(ExtendableReadonlyClass::class); + + clone $stub; + } +} diff --git a/tests/end-to-end/mock-objects/clone-readonly-php-82.phpt b/tests/end-to-end/mock-objects/clone-readonly-php-82.phpt new file mode 100644 index 00000000000..c8c3c463346 --- /dev/null +++ b/tests/end-to-end/mock-objects/clone-readonly-php-82.phpt @@ -0,0 +1,34 @@ +--TEST-- +PHPUnit emits an error when a test double for a readonly class is cloned on PHP 8.2 +--SKIPIF-- +')) { + print 'skip: This test requires PHP 8.2' . PHP_EOL; +} +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s + +E 1 / 1 (100%) + +Time: %s, Memory: %s + +There was 1 error: + +1) PHPUnit\TestFixture\Php82CloneReadonlyTestDoubleTest::testOne +Error: Cannot modify readonly property MockObject_ExtendableReadonlyClass_%s::$__phpunit_state + +%sPhp82CloneReadonlyTestDoubleTest.php:%d + +ERRORS! +Tests: 1, Assertions: 0, Errors: 1. From baec6a0efd95bd2c9be13a8317c8e0be4a94a1b8 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 11 Apr 2024 10:30:34 +0200 Subject: [PATCH 14/15] Make it clear(er) that DoubledCloneMethod and ProxiedCloneMethod are mutually exclusive --- src/Framework/MockObject/Generator/Generator.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Framework/MockObject/Generator/Generator.php b/src/Framework/MockObject/Generator/Generator.php index d002c75a1cc..b91016e91d3 100644 --- a/src/Framework/MockObject/Generator/Generator.php +++ b/src/Framework/MockObject/Generator/Generator.php @@ -806,9 +806,7 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject, if ($doubledCloneMethod) { $traits[] = DoubledCloneMethod::class; - } - - if ($proxiedCloneMethod) { + } elseif ($proxiedCloneMethod) { $traits[] = ProxiedCloneMethod::class; } From b53b04cee70addf1f893b96abf8267e1de4cc08d Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 11 Apr 2024 10:57:39 +0200 Subject: [PATCH 15/15] Throw exception when test double for readonly class is to be cloned on PHP 8.2 --- ...oneTestDoubleForReadonlyClassException.php | 25 +++++++++++++++++++ .../MockObject/Generator/Generator.php | 21 ++++++++++------ .../Runtime/Api/ErrorCloneMethod.php | 23 +++++++++++++++++ .../mock-objects/clone-readonly-php-82.phpt | 2 +- 4 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 src/Framework/MockObject/Exception/CannotCloneTestDoubleForReadonlyClassException.php create mode 100644 src/Framework/MockObject/Runtime/Api/ErrorCloneMethod.php diff --git a/src/Framework/MockObject/Exception/CannotCloneTestDoubleForReadonlyClassException.php b/src/Framework/MockObject/Exception/CannotCloneTestDoubleForReadonlyClassException.php new file mode 100644 index 00000000000..00c0c0b120e --- /dev/null +++ b/src/Framework/MockObject/Exception/CannotCloneTestDoubleForReadonlyClassException.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Framework\MockObject; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + * + * @codeCoverageIgnore + */ +final class CannotCloneTestDoubleForReadonlyClassException extends \PHPUnit\Framework\Exception implements Exception +{ + public function __construct() + { + parent::__construct( + 'Cloning test doubles for readonly classes is not supported on PHP 8.2', + ); + } +} diff --git a/src/Framework/MockObject/Generator/Generator.php b/src/Framework/MockObject/Generator/Generator.php index b91016e91d3..772065a4425 100644 --- a/src/Framework/MockObject/Generator/Generator.php +++ b/src/Framework/MockObject/Generator/Generator.php @@ -39,7 +39,6 @@ use function strpos; use function substr; use function trait_exists; -use function version_compare; use Exception; use Iterator; use IteratorAggregate; @@ -49,6 +48,7 @@ use PHPUnit\Framework\InvalidArgumentException; use PHPUnit\Framework\MockObject\ConfigurableMethod; use PHPUnit\Framework\MockObject\DoubledCloneMethod; +use PHPUnit\Framework\MockObject\ErrorCloneMethod; use PHPUnit\Framework\MockObject\GeneratedAsMockObject; use PHPUnit\Framework\MockObject\GeneratedAsTestStub; use PHPUnit\Framework\MockObject\Method; @@ -762,9 +762,10 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject, } /** @psalm-var trait-string[] $traits */ - $traits = []; + $traits = []; + $isPhp82 = PHP_MAJOR_VERSION === 8 && PHP_MINOR_VERSION === 2; - if (!$isReadonly && version_compare('8.3.0', PHP_VERSION, '>')) { + if (!$isReadonly && $isPhp82) { // @codeCoverageIgnoreStart $traits[] = MutableStubApi::class; // @codeCoverageIgnoreEnd @@ -804,10 +805,16 @@ private function generateCodeForTestDoubleClass(string $type, bool $mockObject, $traits[] = Method::class; } - if ($doubledCloneMethod) { - $traits[] = DoubledCloneMethod::class; - } elseif ($proxiedCloneMethod) { - $traits[] = ProxiedCloneMethod::class; + if ($isPhp82 && $isReadonly) { + // @codeCoverageIgnoreStart + $traits[] = ErrorCloneMethod::class; + // @codeCoverageIgnoreEnd + } else { + if ($doubledCloneMethod) { + $traits[] = DoubledCloneMethod::class; + } elseif ($proxiedCloneMethod) { + $traits[] = ProxiedCloneMethod::class; + } } $useStatements = ''; diff --git a/src/Framework/MockObject/Runtime/Api/ErrorCloneMethod.php b/src/Framework/MockObject/Runtime/Api/ErrorCloneMethod.php new file mode 100644 index 00000000000..ed93e60e295 --- /dev/null +++ b/src/Framework/MockObject/Runtime/Api/ErrorCloneMethod.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Framework\MockObject; + +/** + * @internal This trait is not covered by the backward compatibility promise for PHPUnit + * + * @codeCoverageIgnore + */ +trait ErrorCloneMethod +{ + public function __clone(): void + { + throw new CannotCloneTestDoubleForReadonlyClassException; + } +} diff --git a/tests/end-to-end/mock-objects/clone-readonly-php-82.phpt b/tests/end-to-end/mock-objects/clone-readonly-php-82.phpt index c8c3c463346..a920a46c6bd 100644 --- a/tests/end-to-end/mock-objects/clone-readonly-php-82.phpt +++ b/tests/end-to-end/mock-objects/clone-readonly-php-82.phpt @@ -26,7 +26,7 @@ Time: %s, Memory: %s There was 1 error: 1) PHPUnit\TestFixture\Php82CloneReadonlyTestDoubleTest::testOne -Error: Cannot modify readonly property MockObject_ExtendableReadonlyClass_%s::$__phpunit_state +PHPUnit\Framework\MockObject\CannotCloneTestDoubleForReadonlyClassException: Cloning test doubles for readonly classes is not supported on PHP 8.2 %sPhp82CloneReadonlyTestDoubleTest.php:%d