Skip to content

Commit e90d347

Browse files
[PhpUnitBridge] cleanup implementation of expectException*()
1 parent 5483eef commit e90d347

File tree

1 file changed

+18
-37
lines changed

1 file changed

+18
-37
lines changed

Legacy/ForwardCompatTestTraitForV5.php

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
*/
2020
trait ForwardCompatTestTraitForV5
2121
{
22-
private $forwardCompatExpectedExceptionMessage = '';
23-
private $forwardCompatExpectedExceptionCode = null;
24-
2522
/**
2623
* @return void
2724
*/
@@ -243,11 +240,12 @@ public static function assertIsIterable($actual, $message = '')
243240
*/
244241
public static function assertFinite($actual, $message = '')
245242
{
246-
if (\is_callable('parent::assertFinite')) {
243+
if (method_exists(TestCase::class, 'assertFinite')) {
247244
parent::assertFinite($actual, $message);
248245

249246
return;
250247
}
248+
251249
static::assertInternalType('float', $actual, $message);
252250
static::assertTrue(is_finite($actual), $message ? $message : "Failed asserting that $actual is finite.");
253251
}
@@ -259,11 +257,12 @@ public static function assertFinite($actual, $message = '')
259257
*/
260258
public static function assertInfinite($actual, $message = '')
261259
{
262-
if (\is_callable('parent::assertInfinite')) {
260+
if (method_exists(TestCase::class, 'assertInfinite')) {
263261
parent::assertInfinite($actual, $message);
264262

265263
return;
266264
}
265+
267266
static::assertInternalType('float', $actual, $message);
268267
static::assertTrue(is_infinite($actual), $message ? $message : "Failed asserting that $actual is infinite.");
269268
}
@@ -275,11 +274,12 @@ public static function assertInfinite($actual, $message = '')
275274
*/
276275
public static function assertNan($actual, $message = '')
277276
{
278-
if (\is_callable('parent::assertNan')) {
277+
if (method_exists(TestCase::class, 'assertNan')) {
279278
parent::assertNan($actual, $message);
280279

281280
return;
282281
}
282+
283283
static::assertInternalType('float', $actual, $message);
284284
static::assertTrue(is_nan($actual), $message ? $message : "Failed asserting that $actual is nan.");
285285
}
@@ -297,7 +297,9 @@ public function expectException($exception)
297297
return;
298298
}
299299

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);
301303
}
302304

303305
/**
@@ -311,8 +313,9 @@ public function expectExceptionCode($code)
311313
return;
312314
}
313315

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);
316319
}
317320

318321
/**
@@ -328,8 +331,9 @@ public function expectExceptionMessage($message)
328331
return;
329332
}
330333

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);
333337
}
334338

335339
/**
@@ -345,31 +349,8 @@ public function expectExceptionMessageRegExp($messageRegExp)
345349
return;
346350
}
347351

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);
374355
}
375356
}

0 commit comments

Comments
 (0)