@@ -161,9 +161,8 @@ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, T
161
161
/**
162
162
* @psalm-var array<string,string>
163
163
*/
164
- private array $ iniSettings = [];
165
- private array $ locale = [];
166
- private ?MockGenerator $ mockObjectGenerator = null ;
164
+ private array $ iniSettings = [];
165
+ private array $ locale = [];
167
166
168
167
/**
169
168
* @psalm-var list<MockObjectInternal>
@@ -1169,66 +1168,6 @@ protected function setLocale(mixed ...$arguments): void
1169
1168
}
1170
1169
}
1171
1170
1172
- /**
1173
- * Creates a test stub for the specified interface or class.
1174
- *
1175
- * @psalm-template RealInstanceType of object
1176
- *
1177
- * @psalm-param class-string<RealInstanceType> $originalClassName
1178
- *
1179
- * @psalm-return Stub&RealInstanceType
1180
- *
1181
- * @throws \PHPUnit\Framework\MockObject\Exception
1182
- * @throws InvalidArgumentException
1183
- * @throws NoPreviousThrowableException
1184
- */
1185
- protected function createStub (string $ originalClassName ): Stub
1186
- {
1187
- $ stub = $ this ->createTestDouble ($ originalClassName , false );
1188
-
1189
- Event \Facade::emitter ()->testCreatedStub ($ originalClassName );
1190
-
1191
- return $ stub ;
1192
- }
1193
-
1194
- /**
1195
- * @psalm-param list<class-string> $interfaces
1196
- *
1197
- * @throws \PHPUnit\Framework\MockObject\Exception
1198
- */
1199
- protected function createStubForIntersectionOfInterfaces (array $ interfaces ): Stub
1200
- {
1201
- $ stub = $ this ->mockObjectGenerator ()->getMockForInterfaces ($ interfaces );
1202
-
1203
- Event \Facade::emitter ()->testCreatedStubForIntersectionOfInterfaces ($ interfaces );
1204
-
1205
- return $ stub ;
1206
- }
1207
-
1208
- /**
1209
- * Creates (and configures) a test stub for the specified interface or class.
1210
- *
1211
- * @psalm-template RealInstanceType of object
1212
- *
1213
- * @psalm-param class-string<RealInstanceType> $originalClassName
1214
- *
1215
- * @psalm-return Stub&RealInstanceType
1216
- *
1217
- * @throws \PHPUnit\Framework\MockObject\Exception
1218
- * @throws InvalidArgumentException
1219
- * @throws NoPreviousThrowableException
1220
- */
1221
- final protected function createConfiguredStub (string $ originalClassName , array $ configuration ): Stub
1222
- {
1223
- $ o = $ this ->createStub ($ originalClassName );
1224
-
1225
- foreach ($ configuration as $ method => $ return ) {
1226
- $ o ->method ($ method )->willReturn ($ return );
1227
- }
1228
-
1229
- return $ o ;
1230
- }
1231
-
1232
1171
/**
1233
1172
* Creates a mock object for the specified interface or class.
1234
1173
*
@@ -1244,7 +1183,15 @@ final protected function createConfiguredStub(string $originalClassName, array $
1244
1183
*/
1245
1184
protected function createMock (string $ originalClassName ): MockObject
1246
1185
{
1247
- $ mock = $ this ->createTestDouble ($ originalClassName );
1186
+ $ mock = (new MockGenerator )->getMock (
1187
+ $ originalClassName ,
1188
+ callOriginalConstructor: false ,
1189
+ callOriginalClone: false ,
1190
+ cloneArguments: false ,
1191
+ allowMockingUnknownTypes: false ,
1192
+ );
1193
+
1194
+ $ this ->registerMockObject ($ mock );
1248
1195
1249
1196
Event \Facade::emitter ()->testCreatedMockObject ($ originalClassName );
1250
1197
@@ -1258,7 +1205,7 @@ protected function createMock(string $originalClassName): MockObject
1258
1205
*/
1259
1206
protected function createMockForIntersectionOfInterfaces (array $ interfaces ): MockObject
1260
1207
{
1261
- $ mock = $ this -> mockObjectGenerator ( )->getMockForInterfaces ($ interfaces );
1208
+ $ mock = ( new MockGenerator )->getMockForInterfaces ($ interfaces );
1262
1209
1263
1210
Event \Facade::emitter ()->testCreatedMockObjectForIntersectionOfInterfaces ($ interfaces );
1264
1211
@@ -1368,7 +1315,7 @@ protected function createTestProxy(string $originalClassName, array $constructor
1368
1315
*/
1369
1316
protected function getMockForAbstractClass (string $ originalClassName , array $ arguments = [], string $ mockClassName = '' , bool $ callOriginalConstructor = true , bool $ callOriginalClone = true , bool $ callAutoload = true , array $ mockedMethods = [], bool $ cloneArguments = false ): MockObject
1370
1317
{
1371
- $ mockObject = $ this -> mockObjectGenerator ( )->getMockForAbstractClass (
1318
+ $ mockObject = ( new MockGenerator )->getMockForAbstractClass (
1372
1319
$ originalClassName ,
1373
1320
$ arguments ,
1374
1321
$ mockClassName ,
@@ -1408,7 +1355,7 @@ protected function getMockFromWsdl(string $wsdlFile, string $originalClassName =
1408
1355
1409
1356
if (!class_exists ($ originalClassName )) {
1410
1357
eval (
1411
- $ this -> mockObjectGenerator ( )->generateClassFromWsdl (
1358
+ ( new MockGenerator )->generateClassFromWsdl (
1412
1359
$ wsdlFile ,
1413
1360
$ originalClassName ,
1414
1361
$ methods ,
@@ -1417,7 +1364,7 @@ protected function getMockFromWsdl(string $wsdlFile, string $originalClassName =
1417
1364
);
1418
1365
}
1419
1366
1420
- $ mockObject = $ this -> mockObjectGenerator ( )->getMock (
1367
+ $ mockObject = ( new MockGenerator )->getMock (
1421
1368
$ originalClassName ,
1422
1369
$ methods ,
1423
1370
['' , $ options ],
@@ -1455,7 +1402,7 @@ protected function getMockFromWsdl(string $wsdlFile, string $originalClassName =
1455
1402
*/
1456
1403
protected function getMockForTrait (string $ traitName , array $ arguments = [], string $ mockClassName = '' , bool $ callOriginalConstructor = true , bool $ callOriginalClone = true , bool $ callAutoload = true , array $ mockedMethods = [], bool $ cloneArguments = false ): MockObject
1457
1404
{
1458
- $ mockObject = $ this -> mockObjectGenerator ( )->getMockForTrait (
1405
+ $ mockObject = ( new MockGenerator )->getMockForTrait (
1459
1406
$ traitName ,
1460
1407
$ arguments ,
1461
1408
$ mockClassName ,
@@ -1484,7 +1431,7 @@ protected function getMockForTrait(string $traitName, array $arguments = [], str
1484
1431
*/
1485
1432
protected function getObjectForTrait (string $ traitName , array $ arguments = [], string $ traitClassName = '' , bool $ callOriginalConstructor = true , bool $ callOriginalClone = true , bool $ callAutoload = true ): object
1486
1433
{
1487
- return $ this -> mockObjectGenerator ( )->getObjectForTrait (
1434
+ return ( new MockGenerator )->getObjectForTrait (
1488
1435
$ traitName ,
1489
1436
$ traitClassName ,
1490
1437
$ callAutoload ,
@@ -1660,15 +1607,6 @@ private function markSkippedForMissingDependency(ExecutionOrderDependency $depen
1660
1607
$ this ->status = TestStatus::skipped ($ message );
1661
1608
}
1662
1609
1663
- private function mockObjectGenerator (): MockGenerator
1664
- {
1665
- if ($ this ->mockObjectGenerator === null ) {
1666
- $ this ->mockObjectGenerator = new MockGenerator ;
1667
- }
1668
-
1669
- return $ this ->mockObjectGenerator ;
1670
- }
1671
-
1672
1610
private function startOutputBuffering (): void
1673
1611
{
1674
1612
ob_start ();
@@ -1990,34 +1928,6 @@ private function isCallableTestMethod(string $dependency): bool
1990
1928
);
1991
1929
}
1992
1930
1993
- /**
1994
- * @psalm-template RealInstanceType of object
1995
- *
1996
- * @psalm-param class-string<RealInstanceType> $originalClassName
1997
- *
1998
- * @psalm-return MockObject&RealInstanceType
1999
- *
2000
- * @throws \PHPUnit\Framework\MockObject\Exception
2001
- * @throws InvalidArgumentException
2002
- * @throws NoPreviousThrowableException
2003
- */
2004
- private function createTestDouble (string $ originalClassName , bool $ register = true ): MockObject
2005
- {
2006
- $ testDouble = $ this ->mockObjectGenerator ()->getMock (
2007
- $ originalClassName ,
2008
- callOriginalConstructor: false ,
2009
- callOriginalClone: false ,
2010
- cloneArguments: false ,
2011
- allowMockingUnknownTypes: false ,
2012
- );
2013
-
2014
- if ($ register ) {
2015
- $ this ->registerMockObject ($ testDouble );
2016
- }
2017
-
2018
- return $ testDouble ;
2019
- }
2020
-
2021
1931
/**
2022
1932
* @throws Exception
2023
1933
* @throws ExpectationFailedException
@@ -2273,4 +2183,70 @@ private function isRegisteredFailure(Throwable $t): bool
2273
2183
2274
2184
return false ;
2275
2185
}
2186
+
2187
+ /**
2188
+ * Creates a test stub for the specified interface or class.
2189
+ *
2190
+ * @psalm-template RealInstanceType of object
2191
+ *
2192
+ * @psalm-param class-string<RealInstanceType> $originalClassName
2193
+ *
2194
+ * @psalm-return Stub&RealInstanceType
2195
+ *
2196
+ * @throws \PHPUnit\Framework\MockObject\Exception
2197
+ * @throws InvalidArgumentException
2198
+ * @throws NoPreviousThrowableException
2199
+ */
2200
+ protected static function createStub (string $ originalClassName ): Stub
2201
+ {
2202
+ $ stub = (new MockGenerator )->getMock (
2203
+ $ originalClassName ,
2204
+ callOriginalConstructor: false ,
2205
+ callOriginalClone: false ,
2206
+ cloneArguments: false ,
2207
+ allowMockingUnknownTypes: false ,
2208
+ );
2209
+
2210
+ Event \Facade::emitter ()->testCreatedStub ($ originalClassName );
2211
+
2212
+ return $ stub ;
2213
+ }
2214
+
2215
+ /**
2216
+ * @psalm-param list<class-string> $interfaces
2217
+ *
2218
+ * @throws \PHPUnit\Framework\MockObject\Exception
2219
+ */
2220
+ protected static function createStubForIntersectionOfInterfaces (array $ interfaces ): Stub
2221
+ {
2222
+ $ stub = (new MockGenerator )->getMockForInterfaces ($ interfaces );
2223
+
2224
+ Event \Facade::emitter ()->testCreatedStubForIntersectionOfInterfaces ($ interfaces );
2225
+
2226
+ return $ stub ;
2227
+ }
2228
+
2229
+ /**
2230
+ * Creates (and configures) a test stub for the specified interface or class.
2231
+ *
2232
+ * @psalm-template RealInstanceType of object
2233
+ *
2234
+ * @psalm-param class-string<RealInstanceType> $originalClassName
2235
+ *
2236
+ * @psalm-return Stub&RealInstanceType
2237
+ *
2238
+ * @throws \PHPUnit\Framework\MockObject\Exception
2239
+ * @throws InvalidArgumentException
2240
+ * @throws NoPreviousThrowableException
2241
+ */
2242
+ final protected static function createConfiguredStub (string $ originalClassName , array $ configuration ): Stub
2243
+ {
2244
+ $ o = self ::createStub ($ originalClassName );
2245
+
2246
+ foreach ($ configuration as $ method => $ return ) {
2247
+ $ o ->method ($ method )->willReturn ($ return );
2248
+ }
2249
+
2250
+ return $ o ;
2251
+ }
2276
2252
}
0 commit comments