Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Apr 26, 2024
1 parent 35fe755 commit 93bf190
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/unit/Framework/MockObject/Creation/MockBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
*/
namespace PHPUnit\Framework\MockObject;

use function assert;
use function class_exists;
use function interface_exists;
use function md5;
use function mt_rand;
use function substr;
use function trait_exists;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Medium;
Expand Down Expand Up @@ -110,4 +115,20 @@ public function testCreatesPartialMockObjectForExtendableClass(): void

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

#[TestDox('allowMockingUnknownTypes() can be used to allow mocking of unknown types')]
public function testCreatesMockObjectForUnknownType(): void
{
$type = 'Type_' . substr(md5((string) mt_rand()), 0, 8);

assert(!class_exists($type) && !interface_exists($type) && !trait_exists($type));

$double = $this->getMockBuilder($type)
->allowMockingUnknownTypes()
->getMock();

$this->assertInstanceOf($type, $double);
$this->assertInstanceOf(MockObject::class, $double);

}
}

0 comments on commit 93bf190

Please sign in to comment.