File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
tests/unit/Framework/MockObject/Creation Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 9
9
*/
10
10
namespace PHPUnit \Framework \MockObject ;
11
11
12
+ use function assert ;
13
+ use function class_exists ;
14
+ use function interface_exists ;
12
15
use function md5 ;
13
16
use function mt_rand ;
17
+ use function substr ;
18
+ use function trait_exists ;
14
19
use PHPUnit \Framework \Attributes \CoversClass ;
15
20
use PHPUnit \Framework \Attributes \Group ;
16
21
use PHPUnit \Framework \Attributes \Medium ;
@@ -110,4 +115,20 @@ public function testCreatesPartialMockObjectForExtendableClass(): void
110
115
111
116
$ this ->assertTrue ($ double ->doSomething ());
112
117
}
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
+ }
113
134
}
You can’t perform that action at this time.
0 commit comments