Skip to content

Commit b7e95f5

Browse files
Add test
1 parent 547d314 commit b7e95f5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
use PHPUnit\Framework\Attributes\Group;
1616
use PHPUnit\Framework\Attributes\Medium;
1717
use PHPUnit\Framework\Attributes\TestDox;
18+
use PHPUnit\Framework\MockObject\Generator\ClassAlreadyExistsException;
1819
use PHPUnit\Framework\TestCase;
1920
use PHPUnit\TestFixture\MockObject\AbstractClass;
2021
use PHPUnit\TestFixture\MockObject\ExtendableClass;
2122
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
2223
use PHPUnit\TestFixture\MockObject\TraitWithConcreteAndAbstractMethod;
2324

2425
#[CoversClass(MockBuilder::class)]
26+
#[CoversClass(ClassAlreadyExistsException::class)]
2527
#[CoversClass(CannotUseAddMethodsException::class)]
2628
#[Group('test-doubles')]
2729
#[Group('test-doubles/creation')]
@@ -41,6 +43,16 @@ public function testCanCreateMockObjectWithSpecifiedClassName(): void
4143
$this->assertSame($className, $double::class);
4244
}
4345

46+
#[TestDox('setMockClassName() cannot be used to configure the name of the mock object class when a class with that name already exists')]
47+
public function testCannotCreateMockObjectWithSpecifiedClassNameWhenClassWithThatNameAlreadyExists(): void
48+
{
49+
$this->expectException(ClassAlreadyExistsException::class);
50+
51+
$this->getMockBuilder(InterfaceWithReturnTypeDeclaration::class)
52+
->setMockClassName(__CLASS__)
53+
->getMock();
54+
}
55+
4456
#[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')]
4557
public function testCanCreateMockObjectForExtendableClassWhileAddingMethodsToIt(): void
4658
{

0 commit comments

Comments
 (0)