Skip to content

Commit d9c43cd

Browse files
Add tests
1 parent 13c6e84 commit d9c43cd

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
use PHPUnit\Framework\Attributes\Group;
1616
use PHPUnit\Framework\Attributes\Medium;
1717
use PHPUnit\Framework\TestCase;
18+
use PHPUnit\TestFixture\MockObject\ExtendableClass;
1819
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
1920

2021
#[CoversClass(MockBuilder::class)]
22+
#[CoversClass(CannotUseAddMethodsException::class)]
2123
#[Group('test-doubles')]
2224
#[Group('test-doubles/creation')]
2325
#[Group('test-doubles/mock-object')]
@@ -34,4 +36,26 @@ public function testCanCreateMockObjectWithSpecifiedClassName(): void
3436

3537
$this->assertSame($className, $double::class);
3638
}
39+
40+
public function testCanCreateMockObjectForExtendableClassWhileAddingMethodsToIt(): void
41+
{
42+
$double = $this->getMockBuilder(ExtendableClass::class)
43+
->addMethods(['additionalMethod'])
44+
->getMock();
45+
46+
$value = 'value';
47+
48+
$double->method('additionalMethod')->willReturn($value);
49+
50+
$this->assertSame($value, $double->additionalMethod());
51+
}
52+
53+
public function testCannotCreateMockObjectForExtendableClassAddingMethodsToItThatItAlreadyHas(): void
54+
{
55+
$this->expectException(CannotUseAddMethodsException::class);
56+
57+
$this->getMockBuilder(ExtendableClass::class)
58+
->addMethods(['doSomething'])
59+
->getMock();
60+
}
3761
}

0 commit comments

Comments
 (0)