diff --git a/tests/_files/mock-object/ExtendableClassWithConstructorArguments.php b/tests/_files/mock-object/ExtendableClassWithConstructorArguments.php new file mode 100644 index 00000000000..996151caa75 --- /dev/null +++ b/tests/_files/mock-object/ExtendableClassWithConstructorArguments.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture\MockObject; + +class ExtendableClassWithConstructorArguments +{ + private string $value; + + public function __construct(string $value) + { + $this->value = $value; + } + + public function value(): string + { + return $this->value; + } +} diff --git a/tests/unit/Framework/MockObject/Creation/MockBuilderTest.php b/tests/unit/Framework/MockObject/Creation/MockBuilderTest.php index 84111d36dd1..b3e5f85c6b2 100644 --- a/tests/unit/Framework/MockObject/Creation/MockBuilderTest.php +++ b/tests/unit/Framework/MockObject/Creation/MockBuilderTest.php @@ -29,6 +29,7 @@ use PHPUnit\TestFixture\MockObject\AbstractClass; use PHPUnit\TestFixture\MockObject\ExtendableClass; use PHPUnit\TestFixture\MockObject\ExtendableClassCallingMethodInConstructor; +use PHPUnit\TestFixture\MockObject\ExtendableClassWithConstructorArguments; use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration; use PHPUnit\TestFixture\MockObject\TraitWithConcreteAndAbstractMethod; @@ -65,6 +66,20 @@ public function testCannotCreateMockObjectWithSpecifiedClassNameWhenClassWithTha ->getMock(); } + #[TestDox('setConstructorArgs() can be used to configure constructor arguments for a partially mocked class')] + public function testConstructorArgumentsCanBeConfiguredForPartiallyMockedClass(): void + { + $value = 'string'; + + $double = $this->getMockBuilder(ExtendableClassWithConstructorArguments::class) + ->enableOriginalConstructor() + ->setConstructorArgs([$value]) + ->onlyMethods([]) + ->getMock(); + + $this->assertSame($value, $double->value()); + } + #[IgnorePhpunitDeprecations] #[TestDox('addMethods() can be used to configure an additional method for the mock object class when the original class does not have a method of the same name')] public function testCanCreateMockObjectForExtendableClassWhileAddingMethodsToIt(): void