From 2e294d5428b05316a910c7cedd1c66dfad781e38 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Fri, 13 Oct 2023 17:35:21 +0200 Subject: [PATCH] Closes #5320 --- ChangeLog-11.0.md | 1 + DEPRECATIONS.md | 2 +- src/Framework/MockObject/MockBuilder.php | 6 ++++++ .../unit/Framework/MockObject/Creation/MockBuilderTest.php | 3 +++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog-11.0.md b/ChangeLog-11.0.md index 20277bfc10c..dc6133f1cbd 100644 --- a/ChangeLog-11.0.md +++ b/ChangeLog-11.0.md @@ -16,6 +16,7 @@ All notable changes of the PHPUnit 11.0 release series are documented in this fi * [#5242](https://github.com/sebastianbergmann/phpunit/issues/5242): `TestCase::getMockFromWsdl()` (this method was already [soft-deprecated](https://phpunit.de/backward-compatibility.html#soft-deprecation) in PHPUnit 10) * [#5243](https://github.com/sebastianbergmann/phpunit/issues/5243): `TestCase::getMockForTrait()` (this method was already [soft-deprecated](https://phpunit.de/backward-compatibility.html#soft-deprecation) in PHPUnit 10) * [#5244](https://github.com/sebastianbergmann/phpunit/issues/5244): `TestCase::getObjectForTrait()` (this method was already [soft-deprecated](https://phpunit.de/backward-compatibility.html#soft-deprecation) in PHPUnit 10) +* [#5320](https://github.com/sebastianbergmann/phpunit/issues/5320): `MockBuilder::addMethods()` (this method was already [soft-deprecated](https://phpunit.de/backward-compatibility.html#soft-deprecation) in PHPUnit 10) * [#5472](https://github.com/sebastianbergmann/phpunit/issues/5472): `assertStringNotMatchesFormat()` and `assertStringNotMatchesFormatFile()` (these methods were already [soft-deprecated](https://phpunit.de/backward-compatibility.html#soft-deprecation) in PHPUnit 10) ### Removed diff --git a/DEPRECATIONS.md b/DEPRECATIONS.md index 7d069da45f2..6943a2364ee 100644 --- a/DEPRECATIONS.md +++ b/DEPRECATIONS.md @@ -21,7 +21,6 @@ This functionality is currently [soft-deprecated](https://phpunit.de/backward-co | [#5309](https://github.com/sebastianbergmann/phpunit/issues/5309) | `MockBuilder::enableAutoload()` | 10.1.0 | | | [#5315](https://github.com/sebastianbergmann/phpunit/issues/5315) | `MockBuilder::disableArgumentCloning()` | 10.1.0 | | | [#5315](https://github.com/sebastianbergmann/phpunit/issues/5315) | `MockBuilder::enableArgumentCloning()` | 10.1.0 | | -| [#5320](https://github.com/sebastianbergmann/phpunit/issues/5320) | `MockBuilder::addMethods()` | 10.1.0 | | | [#5421](https://github.com/sebastianbergmann/phpunit/issues/5421) | `MockBuilder::disableAutoReturnValueGeneration()` | 10.3.0 | | | [#5421](https://github.com/sebastianbergmann/phpunit/issues/5421) | `MockBuilder::enableAutoReturnValueGeneration()` | 10.3.0 | | | [#5423](https://github.com/sebastianbergmann/phpunit/issues/5423) | `TestCase::onConsecutiveCalls()` | 10.3.0 | Use `$double->willReturn()` instead of `$double->will($this->onConsecutiveCalls())` | @@ -87,3 +86,4 @@ This functionality is currently [hard-deprecated](https://phpunit.de/backward-co | [#5242](https://github.com/sebastianbergmann/phpunit/issues/5242) | `TestCase::getMockFromWsdl()` | 10.1.0 | | | [#5243](https://github.com/sebastianbergmann/phpunit/issues/5243) | `TestCase::getMockForTrait()` | 10.1.0 | | | [#5244](https://github.com/sebastianbergmann/phpunit/issues/5244) | `TestCase::getObjectForTrait()` | 10.1.0 | | +| [#5320](https://github.com/sebastianbergmann/phpunit/issues/5320) | `MockBuilder::addMethods()` | 10.1.0 | | diff --git a/src/Framework/MockObject/MockBuilder.php b/src/Framework/MockObject/MockBuilder.php index e5e78c86fe1..0566aecb898 100644 --- a/src/Framework/MockObject/MockBuilder.php +++ b/src/Framework/MockObject/MockBuilder.php @@ -12,6 +12,7 @@ use function array_merge; use function assert; use function trait_exists; +use PHPUnit\Event\Facade as EventFacade; use PHPUnit\Framework\InvalidArgumentException; use PHPUnit\Framework\MockObject\Generator\ClassAlreadyExistsException; use PHPUnit\Framework\MockObject\Generator\ClassIsEnumerationException; @@ -235,6 +236,11 @@ public function onlyMethods(array $methods): self */ public function addMethods(array $methods): self { + EventFacade::emitter()->testTriggeredPhpunitDeprecation( + $this->testCase->valueObjectForEvents(), + 'MockBuilder::addMethods() is deprecated and will be removed in PHPUnit 12. No replacement is/will be provided.', + ); + if (empty($methods)) { $this->emptyMethodsArray = true; diff --git a/tests/unit/Framework/MockObject/Creation/MockBuilderTest.php b/tests/unit/Framework/MockObject/Creation/MockBuilderTest.php index 0b08e4f3dbc..67f8297d947 100644 --- a/tests/unit/Framework/MockObject/Creation/MockBuilderTest.php +++ b/tests/unit/Framework/MockObject/Creation/MockBuilderTest.php @@ -13,6 +13,7 @@ use function mt_rand; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations; use PHPUnit\Framework\Attributes\Medium; use PHPUnit\Framework\TestCase; use PHPUnit\TestFixture\MockObject\ExtendableClass; @@ -37,6 +38,7 @@ public function testCanCreateMockObjectWithSpecifiedClassName(): void $this->assertSame($className, $double::class); } + #[IgnorePhpunitDeprecations] public function testCanCreateMockObjectForExtendableClassWhileAddingMethodsToIt(): void { $double = $this->getMockBuilder(ExtendableClass::class) @@ -50,6 +52,7 @@ public function testCanCreateMockObjectForExtendableClassWhileAddingMethodsToIt( $this->assertSame($value, $double->additionalMethod()); } + #[IgnorePhpunitDeprecations] public function testCannotCreateMockObjectForExtendableClassAddingMethodsToItThatItAlreadyHas(): void { $this->expectException(CannotUseAddMethodsException::class);