From 58b7a763580609105f394b3bb26c71fcf1ba693b Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 7 Feb 2024 15:48:25 +0100 Subject: [PATCH] Closes #5316 --- src/Framework/MockObject/MockBuilder.php | 43 +------------------ src/Framework/TestCase.php | 1 - .../MockObject/TestDoubleTestCase.php | 14 ------ 3 files changed, 1 insertion(+), 57 deletions(-) diff --git a/src/Framework/MockObject/MockBuilder.php b/src/Framework/MockObject/MockBuilder.php index 684ba074a3b..acfd9dc6db9 100644 --- a/src/Framework/MockObject/MockBuilder.php +++ b/src/Framework/MockObject/MockBuilder.php @@ -55,7 +55,6 @@ final class MockBuilder private bool $originalConstructor = true; private bool $originalClone = true; private bool $autoload = true; - private bool $cloneArguments = false; private bool $callOriginalMethods = false; private ?object $proxyTarget = null; private bool $returnValueGeneration = true; @@ -99,7 +98,7 @@ public function getMock(): MockObject $this->originalConstructor, $this->originalClone, $this->autoload, - $this->cloneArguments, + false, $this->callOriginalMethods, $this->proxyTarget, false, @@ -267,46 +266,6 @@ public function enableAutoload(): self return $this; } - /** - * Disables the cloning of arguments passed to mocked methods. - * - * @return $this - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5315 - */ - public function disableArgumentCloning(): self - { - if (!$this->calledFromTestCase()) { - EventFacade::emitter()->testTriggeredPhpunitDeprecation( - $this->testCase->valueObjectForEvents(), - 'MockBuilder::disableArgumentCloning() is deprecated and will be removed in PHPUnit 12 without replacement.', - ); - } - - $this->cloneArguments = false; - - return $this; - } - - /** - * Enables the cloning of arguments passed to mocked methods. - * - * @return $this - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5315 - */ - public function enableArgumentCloning(): self - { - EventFacade::emitter()->testTriggeredPhpunitDeprecation( - $this->testCase->valueObjectForEvents(), - 'MockBuilder::enableArgumentCloning() is deprecated and will be removed in PHPUnit 12 without replacement.', - ); - - $this->cloneArguments = true; - - return $this; - } - /** * @return $this */ diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 641c979a189..48fe5fa6571 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -1354,7 +1354,6 @@ final protected function createPartialMock(string $originalClassName, array $met $mockBuilder = $this->getMockBuilder($originalClassName) ->disableOriginalConstructor() ->disableOriginalClone() - ->disableArgumentCloning() ->onlyMethods($methods); if (!self::generateReturnValuesForTestDoubles()) { diff --git a/tests/unit/Framework/MockObject/TestDoubleTestCase.php b/tests/unit/Framework/MockObject/TestDoubleTestCase.php index 1284f7f96bb..b7fcc8205f9 100644 --- a/tests/unit/Framework/MockObject/TestDoubleTestCase.php +++ b/tests/unit/Framework/MockObject/TestDoubleTestCase.php @@ -91,20 +91,6 @@ public function testObjectsPassedAsArgumentAreNotClonedByDefault(): void $this->assertSame($object, $double->doSomething($object)); } - #[IgnorePhpunitDeprecations] - public function testCloningOfObjectsPassedAsArgumentCanBeEnabled(): void - { - $object = new stdClass; - - $double = $this->getMockBuilder(InterfaceWithMethodThatExpectsObject::class) - ->enableArgumentCloning() - ->getMock(); - - $double->method('doSomething')->willReturnArgument(0); - - $this->assertNotSame($object, $double->doSomething($object)); - } - final public function testMethodCanBeConfiguredToReturnOneOfItsArguments(): void { $double = $this->createTestDouble(InterfaceWithReturnTypeDeclaration::class);