1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-10-04 19:51:39 +02:00

[ticket/17543] Remove ReflectionProperty::setAccessible() method calls

As of PHP 8.1.0, calling this method has no effect; all properties
are accessible by default. The method is deprecated since PHP 8.5.

PHPBB-17543
This commit is contained in:
rxu
2025-09-16 22:35:55 +07:00
parent 5336d51f54
commit 9e764b2a98
25 changed files with 0 additions and 53 deletions

View File

@@ -166,13 +166,11 @@ class phpbb_avatar_driver_gravatar_test extends \phpbb_database_test_case
->willReturn([]);
$requestInputReflection = new \ReflectionProperty($request, 'input');
$requestInputReflection->setAccessible(true);
$request_data[request_interface::GET] = $request_data[request_interface::GET] ?? [];
$request_data[request_interface::POST] = $request_data[request_interface::POST] ?? [];
$request_data[request_interface::REQUEST] = $request_data[request_interface::GET] + $request_data[request_interface::POST];
$requestInputReflection->setValue($request, $request_data);
$requestTypeCastHelperReflection = new \ReflectionProperty($request, 'type_cast_helper');
$requestTypeCastHelperReflection->setAccessible(true);
$requestTypeCastHelperReflection->setValue($request, new \phpbb\request\type_cast_helper());
$this->gravatar->prepare_form($request, $this->template, $this->user, $row, $error);

View File

@@ -411,7 +411,6 @@ class ban_manager_test extends \phpbb_session_test_case
$ban_type_ip_reflection = new \ReflectionClass($ban_type_ip);
$get_excluded_reflection = $ban_type_ip_reflection->getMethod('get_excluded');
$get_excluded_reflection->setAccessible(true);
$this->assertFalse($get_excluded_reflection->invoke($ban_type_ip));
}

View File

