Skip to content

Commit 5deb4bc

Browse files
Merge branch '11.5'
2 parents f31dd83 + e0542ca commit 5deb4bc

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

tests/unit/Framework/MockObject/Creation/MockBuilderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use PHPUnit\Framework\TestCase;
2323
use PHPUnit\TestFixture\MockObject\ExtendableClass;
2424
use PHPUnit\TestFixture\MockObject\ExtendableClassCallingMethodInConstructor;
25+
use PHPUnit\TestFixture\MockObject\ExtendableClassWithConstructorArguments;
2526
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
2627

2728
#[CoversClass(MockBuilder::class)]
@@ -56,6 +57,20 @@ public function testCannotCreateMockObjectWithSpecifiedClassNameWhenClassWithTha
5657
->getMock();
5758
}
5859

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+
5974
#[TestDox('onlyMethods() can be used to configure which methods should be doubled')]
6075
public function testCreatesPartialMockObjectForExtendableClass(): void
6176
{

0 commit comments

Comments
 (0)