diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 6a9cae6cf0d..c4d1e105394 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -1538,45 +1538,6 @@ final protected function getMockFromWsdl(string $wsdlFile, string $originalClass return $mockObject; } - /** - * Creates a mock object for the specified trait with all abstract methods - * of the trait mocked. Concrete methods to mock can be specified with the - * `$mockedMethods` parameter. - * - * @param trait-string $traitName - * @param array $arguments - * @param list $mockedMethods - * - * @throws InvalidArgumentException - * @throws MockObjectException - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5243 - */ - final protected function getMockForTrait(string $traitName, 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(), - 'getMockForTrait() is deprecated and will be removed in PHPUnit 12 without replacement.', - ); - - $mockObject = (new MockGenerator)->mockObjectForTrait( - $traitName, - $arguments, - $mockClassName, - $callOriginalConstructor, - $callOriginalClone, - $callAutoload, - $mockedMethods, - $cloneArguments, - ); - - $this->registerMockObject($mockObject); - - Event\Facade::emitter()->testCreatedMockObjectForTrait($traitName); - - return $mockObject; - } - /** * Creates an object that uses the specified trait. * diff --git a/tests/unit/Framework/MockObject/Creation/GetMockForTraitTest.php b/tests/unit/Framework/MockObject/Creation/GetMockForTraitTest.php deleted file mode 100644 index 92343d0c30b..00000000000 --- a/tests/unit/Framework/MockObject/Creation/GetMockForTraitTest.php +++ /dev/null @@ -1,44 +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\TestDox; -use PHPUnit\Framework\MockObject\Generator\UnknownTraitException; -use PHPUnit\Framework\TestCase; -use PHPUnit\TestFixture\MockObject\TraitWithConcreteAndAbstractMethod; - -#[Group('test-doubles')] -#[Group('test-doubles/creation')] -#[Group('test-doubles/mock-object')] -#[Medium] -#[TestDox('getMockForTrait()')] -#[IgnorePhpunitDeprecations] -final class GetMockForTraitTest extends TestCase -{ - public function testCreatesMockObjectForTraitAndAllowsConfigurationOfAbstractMethods(): void - { - $mock = $this->getMockForTrait(TraitWithConcreteAndAbstractMethod::class); - - $mock->method('abstractMethod')->willReturn(true); - - $this->assertTrue($mock->concreteMethod()); - } - - public function testCannotCreateMockObjectForTraitThatDoesNotExist(): void - { - $this->expectException(UnknownTraitException::class); - $this->expectExceptionMessage('Trait "TraitThatDoesNotExist" does not exist'); - - $this->getMockForTrait('TraitThatDoesNotExist'); - } -}