@@ -68,7 +68,6 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
$filename = "{$this->cache_dir}unreadable.$phpEx";
@chmod($filename, 0000);
$readReflection = new \ReflectionMethod($this->cache_file, '_read');
$readReflection->setAccessible(true);
$this->assertFalse($readReflection->invoke($this->cache_file, 'unreadable'));
@chmod($filename, 0600);
$this->assertNotFalse($readReflection->invoke($this->cache_file, 'unreadable'));
@@ -79,11 +78,9 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
global $phpEx;
$reflectionCacheVars = new \ReflectionProperty($this->cache_file, 'vars');
$reflectionCacheVars->setAccessible(true);
$reflectionCacheVars->setValue($this->cache_file, ['foo' => 'bar']);
$reflectionCacheVarExpires = new \ReflectionProperty($this->cache_file, 'var_expires');
$reflectionCacheVarExpires->setAccessible(true);
$reflectionCacheVarExpires->setValue($this->cache_file, ['foo' => time() + 86400]);
// Create file in invalid format
@@ -95,7 +92,6 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
file_put_contents($filename, $cache_data);
$readReflection = new \ReflectionMethod($this->cache_file, '_read');
$readReflection->setAccessible(true);
$this->assertFalse($readReflection->invoke($this->cache_file, 'data_global'));
}
@@ -104,11 +100,9 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
global $phpEx;
$reflectionCacheVars = new \ReflectionProperty($this->cache_file, 'vars');
$reflectionCacheVars->setAccessible(true);
$reflectionCacheVars->setValue($this->cache_file, ['foo' => 'bar']);
$reflectionCacheVarExpires = new \ReflectionProperty($this->cache_file, 'var_expires');
$reflectionCacheVarExpires->setAccessible(true);
$reflectionCacheVarExpires->setValue($this->cache_file, ['foo' => time() + 86400]);
// Create file in invalid format
@@ -120,7 +114,6 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
file_put_contents($filename, $cache_data);
$readReflection = new \ReflectionMethod($this->cache_file, '_read');
$readReflection->setAccessible(true);
$this->assertFalse($readReflection->invoke($this->cache_file, 'data_global'));
}
@@ -129,11 +122,9 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
global $phpEx;
$reflectionCacheVars = new \ReflectionProperty($this->cache_file, 'vars');
$reflectionCacheVars->setAccessible(true);
$reflectionCacheVars->setValue($this->cache_file, ['foo' => 'bar']);
$reflectionCacheVarExpires = new \ReflectionProperty($this->cache_file, 'var_expires');
$reflectionCacheVarExpires->setAccessible(true);
$reflectionCacheVarExpires->setValue($this->cache_file, ['foo' => time() + 86400]);
// Create file in invalid format
@@ -145,18 +136,15 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
file_put_contents($filename, $cache_data);
$readReflection = new \ReflectionMethod($this->cache_file, '_read');
$readReflection->setAccessible(true);
$this->assertFalse($readReflection->invoke($this->cache_file, 'data_global'));
}
public function test_read_data_global_expired()
{
$reflectionCacheVars = new \ReflectionProperty($this->cache_file, 'vars');
$reflectionCacheVars->setAccessible(true);
$reflectionCacheVars->setValue($this->cache_file, ['foo' => 'bar']);
$reflectionCacheVarExpires = new \ReflectionProperty($this->cache_file, 'var_expires');
$reflectionCacheVarExpires->setAccessible(true);
$reflectionCacheVarExpires->setValue($this->cache_file, ['foo' => time() - 86400]);
// Create file in invalid format
@@ -167,7 +155,6 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
$reflectionCacheVarExpires->setValue($this->cache_file, []);
$readReflection = new \ReflectionMethod($this->cache_file, '_read');
$readReflection->setAccessible(true);
$this->assertTrue($readReflection->invoke($this->cache_file, 'data_global'));
// Check data, should be empty
@@ -177,12 +164,10 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
public function test_read_data_global()
{
$reflectionCacheVars = new \ReflectionProperty($this->cache_file, 'vars');
$reflectionCacheVars->setAccessible(true);
$expectedVars = ['foo' => 'bar'];
$reflectionCacheVars->setValue($this->cache_file, $expectedVars);
$reflectionCacheVarExpires = new \ReflectionProperty($this->cache_file, 'var_expires');
$reflectionCacheVarExpires->setAccessible(true);
$expectedVarExpires = ['foo' => time() + 86400];
$reflectionCacheVarExpires->setValue($this->cache_file, $expectedVarExpires);
@@ -196,7 +181,6 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case
$this->assertEquals([], $reflectionCacheVarExpires->getValue($this->cache_file));
$readReflection = new \ReflectionMethod($this->cache_file, '_read');
$readReflection->setAccessible(true);
$this->assertTrue($readReflection->invoke($this->cache_file, 'data_global'));
// Check data, should be empty

View File

@@ -244,7 +244,6 @@ class phpbb_captcha_turnstile_test extends \phpbb_database_test_case
{
$this->turnstile->set_name('custom_service');
$service_name_property = new \ReflectionProperty($this->turnstile, 'service_name');
$service_name_property->setAccessible(true);
$this->assertEquals('custom_service', $service_name_property->getValue($this->turnstile));
}
@@ -275,7 +274,6 @@ class phpbb_captcha_turnstile_test extends \phpbb_database_test_case
// Use reflection to inject the mocked client into the turnstile class
$reflection = new \ReflectionClass($this->turnstile);
$client_property = $reflection->getProperty('client');
$client_property->setAccessible(true);
$client_property->setValue($this->turnstile, $client_mock);
// Validate that the CAPTCHA was solved successfully
@@ -301,7 +299,6 @@ class phpbb_captcha_turnstile_test extends \phpbb_database_test_case
// Use reflection to inject the mocked client into the turnstile class
$reflection = new \ReflectionClass($this->turnstile);
$client_property = $reflection->getProperty('client');
$client_property->setAccessible(true);
$client_property->setValue($this->turnstile, $client_mock);
// Validatation fails due to guzzle exception
@@ -333,9 +330,7 @@ class phpbb_captcha_turnstile_test extends \phpbb_database_test_case
{
$turnstile_reflection = new \ReflectionClass($this->turnstile);
$get_client_method = $turnstile_reflection->getMethod('get_client');
$get_client_method->setAccessible(true);
$client_property = $turnstile_reflection->getProperty('client');
$client_property->setAccessible(true);
$this->assertFalse($client_property->isInitialized($this->turnstile));
$client = $get_client_method->invoke($this->turnstile);
@@ -363,7 +358,6 @@ class phpbb_captcha_turnstile_test extends \phpbb_database_test_case
// Use reflection to inject the mocked client into the turnstile class
$reflection = new \ReflectionClass($this->turnstile);
$client_property = $reflection->getProperty('client');
$client_property->setAccessible(true);
$client_property->setValue($this->turnstile, $client_mock);
// Validate that the CAPTCHA was not solved
@@ -374,7 +368,6 @@ class phpbb_captcha_turnstile_test extends \phpbb_database_test_case
{
// Mock is_solved to return false
$is_solved_property = new \ReflectionProperty($this->turnstile, 'solved');
$is_solved_property->setAccessible(true);
$is_solved_property->setValue($this->turnstile, false);
// Mock the template assignments

View File

@@ -32,11 +32,9 @@ class phpbb_datetime_from_format_test extends phpbb_test_case
$reflection_class = new ReflectionClass('\phpbb\language\language');
// Set default language files loaded flag to true
$common_language_files_loaded_flag = $reflection_class->getProperty('common_language_files_loaded');
$common_language_files_loaded_flag->setAccessible(true);
$common_language_files_loaded_flag->setValue($this->lang, true);
// Set up test language data
$lang_array = $reflection_class->getProperty('lang');
$lang_array->setAccessible(true);
$lang_array->setValue($this->lang, [
'datetime' => [
'TODAY' => 'Today',

View File

@@ -509,7 +509,6 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
if ($this->tools instanceof \phpbb\db\tools\mssql)
{
$max_length_method = new ReflectionMethod('\phpbb\db\tools\mssql', 'get_max_index_name_length');
$max_length_method->setAccessible(true);
$max_index_length = $max_length_method->invoke($this->tools);
}

View File

@@ -146,7 +146,6 @@ class phpbb_email_parsing_test extends phpbb_test_case
$reflection = new ReflectionObject($this->email);
$this->reflection_template_property = $reflection->getProperty('template');
$this->reflection_template_property->setAccessible(true);
}
public static function email_parsing_data()

View File

@@ -27,7 +27,6 @@ class phpbb_extension_extension_base_test extends phpbb_test_case
$reflection_class = new ReflectionClass('\phpbb\extension\base');
self::$reflection_method_get_migration_file_list = $reflection_class->getMethod('get_migration_file_list');
self::$reflection_method_get_migration_file_list->setAccessible(true);
}
protected function setUp(): void

View File

@@ -146,7 +146,6 @@ class phpbb_files_types_local_test extends phpbb_test_case
'mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser(),
)));
$filespec_local = new ReflectionProperty($filespec, 'local');
$filespec_local->setAccessible(true);
$filespec_local->setValue($filespec, true);
$this->container->set('files.filespec', $filespec);
$this->factory = new \phpbb\files\factory($this->container);

View File

@@ -76,7 +76,6 @@ class phpbb_files_upload_test extends phpbb_test_case
{
$upload = new \phpbb\files\upload($this->factory, $this->language, $this->php_ini, $this->request);
$disallowed_content = new ReflectionProperty($upload, 'disallowed_content');
$disallowed_content->setAccessible(true);
$upload->set_disallowed_content(array('foo'));
$this->assertEquals(array('foo'), $disallowed_content->getValue($upload));

View File

@@ -22,7 +22,6 @@ class phpbb_filesystem_helper_realpath_test extends phpbb_test_case
parent::setUpBeforeClass();
self::$filesystem_helper_phpbb_own_realpath = new ReflectionMethod('\phpbb\filesystem\helper', 'phpbb_own_realpath');
self::$filesystem_helper_phpbb_own_realpath->setAccessible(true);
}
protected function setUp(): void

View File

@@ -24,7 +24,6 @@ class phpbb_filesystem_realpath_test extends phpbb_test_case
$reflection_class = new ReflectionClass('\phpbb\filesystem\filesystem');
self::$filesystem_own_realpath = $reflection_class->getMethod('phpbb_own_realpath');
self::$filesystem_own_realpath->setAccessible(true);
}
protected function setUp(): void

View File

@@ -87,12 +87,10 @@ class phpbb_group_helper_test_case extends phpbb_test_case
// Set default language files loaded flag to true
$loaded_flag = $reflection_class->getProperty('common_language_files_loaded');
$loaded_flag->setAccessible(true);
$loaded_flag->setValue($lang, true);
// Set up test language data
$lang_array = $reflection_class->getProperty('lang');
$lang_array->setAccessible(true);
$lang_array->setValue($lang, $this->get_test_language_data_set());
// Set up event dispatcher

View File

@@ -30,12 +30,10 @@ class phpbb_language_test extends phpbb_test_case
// Set default language files loaded flag to true
$loaded_flag = $reflection_class->getProperty('common_language_files_loaded');
$loaded_flag->setAccessible(true);
$loaded_flag->setValue($this->lang, true);
// Set up test language data
$lang_array = $reflection_class->getProperty('lang');
$lang_array->setAccessible(true);
$lang_array->setValue($this->lang, $this->get_test_data_set());
}

