Skip to content

Commit 93bf190

Browse files
Add test
1 parent 35fe755 commit 93bf190

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
*/
1010
namespace PHPUnit\Framework\MockObject;
1111

12+
use function assert;
13+
use function class_exists;
14+
use function interface_exists;
1215
use function md5;
1316
use function mt_rand;
17+
use function substr;
18+
use function trait_exists;
1419
use PHPUnit\Framework\Attributes\CoversClass;
1520
use PHPUnit\Framework\Attributes\Group;
1621
use PHPUnit\Framework\Attributes\Medium;
@@ -110,4 +115,20 @@ public function testCreatesPartialMockObjectForExtendableClass(): void
110115

111116
$this->assertTrue($double->doSomething());
112117
}
118+
119+
#[TestDox('allowMockingUnknownTypes() can be used to allow mocking of unknown types')]
120+
public function testCreatesMockObjectForUnknownType(): void
121+
{
122+
$type = 'Type_' . substr(md5((string) mt_rand()), 0, 8);
123+
124+
assert(!class_exists($type) && !interface_exists($type) && !trait_exists($type));
125+
126+
$double = $this->getMockBuilder($type)
127+
->allowMockingUnknownTypes()
128+
->getMock();
129+
130+
$this->assertInstanceOf($type, $double);
131+
$this->assertInstanceOf(MockObject::class, $double);
132+
133+
}
113134
}

0 commit comments

Comments
 (0)