diff --git a/ChangeLog-12.0.md b/ChangeLog-12.0.md index ebc77ac0144..83218dbb11c 100644 --- a/ChangeLog-12.0.md +++ b/ChangeLog-12.0.md @@ -6,6 +6,7 @@ All notable changes of the PHPUnit 12.0 release series are documented in this fi ### Removed +* [#5247](https://github.com/sebastianbergmann/phpunit/issues/5247): `TestCase::getMockForAbstractClass()` * [#5978](https://github.com/sebastianbergmann/phpunit/issues/5978): Support for PHP 8.2 [12.0.0]: https://github.com/sebastianbergmann/phpunit/compare/11.5...main diff --git a/DEPRECATIONS.md b/DEPRECATIONS.md index f30c7f1055c..580dff34a54 100644 --- a/DEPRECATIONS.md +++ b/DEPRECATIONS.md @@ -18,7 +18,6 @@ This functionality is currently [hard-deprecated](https://phpunit.de/backward-co | Issue | Description | Since | Replacement | |-------------------------------------------------------------------|--------------------------------------------------------------------------------|--------|-----------------------------------------------------------------------------------------| | [#5240](https://github.com/sebastianbergmann/phpunit/issues/5240) | `TestCase::createTestProxy()` | 10.1.0 | | -| [#5241](https://github.com/sebastianbergmann/phpunit/issues/5241) | `TestCase::getMockForAbstractClass()` | 10.1.0 | | | [#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 | | diff --git a/src/Event/Emitter/DispatchingEmitter.php b/src/Event/Emitter/DispatchingEmitter.php index 4608c2a4fd7..0e59d6bc4a1 100644 --- a/src/Event/Emitter/DispatchingEmitter.php +++ b/src/Event/Emitter/DispatchingEmitter.php @@ -517,22 +517,6 @@ public function testCreatedMockObjectForTrait(string $traitName): void ); } - /** - * @param class-string $className - * - * @throws InvalidArgumentException - * @throws UnknownEventTypeException - */ - public function testCreatedMockObjectForAbstractClass(string $className): void - { - $this->dispatcher->dispatch( - new Test\MockObjectForAbstractClassCreated( - $this->telemetryInfo(), - $className, - ), - ); - } - /** * @param class-string $originalClassName * @param class-string $mockClassName diff --git a/src/Event/Emitter/Emitter.php b/src/Event/Emitter/Emitter.php index 2c191a8c6ae..e52e8f8ba2c 100644 --- a/src/Event/Emitter/Emitter.php +++ b/src/Event/Emitter/Emitter.php @@ -122,11 +122,6 @@ public function testCreatedMockObjectForIntersectionOfInterfaces(array $interfac */ public function testCreatedMockObjectForTrait(string $traitName): void; - /** - * @param class-string $className - */ - public function testCreatedMockObjectForAbstractClass(string $className): void; - /** * @param class-string $originalClassName * @param class-string $mockClassName diff --git a/src/Event/Events/Test/TestDouble/MockObjectForAbstractClassCreated.php b/src/Event/Events/Test/TestDouble/MockObjectForAbstractClassCreated.php deleted file mode 100644 index 6dcc79a736f..00000000000 --- a/src/Event/Events/Test/TestDouble/MockObjectForAbstractClassCreated.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace PHPUnit\Event\Test; - -use function sprintf; -use PHPUnit\Event\Event; -use PHPUnit\Event\Telemetry; - -/** - * @immutable - * - * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit - */ -final readonly class MockObjectForAbstractClassCreated implements Event -{ - private Telemetry\Info $telemetryInfo; - - /** - * @var class-string - */ - private string $className; - - /** - * @param class-string $className - */ - public function __construct(Telemetry\Info $telemetryInfo, string $className) - { - $this->telemetryInfo = $telemetryInfo; - $this->className = $className; - } - - public function telemetryInfo(): Telemetry\Info - { - return $this->telemetryInfo; - } - - /** - * @return class-string - */ - public function className(): string - { - return $this->className; - } - - public function asString(): string - { - return sprintf( - 'Mock Object Created (%s)', - $this->className, - ); - } -} diff --git a/src/Event/Events/Test/TestDouble/MockObjectForAbstractClassCreatedSubscriber.php b/src/Event/Events/Test/TestDouble/MockObjectForAbstractClassCreatedSubscriber.php deleted file mode 100644 index c335d1917d7..00000000000 --- a/src/Event/Events/Test/TestDouble/MockObjectForAbstractClassCreatedSubscriber.php +++ /dev/null @@ -1,20 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace PHPUnit\Event\Test; - -use PHPUnit\Event\Subscriber; - -/** - * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit - */ -interface MockObjectForAbstractClassCreatedSubscriber extends Subscriber -{ - public function notify(MockObjectForAbstractClassCreated $event): void; -} diff --git a/src/Event/Facade.php b/src/Event/Facade.php index 0f32e117c42..3e590617dc0 100644 --- a/src/Event/Facade.php +++ b/src/Event/Facade.php @@ -209,7 +209,6 @@ private function registerDefaultTypes(TypeMap $typeMap): void Test\WarningTriggered::class, Test\MockObjectCreated::class, - Test\MockObjectForAbstractClassCreated::class, Test\MockObjectForIntersectionOfInterfacesCreated::class, Test\MockObjectForTraitCreated::class, Test\MockObjectFromWsdlCreated::class, diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index d9a2feb3cd7..8e88d9e50b9 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -1478,52 +1478,6 @@ final protected function createTestProxy(string $originalClassName, array $const return $testProxy; } - /** - * Creates a mock object for the specified abstract class with all abstract - * methods of the class mocked. Concrete methods are not mocked by default. - * To mock concrete methods, use the 7th parameter ($mockedMethods). - * - * @template RealInstanceType of object - * - * @param class-string $originalClassName - * @param array $arguments - * @param list $mockedMethods - * - * @throws InvalidArgumentException - * @throws MockObjectException - * - * @return MockObject&RealInstanceType - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5241 - */ - final protected function getMockForAbstractClass(string $originalClassName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = [], bool $cloneArguments = false): MockObject - { - Event\Facade::emitter()->testTriggeredPhpunitDeprecation( - $this->valueObjectForEvents(), - 'getMockForAbstractClass() is deprecated and will be removed in PHPUnit 12 without replacement.', - ); - - $mockObject = (new MockGenerator)->mockObjectForAbstractClass( - $originalClassName, - $arguments, - $mockClassName, - $callOriginalConstructor, - $callOriginalClone, - $callAutoload, - $mockedMethods, - $cloneArguments, - ); - - $this->registerMockObject($mockObject); - - Event\Facade::emitter()->testCreatedMockObjectForAbstractClass($originalClassName); - - assert($mockObject instanceof $originalClassName); - assert($mockObject instanceof MockObject); - - return $mockObject; - } - /** * Creates a mock object based on the given WSDL file. * diff --git a/tests/unit/Event/Emitter/DispatchingEmitterTest.php b/tests/unit/Event/Emitter/DispatchingEmitterTest.php index 2ce6c24b048..6e461481701 100644 --- a/tests/unit/Event/Emitter/DispatchingEmitterTest.php +++ b/tests/unit/Event/Emitter/DispatchingEmitterTest.php @@ -1138,42 +1138,6 @@ public function notify(Test\MockObjectForTraitCreated $event): void $this->assertSame($traitName, $event->traitName()); } - public function testTestMockObjectCreatedForAbstractClassDispatchesTestDoubleMockObjectCreatedForAbstractClassEvent(): void - { - $className = stdClass::class; - - $subscriber = new class extends RecordingSubscriber implements Test\MockObjectForAbstractClassCreatedSubscriber - { - public function notify(Test\MockObjectForAbstractClassCreated $event): void - { - $this->record($event); - } - }; - - $dispatcher = $this->dispatcherWithRegisteredSubscriber( - Test\MockObjectForAbstractClassCreatedSubscriber::class, - Test\MockObjectForAbstractClassCreated::class, - $subscriber, - ); - - $telemetrySystem = $this->telemetrySystem(); - - $emitter = new DispatchingEmitter( - $dispatcher, - $telemetrySystem, - ); - - $emitter->testCreatedMockObjectForAbstractClass($className); - - $this->assertSame(1, $subscriber->recordedEventCount()); - - $event = $subscriber->lastRecordedEvent(); - - $this->assertInstanceOf(Test\MockObjectForAbstractClassCreated::class, $event); - - $this->assertSame($className, $event->className()); - } - public function testTestMockObjectCreatedFromWsdlDispatchesTestDoubleMockObjectCreatedFromWsdlEvent(): void { $wsdlFile = __FILE__; diff --git a/tests/unit/Event/Events/TestDouble/MockObjectForAbstractClassCreatedTest.php b/tests/unit/Event/Events/TestDouble/MockObjectForAbstractClassCreatedTest.php deleted file mode 100644 index cddbfb6b5c6..00000000000 --- a/tests/unit/Event/Events/TestDouble/MockObjectForAbstractClassCreatedTest.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace PHPUnit\Event\Test; - -use PHPUnit\Event\AbstractEventTestCase; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\Small; - -#[CoversClass(MockObjectForAbstractClassCreated::class)] -#[Small] -final class MockObjectForAbstractClassCreatedTest extends AbstractEventTestCase -{ - public function testConstructorSetsValues(): void - { - $telemetryInfo = $this->telemetryInfo(); - $className = 'OriginalType'; - - $event = new MockObjectForAbstractClassCreated( - $telemetryInfo, - $className, - ); - - $this->assertSame($telemetryInfo, $event->telemetryInfo()); - $this->assertSame($className, $event->className()); - } - - public function testCanBeRepresentedAsString(): void - { - $event = new MockObjectForAbstractClassCreated( - $this->telemetryInfo(), - 'OriginalType', - ); - - $this->assertSame('Mock Object Created (OriginalType)', $event->asString()); - } -} diff --git a/tests/unit/Framework/MockObject/Creation/GetMockForAbstractClassTest.php b/tests/unit/Framework/MockObject/Creation/GetMockForAbstractClassTest.php deleted file mode 100644 index 7a545ac808d..00000000000 --- a/tests/unit/Framework/MockObject/Creation/GetMockForAbstractClassTest.php +++ /dev/null @@ -1,69 +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; - -use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations; -use PHPUnit\Framework\Attributes\Medium; -use PHPUnit\Framework\Attributes\RequiresPhpExtension; -use PHPUnit\Framework\Attributes\TestDox; -use PHPUnit\Framework\MockObject\Generator\UnknownClassException; -use PHPUnit\Framework\TestCase; -use PHPUnit\TestFixture\MockObject\AbstractClass; -use ReflectionProperty; - -#[Group('test-doubles')] -#[Group('test-doubles/creation')] -#[Group('test-doubles/mock-object')] -#[Medium] -#[RequiresPhpExtension('soap')] -#[TestDox('getMockForAbstractClass()')] -#[IgnorePhpunitDeprecations] -final class GetMockForAbstractClassTest extends TestCase -{ - public function testCreatesMockObjectForAbstractClassAndAllowsConfigurationOfAbstractMethods(): void - { - $mock = $this->getMockForAbstractClass(AbstractClass::class); - - $mock->expects($this->once())->method('doSomethingElse')->willReturn(true); - - $this->assertTrue($mock->doSomething()); - } - - public function testCannotCreateMockObjectForAbstractClassThatDoesNotExist(): void - { - $this->expectException(UnknownClassException::class); - $this->expectExceptionMessage('Class "DoesNotExist" does not exist'); - - $this->getMockForAbstractClass('DoesNotExist'); - } - - public function testCreatesMockObjectForAbstractClassAndDoesNotAllowConfigurationOfConcreteMethods(): void - { - $mock = $this->getMockForAbstractClass(AbstractClass::class); - - try { - $mock->expects($this->once())->method('doSomething'); - } catch (MethodCannotBeConfiguredException $e) { - $this->assertSame('Trying to configure method "doSomething" which cannot be configured because it does not exist, has not been specified, is final, or is static', $e->getMessage()); - - return; - } finally { - $this->resetMockObjects(); - } - - $this->fail(); - } - - private function resetMockObjects(): void - { - (new ReflectionProperty(TestCase::class, 'mockObjects'))->setValue($this, []); - } -}