Skip to content

Commit 89ec9b4

Browse files
authored
Merge pull request #695 from PHPCSStandards/feature/fix-test-runtime-deprecations-php-8.5
PHP 8.5 | TestUtils: prevent deprecation notice for Reflection*::setAccessible()
2 parents c0435a4 + 01eb8b6 commit 89ec9b4

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

PHPCSUtils/TestUtils/ConfigDouble.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private function preventAutoDiscoveryScreenWidth()
211211
public function getStaticConfigProperty($name)
212212
{
213213
$property = new ReflectionProperty('PHP_CodeSniffer\Config', $name);
214-
$property->setAccessible(true);
214+
(\PHP_VERSION_ID < 80100) && $property->setAccessible(true);
215215

216216
if ($name === 'overriddenDefaults' && \version_compare($this->phpcsVersion, '3.99.99', '>')) {
217217
return $property->getValue($this);
@@ -236,14 +236,14 @@ public function getStaticConfigProperty($name)
236236
public function setStaticConfigProperty($name, $value)
237237
{
238238
$property = new ReflectionProperty('PHP_CodeSniffer\Config', $name);
239-
$property->setAccessible(true);
239+
(\PHP_VERSION_ID < 80100) && $property->setAccessible(true);
240240

241241
if ($name === 'overriddenDefaults' && \version_compare($this->phpcsVersion, '3.99.99', '>')) {
242242
$property->setValue($this, $value);
243243
} else {
244244
$property->setValue(null, $value);
245245
}
246246

247-
$property->setAccessible(false);
247+
(\PHP_VERSION_ID < 80100) && $property->setAccessible(false);
248248
}
249249
}

PHPCSUtils/TestUtils/UtilityMethodTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ public static function resetTestFile()
349349
public static function setStaticConfigProperty($name, $value)
350350
{
351351
$property = new ReflectionProperty('PHP_CodeSniffer\Config', $name);
352-
$property->setAccessible(true);
352+
(\PHP_VERSION_ID < 80100) && $property->setAccessible(true);
353353
$property->setValue(null, $value);
354-
$property->setAccessible(false);
354+
(\PHP_VERSION_ID < 80100) && $property->setAccessible(false);
355355
}
356356

357357
/**

Tests/AssertPropertySame.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public static function getObjectPropertyValue($objectUnderTest, $propertyName)
7878
return $objectUnderTest->$propertyName;
7979
}
8080

81-
$property->setAccessible(true);
81+
(\PHP_VERSION_ID < 80100) && $property->setAccessible(true);
8282
$value = $property->getValue($objectUnderTest);
83-
$property->setAccessible(false);
83+
(\PHP_VERSION_ID < 80100) && $property->setAccessible(false);
8484

8585
return $value;
8686
} catch (ReflectionException $e) {

Tests/TestUtils/ConfigDouble/ConfigDoubleTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public function testDestruct()
300300
private function getStaticConfigProperty($name, $config = null)
301301
{
302302
$property = new ReflectionProperty('PHP_CodeSniffer\Config', $name);
303-
$property->setAccessible(true);
303+
(\PHP_VERSION_ID < 80100) && $property->setAccessible(true);
304304

305305
if ($name === 'overriddenDefaults' && \version_compare(Helper::getVersion(), '3.99.99', '>')) {
306306
// The `overriddenDefaults` property is no longer static on PHPCS 4.0+.
@@ -330,8 +330,8 @@ public static function setStaticConfigProperty($name, $value)
330330
}
331331

332332
$property = new ReflectionProperty('PHP_CodeSniffer\Config', $name);
333-
$property->setAccessible(true);
333+
(\PHP_VERSION_ID < 80100) && $property->setAccessible(true);
334334
$property->setValue(null, $value);
335-
$property->setAccessible(false);
335+
(\PHP_VERSION_ID < 80100) && $property->setAccessible(false);
336336
}
337337
}

Tests/TestUtils/UtilityMethodTestCase/ResetTestFileTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function testTearDownCleansUpStaticConfigProperties()
183183
private function getStaticConfigProperty($name, $config = null)
184184
{
185185
$property = new ReflectionProperty('PHP_CodeSniffer\Config', $name);
186-
$property->setAccessible(true);
186+
(\PHP_VERSION_ID < 80100) && $property->setAccessible(true);
187187

188188
if ($name === 'overriddenDefaults'
189189
&& (self::$phpcsVersion === '0' || \version_compare(self::$phpcsVersion, '3.99.99', '>'))

Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ final class PropertyBasedTokenArraysTest extends TestCase
3636
public function testPropertyBasedTokenArrays($name)
3737
{
3838
$reflProp = new ReflectionProperty('PHPCSUtils\Tokens\Collections', $name);
39-
$reflProp->setAccessible(true);
39+
(\PHP_VERSION_ID < 80100) && $reflProp->setAccessible(true);
4040
$expected = $reflProp->getValue();
41-
$reflProp->setAccessible(false);
41+
(\PHP_VERSION_ID < 80100) && $reflProp->setAccessible(false);
4242

4343
$this->assertSame($expected, Collections::$name());
4444
}

0 commit comments

Comments
 (0)