File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
unit/Framework/MockObject/Creation Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+ /*
3
+ * This file is part of PHPUnit.
4
+ *
5
+ * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ namespace PHPUnit \TestFixture \MockObject ;
11
+
12
+ class ExtendableClassWithConstructorArguments
13
+ {
14
+ private string $ value ;
15
+
16
+ public function __construct (string $ value )
17
+ {
18
+ $ this ->value = $ value ;
19
+ }
20
+
21
+ public function value (): string
22
+ {
23
+ return $ this ->value ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change 22
22
use PHPUnit \Framework \TestCase ;
23
23
use PHPUnit \TestFixture \MockObject \ExtendableClass ;
24
24
use PHPUnit \TestFixture \MockObject \ExtendableClassCallingMethodInConstructor ;
25
+ use PHPUnit \TestFixture \MockObject \ExtendableClassWithConstructorArguments ;
25
26
use PHPUnit \TestFixture \MockObject \InterfaceWithReturnTypeDeclaration ;
26
27
27
28
#[CoversClass(MockBuilder::class)]
@@ -56,6 +57,20 @@ public function testCannotCreateMockObjectWithSpecifiedClassNameWhenClassWithTha
56
57
->getMock ();
57
58
}
58
59
60
+ #[TestDox('setConstructorArgs() can be used to configure constructor arguments for a partially mocked class ' )]
61
+ public function testConstructorArgumentsCanBeConfiguredForPartiallyMockedClass (): void
62
+ {
63
+ $ value = 'string ' ;
64
+
65
+ $ double = $ this ->getMockBuilder (ExtendableClassWithConstructorArguments::class)
66
+ ->enableOriginalConstructor ()
67
+ ->setConstructorArgs ([$ value ])
68
+ ->onlyMethods ([])
69
+ ->getMock ();
70
+
71
+ $ this ->assertSame ($ value , $ double ->value ());
72
+ }
73
+
59
74
#[TestDox('onlyMethods() can be used to configure which methods should be doubled ' )]
60
75
public function testCreatesPartialMockObjectForExtendableClass (): void
61
76
{
You can’t perform that action at this time.
0 commit comments