Skip to content

Commit 83f47bf

Browse files
committed
PHP 8.5 | Tests: prevent deprecation notice for Reflection*::setAccessible()
Since PHP 8.1, calling the `Reflection*::setAccessible()` methods is no longer necessary as reflected properties/methods/etc will always be accessible. However, the method calls are still needed for PHP < 8.1. As of PHP 8.5, calling the `Reflection*::setAccessible()` methods is now formally deprecated and will yield a deprecation notice, which will fail test runs. As of PHP 9.0, the `setAccessible()` method(s) will be removed. With the latter in mind, this commit prevents the deprecation notice by making the calls to `setAccessible()` conditional. Silencing the deprecation would mean, this would need to be "fixed" again come PHP 9.0, while the current solution should be stable, including for PHP 9.0. Ref: https://wiki.php.net/rfc/deprecations_php_8_5#extreflection_deprecations
1 parent 350c5e7 commit 83f47bf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Tests/FeatureComplete/Config/GetHelpTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ public function testGetHelpWithColors()
130130
$config = new Config(new TestWriter());
131131

132132
$getHelp = new ReflectionMethod($config, 'getHelp');
133-
$getHelp->setAccessible(true);
133+
(\PHP_VERSION_ID < 80100) && $getHelp->setAccessible(true);
134134

135135
$actual = $getHelp->invoke($config);
136136
$actual = \str_replace(["\r\n", "\r"], "\n", $actual);
137137

138138
// Reset to prevent influencing other tests, even if this test would fail.
139-
$getHelp->setAccessible(false);
139+
(\PHP_VERSION_ID < 80100) && $getHelp->setAccessible(false);
140140

141141
$this->assertSame($this->expectedOutputColorized, $actual);
142142
}

0 commit comments

Comments
 (0)