Skip to content

Commit b82007c

Browse files
Add tests
1 parent 8c7e59b commit b82007c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
use PHPUnit\Framework\Attributes\Medium;
1717
use PHPUnit\Framework\Attributes\TestDox;
1818
use PHPUnit\Framework\TestCase;
19+
use PHPUnit\TestFixture\MockObject\AbstractClass;
1920
use PHPUnit\TestFixture\MockObject\ExtendableClass;
2021
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
22+
use PHPUnit\TestFixture\MockObject\TraitWithConcreteAndAbstractMethod;
2123

2224
#[CoversClass(MockBuilder::class)]
2325
#[CoversClass(CannotUseAddMethodsException::class)]
@@ -62,4 +64,38 @@ public function testCannotCreateMockObjectForExtendableClassAddingMethodsToItTha
6264
->addMethods(['doSomething'])
6365
->getMock();
6466
}
67+
68+
#[TestDox('getMockForAbstractClass() can be used to create a mock object for an abstract class')]
69+
public function testCreatesMockObjectForAbstractClassAndAllowsConfigurationOfAbstractMethods(): void
70+
{
71+
$mock = $this->getMockBuilder(AbstractClass::class)
72+
->getMockForAbstractClass();
73+
74+
$mock->expects($this->once())->method('doSomethingElse')->willReturn(true);
75+
76+
$this->assertTrue($mock->doSomething());
77+
}
78+
79+
#[TestDox('getMockForTrait() can be used to create a mock object for a trait')]
80+
public function testCreatesMockObjectForTraitAndAllowsConfigurationOfMethods(): void
81+
{
82+
$mock = $this->getMockBuilder(TraitWithConcreteAndAbstractMethod::class)
83+
->getMockForTrait();
84+
85+
$mock->method('abstractMethod')->willReturn(true);
86+
87+
$this->assertTrue($mock->concreteMethod());
88+
}
89+
90+
#[TestDox('onlyMethods() can be used to configure which methods should be doubled')]
91+
public function testCreatesPartialMockObjectForExtendableClass(): void
92+
{
93+
$mock = $this->getMockBuilder(ExtendableClass::class)
94+
->onlyMethods(['doSomethingElse'])
95+
->getMock();
96+
97+
$mock->expects($this->once())->method('doSomethingElse')->willReturn(true);
98+
99+
$this->assertTrue($mock->doSomething());
100+
}
65101
}

0 commit comments

Comments
 (0)