Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Apr 17, 2024
1 parent 8c7e59b commit b82007c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/unit/Framework/MockObject/Creation/MockBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
use PHPUnit\Framework\Attributes\Medium;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
use PHPUnit\TestFixture\MockObject\AbstractClass;
use PHPUnit\TestFixture\MockObject\ExtendableClass;
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
use PHPUnit\TestFixture\MockObject\TraitWithConcreteAndAbstractMethod;

#[CoversClass(MockBuilder::class)]
#[CoversClass(CannotUseAddMethodsException::class)]
Expand Down Expand Up @@ -62,4 +64,38 @@ public function testCannotCreateMockObjectForExtendableClassAddingMethodsToItTha
->addMethods(['doSomething'])
->getMock();
}

#[TestDox('getMockForAbstractClass() can be used to create a mock object for an abstract class')]
public function testCreatesMockObjectForAbstractClassAndAllowsConfigurationOfAbstractMethods(): void
{
$mock = $this->getMockBuilder(AbstractClass::class)
->getMockForAbstractClass();

$mock->expects($this->once())->method('doSomethingElse')->willReturn(true);

$this->assertTrue($mock->doSomething());
}

#[TestDox('getMockForTrait() can be used to create a mock object for a trait')]
public function testCreatesMockObjectForTraitAndAllowsConfigurationOfMethods(): void
{
$mock = $this->getMockBuilder(TraitWithConcreteAndAbstractMethod::class)
->getMockForTrait();

$mock->method('abstractMethod')->willReturn(true);

$this->assertTrue($mock->concreteMethod());
}

#[TestDox('onlyMethods() can be used to configure which methods should be doubled')]
public function testCreatesPartialMockObjectForExtendableClass(): void
{
$mock = $this->getMockBuilder(ExtendableClass::class)
->onlyMethods(['doSomethingElse'])
->getMock();

$mock->expects($this->once())->method('doSomethingElse')->willReturn(true);

$this->assertTrue($mock->doSomething());
}
}

0 comments on commit b82007c

Please sign in to comment.