19
19
*/
20
20
trait ForwardCompatTestTraitForV5
21
21
{
22
- private $ forwardCompatExpectedExceptionMessage = '' ;
23
- private $ forwardCompatExpectedExceptionCode = null ;
24
-
25
22
/**
26
23
* @return void
27
24
*/
@@ -243,11 +240,12 @@ public static function assertIsIterable($actual, $message = '')
243
240
*/
244
241
public static function assertFinite ($ actual , $ message = '' )
245
242
{
246
- if (\is_callable ( ' parent:: assertFinite ' )) {
243
+ if (method_exists (TestCase::class, ' assertFinite ' )) {
247
244
parent ::assertFinite ($ actual , $ message );
248
245
249
246
return ;
250
247
}
248
+
251
249
static ::assertInternalType ('float ' , $ actual , $ message );
252
250
static ::assertTrue (is_finite ($ actual ), $ message ? $ message : "Failed asserting that $ actual is finite. " );
253
251
}
@@ -259,11 +257,12 @@ public static function assertFinite($actual, $message = '')
259
257
*/
260
258
public static function assertInfinite ($ actual , $ message = '' )
261
259
{
262
- if (\is_callable ( ' parent:: assertInfinite ' )) {
260
+ if (method_exists (TestCase::class, ' assertInfinite ' )) {
263
261
parent ::assertInfinite ($ actual , $ message );
264
262
265
263
return ;
266
264
}
265
+
267
266
static ::assertInternalType ('float ' , $ actual , $ message );
268
267
static ::assertTrue (is_infinite ($ actual ), $ message ? $ message : "Failed asserting that $ actual is infinite. " );
269
268
}
@@ -275,11 +274,12 @@ public static function assertInfinite($actual, $message = '')
275
274
*/
276
275
public static function assertNan ($ actual , $ message = '' )
277
276
{
278
- if (\is_callable ( ' parent:: assertNan ' )) {
277
+ if (method_exists (TestCase::class, ' assertNan ' )) {
279
278
parent ::assertNan ($ actual , $ message );
280
279
281
280
return ;
282
281
}
282
+
283
283
static ::assertInternalType ('float ' , $ actual , $ message );
284
284
static ::assertTrue (is_nan ($ actual ), $ message ? $ message : "Failed asserting that $ actual is nan. " );
285
285
}
@@ -297,7 +297,9 @@ public function expectException($exception)
297
297
return ;
298
298
}
299
299
300
- parent ::setExpectedException ($ exception , $ this ->forwardCompatExpectedExceptionMessage , $ this ->forwardCompatExpectedExceptionCode );
300
+ $ property = new \ReflectionProperty (class_exists ('PHPUnit_Framework_TestCase ' ) ? 'PHPUnit_Framework_TestCase ' : TestCase::class, 'expectedException ' );
301
+ $ property ->setAccessible (true );
302
+ $ property ->setValue ($ this , $ exception );
301
303
}
302
304
303
305
/**
@@ -311,8 +313,9 @@ public function expectExceptionCode($code)
311
313
return ;
312
314
}
313
315
314
- $ this ->forwardCompatExpectedExceptionCode = $ code ;
315
- parent ::setExpectedException (parent ::getExpectedException (), $ this ->forwardCompatExpectedExceptionMessage , $ this ->forwardCompatExpectedExceptionCode );
316
+ $ property = new \ReflectionProperty (class_exists ('PHPUnit_Framework_TestCase ' ) ? 'PHPUnit_Framework_TestCase ' : TestCase::class, 'expectedExceptionCode ' );
317
+ $ property ->setAccessible (true );
318
+ $ property ->setValue ($ this , $ exception );
316
319
}
317
320
318
321
/**
@@ -328,8 +331,9 @@ public function expectExceptionMessage($message)
328
331
return ;
329
332
}
330
333
331
- $ this ->forwardCompatExpectedExceptionMessage = $ message ;
332
- parent ::setExpectedException (parent ::getExpectedException (), $ this ->forwardCompatExpectedExceptionMessage , $ this ->forwardCompatExpectedExceptionCode );
334
+ $ property = new \ReflectionProperty (class_exists ('PHPUnit_Framework_TestCase ' ) ? 'PHPUnit_Framework_TestCase ' : TestCase::class, 'expectedExceptionMessage ' );
335
+ $ property ->setAccessible (true );
336
+ $ property ->setValue ($ this , $ exception );
333
337
}
334
338
335
339
/**
@@ -345,31 +349,8 @@ public function expectExceptionMessageRegExp($messageRegExp)
345
349
return ;
346
350
}
347
351
348
- parent ::setExpectedExceptionRegExp (parent ::getExpectedException (), $ messageRegExp , $ this ->forwardCompatExpectedExceptionCode );
349
- }
350
-
351
- /**
352
- * @param string $exceptionMessage
353
- *
354
- * @return void
355
- */
356
- public function setExpectedException ($ exceptionName , $ exceptionMessage = '' , $ exceptionCode = null )
357
- {
358
- $ this ->forwardCompatExpectedExceptionMessage = $ exceptionMessage ;
359
- $ this ->forwardCompatExpectedExceptionCode = $ exceptionCode ;
360
-
361
- parent ::setExpectedException ($ exceptionName , $ exceptionMessage , $ exceptionCode );
362
- }
363
-
364
- /**
365
- * @param string $exceptionMessageRegExp
366
- *
367
- * @return void
368
- */
369
- public function setExpectedExceptionRegExp ($ exceptionName , $ exceptionMessageRegExp = '' , $ exceptionCode = null )
370
- {
371
- $ this ->forwardCompatExpectedExceptionCode = $ exceptionCode ;
372
-
373
- parent ::setExpectedExceptionRegExp ($ exceptionName , $ exceptionMessageRegExp , $ exceptionCode );
352
+ $ property = new \ReflectionProperty (class_exists ('PHPUnit_Framework_TestCase ' ) ? 'PHPUnit_Framework_TestCase ' : TestCase::class, 'expectedExceptionMessageRegExp ' );
353
+ $ property ->setAccessible (true );
354
+ $ property ->setValue ($ this , $ exception );
374
355
}
375
356
}
0 commit comments