Skip to content

Commit 0f868b8

Browse files
committed
Tests: avoid setAccessible deprecation warnings
1 parent 14c52a5 commit 0f868b8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tests/phpunit/shared/Private_Access.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ trait Private_Access {
5050
*/
5151
protected function call_private_method( $callback, array $args = [] ) {
5252
$method = ( new ReflectionClass( $callback[0] ) )->getMethod( $callback[1] );
53-
$method->setAccessible( true );
53+
if ( PHP_VERSION_ID < 80100 ) {
54+
$method->setAccessible( true );
55+
}
5456
return $method->invokeArgs( $callback[0], $args );
5557
}
5658

@@ -72,7 +74,9 @@ protected function call_private_method( $callback, array $args = [] ) {
7274
*/
7375
protected function call_private_static_method( $callback, array $args = [] ) {
7476
$method = ( new ReflectionClass( $callback[0] ) )->getMethod( $callback[1] );
75-
$method->setAccessible( true );
77+
if ( PHP_VERSION_ID < 80100 ) {
78+
$method->setAccessible( true );
79+
}
7680
return $method->invokeArgs( null, $args );
7781
}
7882

@@ -88,7 +92,9 @@ protected function call_private_static_method( $callback, array $args = [] ) {
8892
protected function set_private_property( $instance, string $property_name, $value ): void {
8993
$reflection_class = new ReflectionClass( $instance );
9094
$property = $reflection_class->getProperty( $property_name );
91-
$property->setAccessible( true );
95+
if ( PHP_VERSION_ID < 80100 ) {
96+
$property->setAccessible( true );
97+
}
9298

9399
$property->isStatic() ? $reflection_class->setStaticPropertyValue( $property_name, $value ) : $property->setValue( $instance, $value );
94100
}
@@ -104,7 +110,9 @@ protected function set_private_property( $instance, string $property_name, $valu
104110
*/
105111
protected function get_private_property( $instance, string $property_name ) {
106112
$property = ( new ReflectionClass( $instance ) )->getProperty( $property_name );
107-
$property->setAccessible( true );
113+
if ( PHP_VERSION_ID < 80100 ) {
114+
$property->setAccessible( true );
115+
}
108116
return $property->getValue( $instance );
109117
}
110118

0 commit comments

Comments
 (0)