Skip to content

Commit cbba7be

Browse files
Merge branch '10.5' into 11.1
2 parents 2088e05 + b82007c commit cbba7be

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
use PHPUnit\Framework\Attributes\Group;
1616
use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations;
1717
use PHPUnit\Framework\Attributes\Medium;
18+
use PHPUnit\Framework\Attributes\TestDox;
1819
use PHPUnit\Framework\TestCase;
20+
use PHPUnit\TestFixture\MockObject\AbstractClass;
1921
use PHPUnit\TestFixture\MockObject\ExtendableClass;
2022
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
23+
use PHPUnit\TestFixture\MockObject\TraitWithConcreteAndAbstractMethod;
2124

2225
#[CoversClass(MockBuilder::class)]
2326
#[CoversClass(CannotUseAddMethodsException::class)]
@@ -27,6 +30,7 @@
2730
#[Medium]
2831
final class MockBuilderTest extends TestCase
2932
{
33+
#[TestDox('setMockClassName() can be used to configure the name of the mock object class')]
3034
public function testCanCreateMockObjectWithSpecifiedClassName(): void
3135
{
3236
$className = 'random_' . md5((string) mt_rand());
@@ -39,6 +43,7 @@ public function testCanCreateMockObjectWithSpecifiedClassName(): void
3943
}
4044

4145
#[IgnorePhpunitDeprecations]
46+
#[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')]
4247
public function testCanCreateMockObjectForExtendableClassWhileAddingMethodsToIt(): void
4348
{
4449
$double = $this->getMockBuilder(ExtendableClass::class)
@@ -53,6 +58,7 @@ public function testCanCreateMockObjectForExtendableClassWhileAddingMethodsToIt(
5358
}
5459

5560
#[IgnorePhpunitDeprecations]
61+
#[TestDox('addMethods() cannot be used to configure an additional method for the mock object class when the original class has a method of the same name')]
5662
public function testCannotCreateMockObjectForExtendableClassAddingMethodsToItThatItAlreadyHas(): void
5763
{
5864
$this->expectException(CannotUseAddMethodsException::class);
@@ -61,4 +67,41 @@ public function testCannotCreateMockObjectForExtendableClassAddingMethodsToItTha
6167
->addMethods(['doSomething'])
6268
->getMock();
6369
}
70+
71+
#[IgnorePhpunitDeprecations]
72+
#[TestDox('getMockForAbstractClass() can be used to create a mock object for an abstract class')]
73+
public function testCreatesMockObjectForAbstractClassAndAllowsConfigurationOfAbstractMethods(): void
74+
{
75+
$mock = $this->getMockBuilder(AbstractClass::class)
76+
->getMockForAbstractClass();
77+
78+
$mock->expects($this->once())->method('doSomethingElse')->willReturn(true);
79+
80+
$this->assertTrue($mock->doSomething());
81+
}
82+
83+
#[IgnorePhpunitDeprecations]
84+
#[TestDox('getMockForTrait() can be used to create a mock object for a trait')]
85+
public function testCreatesMockObjectForTraitAndAllowsConfigurationOfMethods(): void
86+
{
87+
$mock = $this->getMockBuilder(TraitWithConcreteAndAbstractMethod::class)
88+
->getMockForTrait();
89+
90+
$mock->method('abstractMethod')->willReturn(true);
91+
92+
$this->assertTrue($mock->concreteMethod());
93+
}
94+
95+
#[IgnorePhpunitDeprecations]
96+
#[TestDox('onlyMethods() can be used to configure which methods should be doubled')]
97+
public function testCreatesPartialMockObjectForExtendableClass(): void
98+
{
99+
$mock = $this->getMockBuilder(ExtendableClass::class)
100+
->onlyMethods(['doSomethingElse'])
101+
->getMock();
102+
103+
$mock->expects($this->once())->method('doSomethingElse')->willReturn(true);
104+
105+
$this->assertTrue($mock->doSomething());
106+
}
64107
}

0 commit comments

Comments
 (0)