|
9 | 9 | */ |
10 | 10 | namespace PHPUnit\Framework\Constraint; |
11 | 11 |
|
| 12 | +use const PHP_VERSION; |
12 | 13 | use function array_map; |
13 | 14 | use function sprintf; |
| 15 | +use function version_compare; |
14 | 16 | use PHPUnit\Framework\ExpectationFailedException; |
15 | 17 | use PHPUnit\TestFixture\BooleanConstraint; |
16 | 18 | use PHPUnit\TestFixture\CountConstraint; |
@@ -395,7 +397,10 @@ public function testFailureDescriptionWithNativeTransformations(string $input, s |
395 | 397 | $constraint = new $className($operand); |
396 | 398 |
|
397 | 399 | $method = (new ReflectionMethod($className, 'failureDescription')); |
398 | | - $method->setAccessible(true); |
| 400 | + |
| 401 | + if (version_compare(PHP_VERSION, '8.1.0', '<')) { |
| 402 | + $method->setAccessible(true); |
| 403 | + } |
399 | 404 |
|
400 | 405 | $this->assertSame("'whatever' " . $expected, $method->invokeArgs($constraint, ['whatever'])); |
401 | 406 | } |
@@ -427,7 +432,10 @@ public function testFailureDescriptionWithNonContextualTerminalConstraint(): voi |
427 | 432 | ->willReturn($string); |
428 | 433 |
|
429 | 434 | $method = (new ReflectionMethod($className, 'failureDescription')); |
430 | | - $method->setAccessible(true); |
| 435 | + |
| 436 | + if (version_compare(PHP_VERSION, '8.1.0', '<')) { |
| 437 | + $method->setAccessible(true); |
| 438 | + } |
431 | 439 |
|
432 | 440 | $expected = "'whatever' " . $string; |
433 | 441 |
|
@@ -459,7 +467,10 @@ public function testFailureDescriptionWithContextualTerminalConstraint(): void |
459 | 467 | ->method('toString'); |
460 | 468 |
|
461 | 469 | $method = (new ReflectionMethod($className, 'failureDescription')); |
462 | | - $method->setAccessible(true); |
| 470 | + |
| 471 | + if (version_compare(PHP_VERSION, '8.1.0', '<')) { |
| 472 | + $method->setAccessible(true); |
| 473 | + } |
463 | 474 |
|
464 | 475 | $expected = "'whatever' " . $string; |
465 | 476 |
|
@@ -499,7 +510,10 @@ public function testFailureDescriptionWithContextualUnaryOperator(): void |
499 | 510 | ->method('toString'); |
500 | 511 |
|
501 | 512 | $method = (new ReflectionMethod($className, 'failureDescription')); |
502 | | - $method->setAccessible(true); |
| 513 | + |
| 514 | + if (version_compare(PHP_VERSION, '8.1.0', '<')) { |
| 515 | + $method->setAccessible(true); |
| 516 | + } |
503 | 517 |
|
504 | 518 | $expected = "'whatever' " . $string; |
505 | 519 |
|
@@ -543,7 +557,10 @@ public function testFailureDescriptionWithNonContextualBinaryOperatorOfHigherPre |
543 | 557 | ->willReturn($string); |
544 | 558 |
|
545 | 559 | $method = (new ReflectionMethod($className, 'failureDescription')); |
546 | | - $method->setAccessible(true); |
| 560 | + |
| 561 | + if (version_compare(PHP_VERSION, '8.1.0', '<')) { |
| 562 | + $method->setAccessible(true); |
| 563 | + } |
547 | 564 |
|
548 | 565 | $expected = "'whatever' " . $string; |
549 | 566 |
|
@@ -585,7 +602,10 @@ public function testFailureDescriptionWithContextualBinaryOperatorOfHigherPreced |
585 | 602 | ->method('toString'); |
586 | 603 |
|
587 | 604 | $method = (new ReflectionMethod($className, 'failureDescription')); |
588 | | - $method->setAccessible(true); |
| 605 | + |
| 606 | + if (version_compare(PHP_VERSION, '8.1.0', '<')) { |
| 607 | + $method->setAccessible(true); |
| 608 | + } |
589 | 609 |
|
590 | 610 | $expected = "'whatever' " . $string; |
591 | 611 |
|
@@ -627,7 +647,10 @@ public function testFailureDescriptionWithBinaryOperatorOfLowerPrecedence(): voi |
627 | 647 | ->willReturn($string); |
628 | 648 |
|
629 | 649 | $method = (new ReflectionMethod($className, 'failureDescription')); |
630 | | - $method->setAccessible(true); |
| 650 | + |
| 651 | + if (version_compare(PHP_VERSION, '8.1.0', '<')) { |
| 652 | + $method->setAccessible(true); |
| 653 | + } |
631 | 654 |
|
632 | 655 | $expected = $this->getOperatorName() . "( 'whatever' " . $string . ' )'; |
633 | 656 |
|
|
0 commit comments