View File

@@ -191,7 +191,6 @@ class phpbb_messenger_queue_test extends phpbb_test_case
$filesystem->method('phpbb_chmod')
->will($this->throwException(new filesystem_exception('Chmod failed')));
$filesystem_reflection = new \ReflectionProperty(queue::class, 'filesystem');
$filesystem_reflection->setAccessible(true);
$filesystem_reflection->setValue($this->messenger_queue, $filesystem);
// Process the queue
@@ -312,7 +311,6 @@ class phpbb_messenger_queue_test extends phpbb_test_case
$filesystem->method('phpbb_chmod')
->will($this->throwException(new filesystem_exception('Chmod failed')));
$filesystem_reflection = new \ReflectionProperty(queue::class, 'filesystem');
$filesystem_reflection->setAccessible(true);
$filesystem_reflection->setValue($this->messenger_queue, $filesystem);
$this->messenger_queue->save();

View File

@@ -137,7 +137,6 @@ class get_callable_from_step_test extends phpbb_database_test_case
{
$class = new ReflectionClass($this->migrator);
$method = $class->getMethod('get_callable_from_step');
$method->setAccessible(true);
return $method->invokeArgs($this->migrator, array($step));
}
}

View File

@@ -126,7 +126,6 @@ class notification_method_email_test extends phpbb_tests_notification_base
$class = new ReflectionClass($notification_method_email);
$empty_queue_method = $class->getMethod('empty_queue');
$empty_queue_method->setAccessible(true);
$this->notification_method_email->method('notify_using_messenger')
->will($this->returnCallback(function () use ($notification_method_email, $empty_queue_method) {

View File

@@ -680,7 +680,6 @@ class notification_method_webpush_test extends phpbb_tests_notification_base
public function test_set_endpoint_padding($endpoint, $expected_padding): void
{
$web_push_reflection = new \ReflectionMethod($this->notification_method_webpush, 'set_endpoint_padding');
$web_push_reflection->setAccessible(true);
$auth = [
'VAPID' => [

View File

@@ -84,7 +84,6 @@ class phpbb_template_extension_test extends phpbb_template_template_test_case
$class = new ReflectionClass('\phpbb\avatar\manager');
$enabled_drivers = $class->getProperty('enabled_drivers');
$enabled_drivers->setAccessible(true);
$enabled_drivers->setValue($class, false);
$avatar_helper = new phpbb\avatar\helper(
$config,

View File

@@ -35,7 +35,6 @@ class phpbb_template_template_test_case extends phpbb_test_case
$reflection = new ReflectionClass('\phpbb\language\language');
self::$language_reflection_lang = $reflection->getProperty('lang');
self::$language_reflection_lang->setAccessible(true);
}
protected function display($handle)

View File

@@ -128,7 +128,6 @@ class twig_test extends \phpbb_test_case
// Get loader instance
$template_reflection = new \ReflectionObject($this->template);
$loader_reflection = $template_reflection->getProperty('loader');
$loader_reflection->setAccessible(true);
/** @var \phpbb\template\twig\loader $loader */
$loader = $loader_reflection->getValue($this->template);

View File

@@ -74,7 +74,6 @@ class phpbb_textreparser_post_text_test extends phpbb_textreparser_test_row_base
// Call reparse_record via reflection
$reparser = $this->get_reparser();
$reparser_reflection = new \ReflectionMethod($reparser, 'reparse_record');
$reparser_reflection->setAccessible(true);
$reparser_reflection->invoke($reparser, $record);
// Retrieve reparsed post text and compare with expectec

View File

@@ -27,7 +27,6 @@ abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_t
$reflection_reparser = new ReflectionClass(get_class($reparser));
$table_property = $reflection_reparser->getProperty('table');
$table_property->setAccessible(true);
$sql = 'SELECT ' . $columns['id'] . ' AS id, ' . $columns['text'] . ' AS text
FROM ' . $table_property->getValue($reparser) . '

View File

@@ -422,7 +422,6 @@ class test_ucp_controller_webpush_test extends phpbb_database_test_case
$this->expectExceptionMessage('FORM_INVALID');
$check_subscribe_reflection = new ReflectionMethod($this->controller, 'check_subscribe_requests');
$check_subscribe_reflection->setAccessible(true);
$check_subscribe_reflection->invoke($this->controller);
}
@@ -436,7 +435,6 @@ class test_ucp_controller_webpush_test extends phpbb_database_test_case
$this->expectExceptionMessage('NO_AUTH_OPERATION');
$check_subscribe_reflection = new ReflectionMethod($this->controller, 'check_subscribe_requests');
$check_subscribe_reflection->setAccessible(true);
$check_subscribe_reflection->invoke($this->controller);
}

View File

@@ -83,7 +83,6 @@ class phpbb_filespec_test extends phpbb_test_case
private function set_reflection_property($class, $property_name, $value)
{
$property = new ReflectionProperty($class, $property_name);
$property->setAccessible(true);
$property->setValue($class, $value);
}
@@ -538,7 +537,6 @@ class phpbb_filespec_test extends phpbb_test_case
$filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper, new \FastImageSize\FastImageSize(), $this->phpbb_root_path, null);
$reflection_filespec = new ReflectionClass($filespec);
$plupload_property = $reflection_filespec->getProperty('plupload');
$plupload_property->setAccessible(true);
$plupload_mock = $this->getMockBuilder('\phpbb\plupload\plupload')
->disableOriginalConstructor()
->getMock();