diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index 496a943e039..af7fbb3e516 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -30,9 +30,4 @@ \PHPUnit\Framework\TestCase::createTestProxy(0), map([""=>"$0"]) ); - - override( - \PHPUnit\Framework\TestCase::getMockForAbstractClass(0), - map([""=>"$0"]) - ); } diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index dd5fc99a96a..a885f7c5f50 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -1421,50 +1421,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). - * - * @psalm-template RealInstanceType of object - * - * @psalm-param class-string $originalClassName - * - * @psalm-return MockObject&RealInstanceType - * - * @throws InvalidArgumentException - * @throws MockObjectException - * - * @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/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, []); - } -}