From 361dfe814542e460c4d2da06bd41561403d10b87 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sun, 10 Mar 2024 18:11:25 +0100 Subject: [PATCH] MDL-75952 general: Since php81, refection->setAccessible() is no-op Refereces: - https://wiki.php.net/rfc/make-reflection-setaccessible-no-op - https://www.php.net/manual/en/reflectionproperty.setaccessible.php - https://www.php.net/manual/en/reflectionmethod.setaccessible.php As of PHP 8.1.0, calling this method has no effect; all methods are invokable by default. So, let's remove all uses from core, they are no-op. --- admin/presets/tests/generator/lib.php | 2 -- .../tests/expired_contexts_test.php | 2 -- .../tests/filtered_userlist_test.php | 1 - admin/tool/langimport/tests/locale_test.php | 1 - .../tool/licensemanager/tests/manager_test.php | 5 ----- .../mfa/factor/email/tests/factor_test.php | 2 -- .../tool/mfa/factor/sms/tests/factor_test.php | 1 - .../mfa/factor/token/tests/factor_test.php | 5 ----- admin/tool/mfa/tests/secret_manager_test.php | 5 ----- admin/tool/usertours/tests/manager_test.php | 2 -- admin/tool/usertours/tests/step_test.php | 15 --------------- admin/tool/usertours/tests/tour_test.php | 16 ---------------- ...nity_of_inquiry_activities_completed_by.php | 3 --- analytics/tests/model_test.php | 1 - backup/moodle2/tests/backup_stepslib_test.php | 1 - .../restore_gradebook_structure_step_test.php | 1 - backup/tests/automated_backup_test.php | 9 --------- backup/util/dbops/tests/restore_dbops_test.php | 1 - .../helper/tests/restore_log_rule_test.php | 2 -- badges/tests/badgeslib_test.php | 3 --- .../output/manage_badge_action_bar_test.php | 1 - .../tests/accessibility_review_test.php | 3 --- blog/tests/lib_test.php | 3 --- cache/stores/redis/lib.php | 1 - cache/tests/cache_test.php | 4 ---- .../tests/calendar_event_exporter_test.php | 2 -- calendar/tests/rrule_manager_test.php | 1 - .../matrix/tests/local/command_test.php | 1 - .../matrix/tests/matrix_client_test.php | 1 - contentbank/tests/contentbank_test.php | 2 -- course/format/tests/local/baseactions_test.php | 1 - course/tests/category_hooks_test.php | 1 - course/tests/course_image_cache_test.php | 5 ----- course/tests/targets_test.php | 7 ------- customfield/tests/generator/lib.php | 1 - enrol/ldap/tests/ldap_test.php | 1 - enrol/lti/tests/helper_test.php | 2 -- files/tests/converter_test.php | 10 ---------- grade/report/user/tests/lib_test.php | 2 -- h5p/tests/editor_test.php | 7 ------- h5p/tests/file_storage_test.php | 4 ---- h5p/tests/generator/lib.php | 1 - lib/behat/classes/named_selector.php | 2 -- lib/classes/scss.php | 1 - lib/ddl/tests/ddl_test.php | 2 -- lib/dml/tests/dml_mysqli_read_slave_test.php | 1 - lib/dml/tests/dml_test.php | 15 +++++++-------- .../test_dml_sql_debugging_fixture.php | 1 - .../fixtures/test_moodle_read_slave_trait.php | 1 - .../mysqli_native_moodle_database_test.php | 1 - .../pgsql_native_moodle_database_test.php | 2 -- .../sqlsrv_native_moodle_database_test.php | 3 --- lib/external/tests/external_api_test.php | 1 - .../tests/file_system_filedir_test.php | 14 -------------- lib/filestorage/tests/file_system_test.php | 9 --------- lib/phpunit/classes/util.php | 1 - lib/phpunit/tests/phpunit_dataset_test.php | 18 ------------------ lib/tests/accesslib_test.php | 5 ----- lib/tests/analysers_test.php | 3 --- lib/tests/client_test.php | 1 - lib/tests/completionlib_test.php | 3 --- lib/tests/component_test.php | 6 ------ .../core_renderer_template_exploit_test.php | 1 - .../check/get_result_admintree_test.php | 1 - lib/tests/filelib_test.php | 3 --- lib/tests/filestorage_zip_archive_test.php | 1 - lib/tests/http_client_test.php | 2 -- lib/tests/medialib_test.php | 1 - lib/tests/moodlenet/activity_packager_test.php | 3 --- lib/tests/moodlenet/activity_sender_test.php | 2 -- lib/tests/moodlenet/course_packager_test.php | 3 --- .../moodlenet/course_partial_packager_test.php | 2 -- .../moodlenet/course_partial_sender_test.php | 2 -- lib/tests/moodlenet/course_sender_test.php | 2 -- lib/tests/myprofilelib_test.php | 12 ------------ lib/tests/navigation/output/primary_test.php | 3 --- lib/tests/navigation/views/primary_test.php | 1 - lib/tests/navigation/views/secondary_test.php | 8 -------- lib/tests/output/language_menu_test.php | 1 - .../output/participants_action_bar_test.php | 1 - lib/tests/outputrequirementslib_test.php | 3 --- lib/tests/session_manager_test.php | 1 - lib/tests/session_redis_test.php | 1 - lib/tests/setuplib_test.php | 2 -- lib/tests/xhprof_test.php | 2 -- .../editpdf/tests/document_services_test.php | 2 -- mod/assign/tests/downloader_test.php | 1 - .../tests/locallib_participants_test.php | 1 - mod/assign/tests/locallib_test.php | 1 - .../test/subplugins_test_helper_trait.php | 7 ------- .../tests/behat/behat_mod_bigbluebuttonbn.php | 2 -- mod/bigbluebuttonbn/tests/instance_test.php | 1 - mod/bigbluebuttonbn/tests/lib_test.php | 1 - .../tests/local/extension_test.php | 1 - .../tests/local/proxy/proxy_base_test.php | 1 - .../tests/task/base_send_notification_test.php | 1 - mod/data/lib.php | 1 - mod/data/tests/preset_test.php | 1 - mod/feedback/tests/item_test.php | 1 - mod/forum/tests/lib_test.php | 3 --- .../tests/output/result/result_test.php | 2 -- mod/h5pactivity/tests/xapi/handler_test.php | 1 - .../seb/tests/access_manager_test.php | 1 - mod/quiz/accessrule/seb/tests/rule_test.php | 7 ------- .../adminpresets_review_setting.php | 1 - mod/quiz/report/overview/tests/report_test.php | 1 - .../tests/quiz_statistics_report_test.php | 1 - .../statistics/tests/statistics_table_test.php | 3 --- .../tests/local_structure_slot_random_test.php | 4 ---- .../tests/scheduled_allocator_test.php | 1 - mod/workshop/tests/locallib_test.php | 1 - mod/workshop/tests/portfolio_caller_test.php | 1 - notes/tests/lib_test.php | 3 --- privacy/tests/contextlist_test.php | 1 - privacy/tests/moodle_content_writer_test.php | 2 -- question/bank/statistics/tests/helper_test.php | 3 --- question/engine/tests/datalib_test.php | 1 - question/engine/tests/question_engine_test.php | 1 - .../statistics/statistics_bulk_loader_test.php | 3 --- question/tests/version_test.php | 1 - .../type/ddwtos/tests/form/edit_form_test.php | 1 - .../gapselect/tests/form/edit_form_test.php | 1 - .../numerical/tests/answerprocessor_test.php | 1 - report/log/tests/lib_test.php | 2 -- report/outline/tests/lib_test.php | 2 -- report/stats/tests/lib_test.php | 3 --- report/usersessions/tests/lib_test.php | 4 ---- reportbuilder/tests/datasource_test.php | 4 ---- reportbuilder/tests/local/report/base_test.php | 3 --- repository/dropbox/tests/api_test.php | 6 ------ .../access_controlled_link_manager_test.php | 2 -- repository/nextcloud/tests/lib_test.php | 3 --- theme/boost/tests/boostnavbar_test.php | 6 ------ webservice/rest/tests/server_test.php | 1 - 134 files changed, 7 insertions(+), 383 deletions(-) diff --git a/admin/presets/tests/generator/lib.php b/admin/presets/tests/generator/lib.php index b5a385c752a..8d6ffc9385d 100644 --- a/admin/presets/tests/generator/lib.php +++ b/admin/presets/tests/generator/lib.php @@ -227,7 +227,6 @@ class core_adminpresets_generator extends \component_generator_base { public function access_protected($object, string $property) { $reflection = new ReflectionClass($object); $property = $reflection->getProperty($property); - $property->setAccessible(true); return $property->getValue($object); } @@ -244,7 +243,6 @@ class core_adminpresets_generator extends \component_generator_base { // Set method accessibility. $method = new ReflectionMethod(manager::class, 'get_setting'); - $method->setAccessible(true); // Get the proper adminpresets_setting instance. $settingpage = $adminroot->locate($category); diff --git a/admin/tool/dataprivacy/tests/expired_contexts_test.php b/admin/tool/dataprivacy/tests/expired_contexts_test.php index abd8d997d6d..ae50fbf2510 100644 --- a/admin/tool/dataprivacy/tests/expired_contexts_test.php +++ b/admin/tool/dataprivacy/tests/expired_contexts_test.php @@ -2079,7 +2079,6 @@ class expired_contexts_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_dataprivacy\expired_contexts_manager::class); $rcm = $rc->getMethod('get_progress'); - $rcm->setAccessible(true); $this->assertInstanceOf(\text_progress_trace::class, $rcm->invoke($manager)); } @@ -2094,7 +2093,6 @@ class expired_contexts_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_dataprivacy\expired_contexts_manager::class); $rcm = $rc->getMethod('get_progress'); - $rcm->setAccessible(true); $this->assertSame($mytrace, $rcm->invoke($manager)); } diff --git a/admin/tool/dataprivacy/tests/filtered_userlist_test.php b/admin/tool/dataprivacy/tests/filtered_userlist_test.php index 7d71da16370..4146e0ec784 100644 --- a/admin/tool/dataprivacy/tests/filtered_userlist_test.php +++ b/admin/tool/dataprivacy/tests/filtered_userlist_test.php @@ -41,7 +41,6 @@ class filtered_userlist_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_dataprivacy\filtered_userlist::class); $rcm = $rc->getMethod('set_userids'); - $rcm->setAccessible(true); $rcm->invoke($userlist, $initial); diff --git a/admin/tool/langimport/tests/locale_test.php b/admin/tool/langimport/tests/locale_test.php index f2f121525ad..dbe51337b75 100644 --- a/admin/tool/langimport/tests/locale_test.php +++ b/admin/tool/langimport/tests/locale_test.php @@ -84,7 +84,6 @@ class locale_test extends \advanced_testcase { $loc = new locale(); $rc = new \ReflectionClass(locale::class); $rm = $rc->getMethod('set_locale'); - $rm->setAccessible(true); // Capture current locale for later restore (funnily, using the set_locale() method itself. $originallocale = $rm->invokeArgs($loc, [LC_ALL, 0]); diff --git a/admin/tool/licensemanager/tests/manager_test.php b/admin/tool/licensemanager/tests/manager_test.php index 2b9763c4ed4..3fdc0dcbf1a 100644 --- a/admin/tool/licensemanager/tests/manager_test.php +++ b/admin/tool/licensemanager/tests/manager_test.php @@ -70,7 +70,6 @@ class manager_test extends advanced_testcase { // We're testing a private method, so we need to setup reflector magic. $method = new ReflectionMethod('\tool_licensemanager\manager', 'edit'); - $method->setAccessible(true); // Allow accessing of private method. $method->invoke($manager, \tool_licensemanager\manager::ACTION_UPDATE, $testlicense->shortname); // Should not create a new license when updating an existing license. @@ -90,7 +89,6 @@ class manager_test extends advanced_testcase { // We're testing a private method, so we need to setup reflector magic. $method = new ReflectionMethod('\tool_licensemanager\manager', 'edit'); - $method->setAccessible(true); // Allow accessing of private method. // Attempt to update a license that doesn't exist. $formdata = [ @@ -111,7 +109,6 @@ class manager_test extends advanced_testcase { // We're testing a private method, so we need to setup reflector magic. $method = new ReflectionMethod('\tool_licensemanager\manager', 'edit'); - $method->setAccessible(true); // Allow accessing of private method. // Attempt to update a license without passing license shortname. $formdata = [ @@ -148,7 +145,6 @@ class manager_test extends advanced_testcase { // We're testing a private method, so we need to setup reflector magic. $method = new ReflectionMethod('\tool_licensemanager\manager', 'edit'); - $method->setAccessible(true); // Allow accessing of private method. $method->invoke($manager, \tool_licensemanager\manager::ACTION_CREATE, $formdata['shortname']); // Should create a new license in database. @@ -180,7 +176,6 @@ class manager_test extends advanced_testcase { // We're testing a private method, so we need to setup reflector magic. $method = new ReflectionMethod('\tool_licensemanager\manager', 'change_license_order'); - $method->setAccessible(true); // Allow accessing of private method. $method->invoke($manager, \tool_licensemanager\manager::ACTION_MOVE_UP, 'cc-nc-4.0'); $licenseorder = array_keys(license_manager::get_licenses()); diff --git a/admin/tool/mfa/factor/email/tests/factor_test.php b/admin/tool/mfa/factor/email/tests/factor_test.php index e0923555e70..55a45585eda 100644 --- a/admin/tool/mfa/factor/email/tests/factor_test.php +++ b/admin/tool/mfa/factor/email/tests/factor_test.php @@ -39,7 +39,6 @@ class factor_test extends \advanced_testcase { $emailfactorclass = new \factor_email\factor('email'); $rc = new \ReflectionClass($emailfactorclass::class); $rcm = $rc->getMethod('check_verification_code'); - $rcm->setAccessible(true); // Assigned email to be used in getting the email factor. $USER->email = 'user@mail.com'; @@ -76,7 +75,6 @@ class factor_test extends \advanced_testcase { // Cleans up email records once MFA passed. $rcm = $rc->getMethod('post_pass_state'); - $rcm->setAccessible(true); $rcm->invoke($emailfactorclass); // Check if the email records have been deleted. diff --git a/admin/tool/mfa/factor/sms/tests/factor_test.php b/admin/tool/mfa/factor/sms/tests/factor_test.php index 978916fc1b4..49e3e9a3313 100644 --- a/admin/tool/mfa/factor/sms/tests/factor_test.php +++ b/admin/tool/mfa/factor/sms/tests/factor_test.php @@ -154,7 +154,6 @@ class factor_test extends \advanced_testcase { // Check verification code. $rcm = $rc->getMethod('check_verification_code'); - $rcm->setAccessible(true); $this->assertTrue($rcm->invoke($smsfactor, $secretcode)); // Test that calling the revoke on the generic type revokes all. diff --git a/admin/tool/mfa/factor/token/tests/factor_test.php b/admin/tool/mfa/factor/token/tests/factor_test.php index 3a0b1450c66..62c63cd92dd 100644 --- a/admin/tool/mfa/factor/token/tests/factor_test.php +++ b/admin/tool/mfa/factor/token/tests/factor_test.php @@ -50,7 +50,6 @@ class factor_test extends \advanced_testcase { set_config('expireovernight', 0, 'factor_token'); $method = new \ReflectionMethod($this->factor, 'calculate_expiry_time'); - $method->setAccessible(true); // Test that non-overnight timestamps are just exactly as configured. // We don't need to care about 0 or negative ints, they will just make the cookie expire immediately. @@ -95,7 +94,6 @@ class factor_test extends \advanced_testcase { public function test_calculate_expiry_time_for_overnight_expiry_with_one_day_expiry($timestamp) { // Setup configuration. $method = new \ReflectionMethod($this->factor, 'calculate_expiry_time'); - $method->setAccessible(true); set_config('expireovernight', 1, 'factor_token'); set_config('expiry', DAYSECS, 'factor_token'); @@ -144,7 +142,6 @@ class factor_test extends \advanced_testcase { public function test_calculate_expiry_time_for_overnight_expiry_with_two_day_expiry($timestamp) { // Setup configuration. $method = new \ReflectionMethod($this->factor, 'calculate_expiry_time'); - $method->setAccessible(true); set_config('expireovernight', 1, 'factor_token'); set_config('expiry', 2 * DAYSECS, 'factor_token'); @@ -195,7 +192,6 @@ class factor_test extends \advanced_testcase { public function test_calculate_expiry_time_for_overnight_expiry_with_three_hour_expiry($timestamp) { // Setup configuration. $method = new \ReflectionMethod($this->factor, 'calculate_expiry_time'); - $method->setAccessible(true); set_config('expireovernight', 1, 'factor_token'); set_config('expiry', 3 * HOURSECS, 'factor_token'); @@ -240,7 +236,6 @@ class factor_test extends \advanced_testcase { public function test_calculate_expiry_time_for_overnight_expiry_with_an_hour_expiry($timestamp) { // Setup configuration. $method = new \ReflectionMethod($this->factor, 'calculate_expiry_time'); - $method->setAccessible(true); set_config('expireovernight', 1, 'factor_token'); set_config('expiry', HOURSECS, 'factor_token'); diff --git a/admin/tool/mfa/tests/secret_manager_test.php b/admin/tool/mfa/tests/secret_manager_test.php index b9b293f52ee..d426dfe0b8f 100644 --- a/admin/tool/mfa/tests/secret_manager_test.php +++ b/admin/tool/mfa/tests/secret_manager_test.php @@ -42,7 +42,6 @@ class secret_manager_test extends \advanced_testcase { // Mutate the sessionid using reflection. $reflectedsessionid = new \ReflectionProperty($secman, 'sessionid'); - $reflectedsessionid->setAccessible(true); $reflectedsessionid->setValue($secman, 'fakesession'); $sec1 = $secman->create_secret(1800, false); @@ -97,7 +96,6 @@ class secret_manager_test extends \advanced_testcase { // Let's make stuff public using reflection. $reflectedscanner = new \ReflectionClass($secman); $reflectedmethod = $reflectedscanner->getMethod('add_secret_to_db'); - $reflectedmethod->setAccessible(true); // Now add a secret and confirm it creates the correct record. $reflectedmethod->invoke($secman, 'code', 1800); @@ -164,7 +162,6 @@ class secret_manager_test extends \advanced_testcase { // Session locked code from the same session id. // Mutate the sessionid using reflection. $reflectedsessionid = new \ReflectionProperty($secman, 'sessionid'); - $reflectedsessionid->setAccessible(true); $reflectedsessionid->setValue($secman, 'fakesession'); $secret = $secman->create_secret(1800, true); @@ -227,7 +224,6 @@ class secret_manager_test extends \advanced_testcase { $reflectedscanner = new \ReflectionClass($secman); $reflectedmethod = $reflectedscanner->getMethod('has_active_secret'); - $reflectedmethod->setAccessible(true); // DB secrets. $this->assertFalse($reflectedmethod->invoke($secman)); @@ -244,7 +240,6 @@ class secret_manager_test extends \advanced_testcase { // Now check a secret with session involvement. // Mutate the sessionid using reflection. $reflectedsessionid = new \ReflectionProperty($secman, 'sessionid'); - $reflectedsessionid->setAccessible(true); $reflectedsessionid->setValue($secman, 'fakesession'); $this->assertFalse($reflectedmethod->invoke($secman, true)); diff --git a/admin/tool/usertours/tests/manager_test.php b/admin/tool/usertours/tests/manager_test.php index 17751f0aa74..82b52db87f0 100644 --- a/admin/tool/usertours/tests/manager_test.php +++ b/admin/tool/usertours/tests/manager_test.php @@ -110,7 +110,6 @@ class manager_test extends \advanced_testcase { $rc = new \ReflectionClass('\tool_usertours\manager'); $rcm = $rc->getMethod($function); - $rcm->setAccessible(true); $this->expectException('moodle_exception'); $rcm->invokeArgs($manager, $arguments); @@ -186,7 +185,6 @@ class manager_test extends \advanced_testcase { // Call protected method via reflection. $class = new \ReflectionClass(\tool_usertours\manager::class); $method = $class->getMethod('_move_tour'); - $method->setAccessible(true); $method->invokeArgs(null, [$tour, $direction]); // Assert expected sortorder. diff --git a/admin/tool/usertours/tests/step_test.php b/admin/tool/usertours/tests/step_test.php index 434908e01d5..f6286f05471 100644 --- a/admin/tool/usertours/tests/step_test.php +++ b/admin/tool/usertours/tests/step_test.php @@ -130,7 +130,6 @@ class step_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_usertours\step::class); $rcm = $rc->getMethod('fetch'); - $rcm->setAccessible(true); $id = rand(1, 100); $this->assertEquals($retval, $rcm->invoke($step, 'fetch', $id)); @@ -150,7 +149,6 @@ class step_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('dirty'); - $rcp->setAccessible(true); $this->assertTrue($rcp->getValue($step)); } @@ -234,7 +232,6 @@ class step_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('config'); - $rcp->setAccessible(true); $allvalues = (object) [ 'some' => 'value', @@ -361,7 +358,6 @@ class step_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('config'); - $rcp->setAccessible(true); $rcp->setValue($step, $values); $target = $this->getMockBuilder(\tool_usertours\local\target\base::class) @@ -465,7 +461,6 @@ class step_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('config'); - $rcp->setAccessible(true); $rcp->setValue($step, $initialvalues); $target = $this->getMockBuilder(\tool_usertours\local\target\base::class) @@ -542,12 +537,10 @@ class step_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('dirty'); - $rcp->setAccessible(true); $rcp->setValue($step, true); $tour = $this->createMock(\tool_usertours\tour::class); $rcp = $rc->getProperty('tour'); - $rcp->setAccessible(true); $rcp->setValue($step, $tour); $this->assertSame($step, $step->persist()); @@ -592,7 +585,6 @@ class step_test extends \advanced_testcase { $tour = $this->createMock(\tool_usertours\tour::class); $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('tour'); - $rcp->setAccessible(true); $rcp->setValue($step, $tour); $this->assertSame($step, $step->persist(true)); @@ -633,16 +625,13 @@ class step_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('id'); - $rcp->setAccessible(true); $rcp->setValue($step, 42); $rcp = $rc->getProperty('dirty'); - $rcp->setAccessible(true); $rcp->setValue($step, true); $tour = $this->createMock(\tool_usertours\tour::class); $rcp = $rc->getProperty('tour'); - $rcp->setAccessible(true); $rcp->setValue($step, $tour); $this->assertSame($step, $step->persist()); @@ -685,12 +674,10 @@ class step_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('id'); - $rcp->setAccessible(true); $rcp->setValue($step, 42); $tour = $this->createMock(\tool_usertours\tour::class); $rcp = $rc->getProperty('tour'); - $rcp->setAccessible(true); $rcp->setValue($step, $tour); $this->assertSame($step, $step->persist(true)); @@ -752,7 +739,6 @@ class step_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('id'); - $rcp->setAccessible(true); $rcp->setValue($step, $id); $this->assertEquals($id, $step->get_id()); @@ -810,7 +796,6 @@ class step_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty($key); - $rcp->setAccessible(true); $rcp->setValue($step, $value); $getter = 'get_' . $key; diff --git a/admin/tool/usertours/tests/tour_test.php b/admin/tool/usertours/tests/tour_test.php index f7955dd94e4..fa3685ac9fd 100644 --- a/admin/tool/usertours/tests/tour_test.php +++ b/admin/tool/usertours/tests/tour_test.php @@ -116,7 +116,6 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(\tool_usertours\tour::class); $rcp = $rc->getProperty('dirty'); - $rcp->setAccessible(true); $this->assertTrue($rcp->getValue($tour)); } @@ -172,7 +171,6 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty($key); - $rcp->setAccessible(true); $rcp->setValue($tour, $value); $getter = 'get_' . $key; @@ -233,13 +231,11 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('dirty'); - $rcp->setAccessible(true); $rcp->setValue($tour, true); $this->assertSame($tour, $tour->persist()); $rcp = $rc->getProperty('id'); - $rcp->setAccessible(true); $this->assertEquals($id, $rcp->getValue($tour)); } @@ -283,7 +279,6 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('id'); - $rcp->setAccessible(true); $this->assertEquals($id, $rcp->getValue($tour)); } @@ -322,11 +317,9 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('id'); - $rcp->setAccessible(true); $rcp->setValue($tour, 42); $rcp = $rc->getProperty('dirty'); - $rcp->setAccessible(true); $rcp->setValue($tour, true); $this->assertSame($tour, $tour->persist()); @@ -370,11 +363,9 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('id'); - $rcp->setAccessible(true); $rcp->setValue($tour, 42); $rcp = $rc->getProperty('dirty'); - $rcp->setAccessible(true); $rcp->setValue($tour, true); $this->assertSame($tour, $tour->persist(true)); @@ -393,7 +384,6 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('config'); - $rcp->setAccessible(true); $this->assertEquals((object) [ 'key' => 'value', 'another' => [ @@ -410,7 +400,6 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('config'); - $rcp->setAccessible(true); $allvalues = (object) [ 'some' => 'value', @@ -499,7 +488,6 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('config'); - $rcp->setAccessible(true); $rcp->setValue($tour, $values); $this->assertEquals($expected, $tour->get_config($key, $default)); @@ -544,7 +532,6 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('id'); - $rcp->setAccessible(true); $rcp->setValue($tour, $id); $step = $this->getMockBuilder(\tool_usertours\step::class) @@ -923,7 +910,6 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('sortorder'); - $rcp->setAccessible(true); $rcp->setValue($tour, $sortorder); $this->assertEquals($isfirst, $tour->is_first_tour()); @@ -943,7 +929,6 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('sortorder'); - $rcp->setAccessible(true); $rcp->setValue($tour, $sortorder); // The total will be calculated. @@ -969,7 +954,6 @@ class tour_test extends \advanced_testcase { $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('sortorder'); - $rcp->setAccessible(true); $rcp->setValue($tour, $sortorder); // The total is provided. diff --git a/analytics/tests/community_of_inquiry_activities_completed_by.php b/analytics/tests/community_of_inquiry_activities_completed_by.php index cb76f02d8db..c8b4df5fa4d 100644 --- a/analytics/tests/community_of_inquiry_activities_completed_by.php +++ b/analytics/tests/community_of_inquiry_activities_completed_by.php @@ -78,7 +78,6 @@ class community_of_inquiry_activities_completed_by_testcase extends advanced_tes )); $method = new ReflectionMethod($availabilityinfo, 'set_in_database'); - $method->setAccessible(true); $method->invoke($availabilityinfo, json_encode($structure)); $this->setUser($stu1); @@ -339,11 +338,9 @@ class community_of_inquiry_activities_completed_by_testcase extends advanced_tes $class = new ReflectionClass($indicator); $property = $class->getProperty('course'); - $property->setAccessible(true); $property->setValue($indicator, $course); $method = new ReflectionMethod($indicator, 'get_activities'); - $method->setAccessible(true); return array($indicator, $method); } diff --git a/analytics/tests/model_test.php b/analytics/tests/model_test.php index 884ef3e610d..b2a621379a0 100644 --- a/analytics/tests/model_test.php +++ b/analytics/tests/model_test.php @@ -427,7 +427,6 @@ class model_test extends \advanced_testcase { $modelconfig = new \core_analytics\model_config($this->model); $method = new \ReflectionMethod('\\core_analytics\\model_config', 'export_model_data'); - $method->setAccessible(true); $modeldata = $method->invoke($modelconfig); diff --git a/backup/moodle2/tests/backup_stepslib_test.php b/backup/moodle2/tests/backup_stepslib_test.php index 46dc1347cb1..d06ec5ae69f 100644 --- a/backup/moodle2/tests/backup_stepslib_test.php +++ b/backup/moodle2/tests/backup_stepslib_test.php @@ -74,7 +74,6 @@ class backup_stepslib_test extends \advanced_testcase { $reflection = new \ReflectionClass($step); $method = $reflection->getMethod('define_structure'); - $method->setAccessible(true); $structure = $method->invoke($step); $elements = $structure->get_final_elements(); diff --git a/backup/moodle2/tests/restore_gradebook_structure_step_test.php b/backup/moodle2/tests/restore_gradebook_structure_step_test.php index 2b47e14c80f..a541f383cb7 100644 --- a/backup/moodle2/tests/restore_gradebook_structure_step_test.php +++ b/backup/moodle2/tests/restore_gradebook_structure_step_test.php @@ -77,7 +77,6 @@ class restore_gradebook_structure_step_test extends \advanced_testcase { $rc = new \ReflectionClass('\restore_gradebook_structure_step'); $rcm = $rc->getMethod('rewrite_step_backup_file_for_legacy_freeze'); - $rcm->setAccessible(true); $rcm->invoke($restore, $filepath); // Check the result. diff --git a/backup/tests/automated_backup_test.php b/backup/tests/automated_backup_test.php index 26831d2ab43..42fdd102374 100644 --- a/backup/tests/automated_backup_test.php +++ b/backup/tests/automated_backup_test.php @@ -116,11 +116,9 @@ class automated_backup_test extends \advanced_testcase { $classobject = $this->backupcronautomatedhelper->return_this(); $method = new \ReflectionMethod('\backup_cron_automated_helper', 'get_courses'); - $method->setAccessible(true); // Allow accessing of private method. $courses = $method->invoke($classobject); $method = new \ReflectionMethod('\backup_cron_automated_helper', 'check_and_push_automated_backups'); - $method->setAccessible(true); // Allow accessing of private method. $emailpending = $method->invokeArgs($classobject, [$courses, $admin]); $this->expectOutputRegex('/Skipping course id ' . $this->course->id . ': Not scheduled for backup until/'); @@ -145,7 +143,6 @@ class automated_backup_test extends \advanced_testcase { $classobject = $this->backupcronautomatedhelper->return_this(); $method = new \ReflectionMethod('\backup_cron_automated_helper', 'get_courses'); - $method->setAccessible(true); // Allow accessing of private method. $courses = $method->invoke($classobject); // Create this backup course. @@ -161,7 +158,6 @@ class automated_backup_test extends \advanced_testcase { $DB->update_record('backup_courses', $backupcourse); $method = new \ReflectionMethod('\backup_cron_automated_helper', 'check_and_push_automated_backups'); - $method->setAccessible(true); // Allow accessing of private method. $emailpending = $method->invokeArgs($classobject, [$courses, $admin]); $this->assertTrue($emailpending); @@ -204,7 +200,6 @@ class automated_backup_test extends \advanced_testcase { $nextstarttime = backup_cron_automated_helper::calculate_next_automated_backup(null, time()); $method = new \ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup'); - $method->setAccessible(true); // Allow accessing of private method. $skipped = $method->invokeArgs($classobject, [$backupcourse, $course, $nextstarttime]); $this->assertTrue($skipped); @@ -239,7 +234,6 @@ class automated_backup_test extends \advanced_testcase { $nextstarttime = backup_cron_automated_helper::calculate_next_automated_backup(null, time()); $method = new \ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup'); - $method->setAccessible(true); // Allow accessing of private method. $skipped = $method->invokeArgs($classobject, [$backupcourse, $course, $nextstarttime]); $this->assertTrue($skipped); @@ -274,7 +268,6 @@ class automated_backup_test extends \advanced_testcase { $nextstarttime = backup_cron_automated_helper::calculate_next_automated_backup(null, time()); $method = new \ReflectionMethod('\backup_cron_automated_helper', 'should_skip_course_backup'); - $method->setAccessible(true); // Allow accessing of private method. $skipped = $method->invokeArgs($classobject, [$backupcourse, $course, $nextstarttime]); $this->assertTrue($skipped); @@ -298,7 +291,6 @@ class automated_backup_test extends \advanced_testcase { // Create a backup task. $method = new \ReflectionMethod('\backup_cron_automated_helper', 'push_course_backup_adhoc_task'); - $method->setAccessible(true); // Allow accessing of private method. $method->invokeArgs($classobject, [$backupcourse, $admin]); // Delete course for this test. @@ -331,7 +323,6 @@ class automated_backup_test extends \advanced_testcase { // Create a backup task. $method = new \ReflectionMethod('\backup_cron_automated_helper', 'push_course_backup_adhoc_task'); - $method->setAccessible(true); // Allow accessing of private method. $method->invokeArgs($classobject, [$backupcourse, $admin]); // Delete backup course for this test. diff --git a/backup/util/dbops/tests/restore_dbops_test.php b/backup/util/dbops/tests/restore_dbops_test.php index 325c01a4adb..2be84704e08 100644 --- a/backup/util/dbops/tests/restore_dbops_test.php +++ b/backup/util/dbops/tests/restore_dbops_test.php @@ -351,7 +351,6 @@ class restore_dbops_test extends \advanced_testcase { $dbuser = $DB->get_record('user', ['id' => $dbuser->id]); $method = (new \ReflectionClass('restore_dbops'))->getMethod('precheck_user'); - $method->setAccessible(true); $result = $method->invoke(null, $backupuser, $samesite, $siteid); if (is_bool($result)) { diff --git a/backup/util/helper/tests/restore_log_rule_test.php b/backup/util/helper/tests/restore_log_rule_test.php index 58c0cfc6ffa..83c004ffc1b 100644 --- a/backup/util/helper/tests/restore_log_rule_test.php +++ b/backup/util/helper/tests/restore_log_rule_test.php @@ -62,11 +62,9 @@ class restore_log_rule_test extends \basic_testcase { $class = new \ReflectionClass('restore_log_rule'); $method = $class->getMethod('extract_tokens'); - $method->setAccessible(true); $tokens = $method->invoke($lr, $original); $method = $class->getMethod('build_regexp'); - $method->setAccessible(true); $this->assertSame($expectation, $method->invoke($lr, $original, $tokens)); } } diff --git a/badges/tests/badgeslib_test.php b/badges/tests/badgeslib_test.php index df569b1cd4c..555e2d8a704 100644 --- a/badges/tests/badgeslib_test.php +++ b/badges/tests/badgeslib_test.php @@ -912,7 +912,6 @@ class badgeslib_test extends advanced_testcase { core_badges_myprofile_navigation($tree, $this->user, $iscurrentuser, $course); $reflector = new ReflectionObject($tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('localbadges', $nodes->getValue($tree)); } @@ -935,7 +934,6 @@ class badgeslib_test extends advanced_testcase { core_badges_myprofile_navigation($tree, $this->user, $iscurrentuser, $course); $reflector = new ReflectionObject($tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('localbadges', $nodes->getValue($tree)); } @@ -954,7 +952,6 @@ class badgeslib_test extends advanced_testcase { core_badges_myprofile_navigation($tree, $this->user, $iscurrentuser, $this->course); $reflector = new ReflectionObject($tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('localbadges', $nodes->getValue($tree)); } diff --git a/badges/tests/output/manage_badge_action_bar_test.php b/badges/tests/output/manage_badge_action_bar_test.php index 0979f5e8c30..b93a3c7d2ed 100644 --- a/badges/tests/output/manage_badge_action_bar_test.php +++ b/badges/tests/output/manage_badge_action_bar_test.php @@ -134,7 +134,6 @@ class manage_badge_action_bar_test extends \advanced_testcase { $rc = new \ReflectionClass(manage_badge_action_bar::class); $rcm = $rc->getMethod('generate_badge_navigation'); - $rcm->setAccessible(true); $content = $rcm->invoke($actionbar); $this->assertEquals($expected, array_values($content)); } diff --git a/blocks/accessreview/tests/accessibility_review_test.php b/blocks/accessreview/tests/accessibility_review_test.php index 00f74ad458c..8388fd31e95 100644 --- a/blocks/accessreview/tests/accessibility_review_test.php +++ b/blocks/accessreview/tests/accessibility_review_test.php @@ -39,7 +39,6 @@ class accessibility_review_test extends advanced_testcase { public function test_get_toggle_link() { $rc = new ReflectionClass(block_accessreview::class); $rm = $rc->getMethod('get_toggle_link'); - $rm->setAccessible(true); $block = new block_accessreview(); $output = $rm->invoke($block); @@ -60,7 +59,6 @@ class accessibility_review_test extends advanced_testcase { $rc = new ReflectionClass(block_accessreview::class); $rm = $rc->getMethod('get_download_link'); - $rm->setAccessible(true); $block = new block_accessreview(); $this->setUser($user1); @@ -86,7 +84,6 @@ class accessibility_review_test extends advanced_testcase { $rc = new ReflectionClass(block_accessreview::class); $rm = $rc->getMethod('get_report_link'); - $rm->setAccessible(true); $block = new block_accessreview(); $this->setUser($user1); diff --git a/blog/tests/lib_test.php b/blog/tests/lib_test.php index 345e9d2936e..0eb80f70e9b 100644 --- a/blog/tests/lib_test.php +++ b/blog/tests/lib_test.php @@ -175,7 +175,6 @@ class lib_test extends \advanced_testcase { core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course); $reflector = new \ReflectionObject($tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('blogs', $nodes->getValue($tree)); } @@ -197,7 +196,6 @@ class lib_test extends \advanced_testcase { core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course); $reflector = new \ReflectionObject($tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('blogs', $nodes->getValue($tree)); } @@ -220,7 +218,6 @@ class lib_test extends \advanced_testcase { core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course); $reflector = new \ReflectionObject($tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('blogs', $nodes->getValue($tree)); } diff --git a/cache/stores/redis/lib.php b/cache/stores/redis/lib.php index 3b3229302bb..16a8d25d8f4 100644 --- a/cache/stores/redis/lib.php +++ b/cache/stores/redis/lib.php @@ -851,7 +851,6 @@ class cachestore_redis extends cache_store implements cache_is_key_aware, cache_ if (!empty($config->test_ttl)) { $definition = clone $definition; $property = (new ReflectionClass($definition))->getProperty('ttl'); - $property->setAccessible(true); $property->setValue($definition, 999); } $cache = new cachestore_redis('Redis test', $configuration); diff --git a/cache/tests/cache_test.php b/cache/tests/cache_test.php index ac6df7fe274..a080816856c 100644 --- a/cache/tests/cache_test.php +++ b/cache/tests/cache_test.php @@ -2332,11 +2332,8 @@ class cache_test extends \advanced_testcase { // We need to get the individual stores so as to set up the right behaviour here. $ref = new \ReflectionClass('\cache'); $definitionprop = $ref->getProperty('definition'); - $definitionprop->setAccessible(true); $storeprop = $ref->getProperty('store'); - $storeprop->setAccessible(true); $loaderprop = $ref->getProperty('loader'); - $loaderprop->setAccessible(true); $definition = $definitionprop->getValue($cache); $localstore = $storeprop->getValue($cache); @@ -2346,7 +2343,6 @@ class cache_test extends \advanced_testcase { // Set the lock waiting time to 1 second so it doesn't take forever to run the test. $ref = new \ReflectionClass('\cachestore_file'); $lockwaitprop = $ref->getProperty('lockwait'); - $lockwaitprop->setAccessible(true); $lockwaitprop->setValue($localstore, 1); $lockwaitprop->setValue($sharedstore, 1); diff --git a/calendar/tests/calendar_event_exporter_test.php b/calendar/tests/calendar_event_exporter_test.php index 05530921646..e092c4689b3 100644 --- a/calendar/tests/calendar_event_exporter_test.php +++ b/calendar/tests/calendar_event_exporter_test.php @@ -80,7 +80,6 @@ class calendar_event_exporter_test extends \advanced_testcase { ->getMock(); $reflector = new \ReflectionClass($class); $method = $reflector->getMethod('get_timestamp_min_limit'); - $method->setAccessible(true); $result = $method->invoke($mock, $starttime, $min); $this->assertEquals($expected, $result['mindaytimestamp']); @@ -137,7 +136,6 @@ class calendar_event_exporter_test extends \advanced_testcase { ->getMock(); $reflector = new \ReflectionClass($class); $method = $reflector->getMethod('get_timestamp_max_limit'); - $method->setAccessible(true); $result = $method->invoke($mock, $starttime, $max); $this->assertEquals($expected, $result['maxdaytimestamp']); diff --git a/calendar/tests/rrule_manager_test.php b/calendar/tests/rrule_manager_test.php index ed9a3c11994..12b625a27a8 100644 --- a/calendar/tests/rrule_manager_test.php +++ b/calendar/tests/rrule_manager_test.php @@ -124,7 +124,6 @@ class rrule_manager_test extends \advanced_testcase { $reflectionclass = new \ReflectionClass($mang); foreach ($props as $prop => $expectedval) { $rcprop = $reflectionclass->getProperty($prop); - $rcprop->setAccessible(true); $this->assertEquals($expectedval, $rcprop->getValue($mang)); } } diff --git a/communication/provider/matrix/tests/local/command_test.php b/communication/provider/matrix/tests/local/command_test.php index c255f26ed63..8e540b78410 100644 --- a/communication/provider/matrix/tests/local/command_test.php +++ b/communication/provider/matrix/tests/local/command_test.php @@ -281,7 +281,6 @@ class command_test extends \advanced_testcase { ); $execute = new ReflectionMethod($instance, 'execute'); - $execute->setAccessible(true); $execute->invoke($instance, $command); } diff --git a/communication/provider/matrix/tests/matrix_client_test.php b/communication/provider/matrix/tests/matrix_client_test.php index 00680e242ad..a3e8c895086 100644 --- a/communication/provider/matrix/tests/matrix_client_test.php +++ b/communication/provider/matrix/tests/matrix_client_test.php @@ -447,7 +447,6 @@ class matrix_client_test extends \advanced_testcase { $rc = new \ReflectionClass($instance); $rcm = $rc->getMethod('execute'); - $rcm->setAccessible(true); $result = $rcm->invoke($instance, $command); $this->assertEquals(200, $result->getStatusCode()); diff --git a/contentbank/tests/contentbank_test.php b/contentbank/tests/contentbank_test.php index 88a08ed07a9..6291c2ae70e 100644 --- a/contentbank/tests/contentbank_test.php +++ b/contentbank/tests/contentbank_test.php @@ -568,7 +568,6 @@ class contentbank_test extends advanced_testcase { // Replace protected singletoninstance reference (core_plugin_manager property) with mock object. $ref = new \ReflectionProperty(\core_plugin_manager::class, 'singletoninstance'); - $ref->setAccessible(true); $ref->setValue(null, $pluginmanager); // Return values of get_plugins_of_type method. @@ -592,7 +591,6 @@ class contentbank_test extends advanced_testcase { // Get access to private property enabledcontenttypes. $rc = new \ReflectionClass(\core_contentbank\contentbank::class); $rcp = $rc->getProperty('enabledcontenttypes'); - $rcp->setAccessible(true); foreach ($contenttypesenabled as $contenttypename) { $plugins["\\contenttype_$contenttypename\\contenttype"] = $contenttypename; diff --git a/course/format/tests/local/baseactions_test.php b/course/format/tests/local/baseactions_test.php index 65bc80d9732..19d05e14332 100644 --- a/course/format/tests/local/baseactions_test.php +++ b/course/format/tests/local/baseactions_test.php @@ -45,7 +45,6 @@ class baseactions_test extends \advanced_testcase { private function get_base_reflection_method(baseactions $baseinstance, string $methodname): ReflectionMethod { $reflectionclass = new \reflectionclass($baseinstance); $method = $reflectionclass->getMethod($methodname); - $method->setAccessible(true); return $method; } diff --git a/course/tests/category_hooks_test.php b/course/tests/category_hooks_test.php index 21a73bd9163..b68de7a7eeb 100644 --- a/course/tests/category_hooks_test.php +++ b/course/tests/category_hooks_test.php @@ -72,7 +72,6 @@ class category_hooks_test extends \advanced_testcase { // This is used to overcome private constructor. $reflected = new \ReflectionClass(\core_course_category::class); $constructor = $reflected->getConstructor(); - $constructor->setAccessible(true); $constructor->invoke($mockcategory, $category->get_db_record()); return $mockcategory; diff --git a/course/tests/course_image_cache_test.php b/course/tests/course_image_cache_test.php index c3fffd79c21..59b697a5b97 100644 --- a/course/tests/course_image_cache_test.php +++ b/course/tests/course_image_cache_test.php @@ -98,7 +98,6 @@ class course_image_cache_test extends \advanced_testcase { public function test_get_image_url_from_overview_files_return_null_if_no_summary_files_in_the_course() { $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files'); $cache = course_image::get_instance_for_cache(new cache_definition()); - $method->setAccessible(true); // Create course without files. $course = $this->getDataGenerator()->create_course(); @@ -111,7 +110,6 @@ class course_image_cache_test extends \advanced_testcase { public function test_get_image_url_from_overview_files_returns_null_if_no_summary_images_in_the_course() { $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files'); $cache = course_image::get_instance_for_cache(new cache_definition()); - $method->setAccessible(true); // Create course without image files. $draftid2 = $this->fill_draft_area(['filename2.zip' => 'Test file contents2']); @@ -125,7 +123,6 @@ class course_image_cache_test extends \advanced_testcase { public function test_get_image_url_from_overview_files_returns_url_if_there_is_a_summary_image() { $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files'); $cache = course_image::get_instance_for_cache(new cache_definition()); - $method->setAccessible(true); // Create course without one image. $draftid1 = $this->fill_draft_area(['filename1.jpg' => file_get_contents(__DIR__ . '/fixtures/image.jpg')]); @@ -140,7 +137,6 @@ class course_image_cache_test extends \advanced_testcase { public function test_get_image_url_from_overview_files_returns_url_of_the_first_image_if_there_are_many_summary_images() { $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files'); $cache = course_image::get_instance_for_cache(new cache_definition()); - $method->setAccessible(true); // Create course with two image files. $draftid1 = $this->fill_draft_area([ @@ -159,7 +155,6 @@ class course_image_cache_test extends \advanced_testcase { public function test_get_image_url_from_overview_files_returns_url_of_the_first_image_if_there_are_many_summary_files() { $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files'); $cache = course_image::get_instance_for_cache(new cache_definition()); - $method->setAccessible(true); // Create course with two image files and one zip file. $draftid1 = $this->fill_draft_area([ diff --git a/course/tests/targets_test.php b/course/tests/targets_test.php index 9e2e72b9823..6dc0ad89a5d 100644 --- a/course/tests/targets_test.php +++ b/course/tests/targets_test.php @@ -413,7 +413,6 @@ class targets_test extends \advanced_testcase { $class = new \ReflectionClass('\core\analytics\analyser\student_enrolments'); $method = $class->getMethod('get_all_samples'); - $method->setAccessible(true); list($sampleids, $samplesdata) = $method->invoke($analyser, $analysable); $target->add_sample_data($samplesdata); @@ -448,7 +447,6 @@ class targets_test extends \advanced_testcase { $class = new \ReflectionClass('\core\analytics\analyser\student_enrolments'); $method = $class->getMethod('get_all_samples'); - $method->setAccessible(true); list($sampleids, $samplesdata) = $method->invoke($analyser, $analysable); $target->add_sample_data($samplesdata); @@ -456,7 +454,6 @@ class targets_test extends \advanced_testcase { $reftarget = new \ReflectionObject($target); $refmethod = $reftarget->getMethod('calculate_sample'); - $refmethod->setAccessible(true); if ($nullcalculation) { $this->assertNull($refmethod->invoke($target, $sampleid, $analysable, $starttime, $endtime)); @@ -532,7 +529,6 @@ class targets_test extends \advanced_testcase { $class = new \ReflectionClass('\core\analytics\analyser\student_enrolments'); $method = $class->getMethod('get_all_samples'); - $method->setAccessible(true); list($sampleids, $samplesdata) = $method->invoke($analyser, $analysable); $target->add_sample_data($samplesdata); @@ -540,7 +536,6 @@ class targets_test extends \advanced_testcase { $class = new \ReflectionClass('\core_course\analytics\target\course_competencies'); $method = $class->getMethod('calculate_sample'); - $method->setAccessible(true); // Method calculate_sample() returns 1 when the user has not achieved all the competencies assigned to the course. $this->assertEquals(1, $method->invoke($target, $sampleid, $analysable)); @@ -630,14 +625,12 @@ class targets_test extends \advanced_testcase { $class = new \ReflectionClass('\core\analytics\analyser\student_enrolments'); $method = $class->getMethod('get_all_samples'); - $method->setAccessible(true); list($sampleids, $samplesdata) = $method->invoke($analyser, $analysable); $target->add_sample_data($samplesdata); $class = new \ReflectionClass('\core_course\analytics\target\course_gradetopass'); $method = $class->getMethod('calculate_sample'); - $method->setAccessible(true); // Verify all the expectations are fulfilled. foreach ($sampleids as $sampleid => $key) { diff --git a/customfield/tests/generator/lib.php b/customfield/tests/generator/lib.php index eae8490154f..6da6bf30f82 100644 --- a/customfield/tests/generator/lib.php +++ b/customfield/tests/generator/lib.php @@ -156,7 +156,6 @@ class core_customfield_generator extends component_generator_base { $rc = new ReflectionClass(get_class($data)); $rcm = $rc->getMethod('get_form_element_name'); - $rcm->setAccessible(true); $formelementname = $rcm->invokeArgs($data, []); $record = (object)[$formelementname => $value]; $data->instance_form_save($record); diff --git a/enrol/ldap/tests/ldap_test.php b/enrol/ldap/tests/ldap_test.php index c918b19f029..7f93d763593 100644 --- a/enrol/ldap/tests/ldap_test.php +++ b/enrol/ldap/tests/ldap_test.php @@ -513,7 +513,6 @@ class ldap_test extends \advanced_testcase { // Use reflection to sneak a look at the plugin. $rc = new \ReflectionClass('enrol_ldap_plugin'); $rcp = $rc->getProperty('userobjectclass'); - $rcp->setAccessible(true); // Fetch the current userobjectclass value. $value = $rcp->getValue($instance); diff --git a/enrol/lti/tests/helper_test.php b/enrol/lti/tests/helper_test.php index 90fc6c09e14..a3553183415 100644 --- a/enrol/lti/tests/helper_test.php +++ b/enrol/lti/tests/helper_test.php @@ -477,7 +477,6 @@ class helper_test extends \advanced_testcase { public function test_set_xpath($parameters, $expected) { $helper = new \ReflectionClass('enrol_lti\\helper'); $function = $helper->getMethod('set_xpath'); - $function->setAccessible(true); $document = new \DOMDocument(); $document->load(realpath(__DIR__ . '/fixtures/input.xml')); @@ -502,7 +501,6 @@ class helper_test extends \advanced_testcase { ]; $helper = new \ReflectionClass('enrol_lti\\helper'); $function = $helper->getMethod('set_xpath'); - $function->setAccessible(true); $document = new \DOMDocument(); $document->load(realpath(__DIR__ . '/fixtures/input.xml')); diff --git a/files/tests/converter_test.php b/files/tests/converter_test.php index d54d4b171ae..ae766c8856c 100644 --- a/files/tests/converter_test.php +++ b/files/tests/converter_test.php @@ -223,7 +223,6 @@ class converter_test extends advanced_testcase { $converter->method('get_enabled_plugins')->willReturn([]); $method = new ReflectionMethod(\core_files\converter::class, 'get_document_converter_classes'); - $method->setAccessible(true); $result = $method->invokeArgs($converter, ['docx', 'pdf']); $this->assertEmpty($result); } @@ -238,7 +237,6 @@ class converter_test extends advanced_testcase { ]); $method = new ReflectionMethod(\core_files\converter::class, 'get_document_converter_classes'); - $method->setAccessible(true); $result = $method->invokeArgs($converter, ['docx', 'pdf']); $this->assertEmpty($result); } @@ -257,7 +255,6 @@ class converter_test extends advanced_testcase { ]); $method = new ReflectionMethod(\core_files\converter::class, 'get_document_converter_classes'); - $method->setAccessible(true); $result = $method->invokeArgs($converter, ['docx', 'pdf']); $this->assertEmpty($result); } @@ -276,7 +273,6 @@ class converter_test extends advanced_testcase { ]); $method = new ReflectionMethod(\core_files\converter::class, 'get_document_converter_classes'); - $method->setAccessible(true); $result = $method->invokeArgs($converter, ['docx', 'pdf']); $this->assertEmpty($result); } @@ -296,7 +292,6 @@ class converter_test extends advanced_testcase { ]); $method = new ReflectionMethod(\core_files\converter::class, 'get_document_converter_classes'); - $method->setAccessible(true); $result = $method->invokeArgs($converter, ['docx', 'pdf']); $this->assertCount(1, $result); $this->assertNotFalse(array_search($classname, $result)); @@ -681,7 +676,6 @@ class converter_test extends advanced_testcase { */ public function test_get_next_converter_no_converters() { $rcm = new \ReflectionMethod(converter::class, 'get_next_converter'); - $rcm->setAccessible(true); $converter = new \core_files\converter(); $result = $rcm->invoke($converter, [], null); @@ -694,7 +688,6 @@ class converter_test extends advanced_testcase { */ public function test_get_next_converter_only_converters() { $rcm = new \ReflectionMethod(converter::class, 'get_next_converter'); - $rcm->setAccessible(true); $converter = new converter(); $result = $rcm->invoke($converter, ['example'], 'example'); @@ -707,7 +700,6 @@ class converter_test extends advanced_testcase { */ public function test_get_next_converter_last_converters() { $rcm = new \ReflectionMethod(converter::class, 'get_next_converter'); - $rcm->setAccessible(true); $converter = new converter(); $result = $rcm->invoke($converter, ['foo', 'example'], 'example'); @@ -720,7 +712,6 @@ class converter_test extends advanced_testcase { */ public function test_get_next_converter_middle_converters() { $rcm = new \ReflectionMethod(converter::class, 'get_next_converter'); - $rcm->setAccessible(true); $converter = new converter(); $result = $rcm->invoke($converter, ['foo', 'bar', 'baz', 'example'], 'bar'); @@ -733,7 +724,6 @@ class converter_test extends advanced_testcase { */ public function test_get_next_converter_first() { $rcm = new \ReflectionMethod(converter::class, 'get_next_converter'); - $rcm->setAccessible(true); $converter = new converter(); $result = $rcm->invoke($converter, ['foo', 'bar', 'baz', 'example']); diff --git a/grade/report/user/tests/lib_test.php b/grade/report/user/tests/lib_test.php index c27caa4c02f..59bb6dc5fe6 100644 --- a/grade/report/user/tests/lib_test.php +++ b/grade/report/user/tests/lib_test.php @@ -69,7 +69,6 @@ class lib_test extends \advanced_testcase { gradereport_user_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('grade', $nodes->getValue($this->tree)); } @@ -84,7 +83,6 @@ class lib_test extends \advanced_testcase { gradereport_user_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('grade', $nodes->getValue($this->tree)); } } diff --git a/h5p/tests/editor_test.php b/h5p/tests/editor_test.php index 74fe952b91f..d2f1fc76381 100644 --- a/h5p/tests/editor_test.php +++ b/h5p/tests/editor_test.php @@ -113,7 +113,6 @@ class editor_test extends advanced_testcase { // Call the method. We need the id of the new H5P content. $rc = new \ReflectionClass(player::class); $rcp = $rc->getProperty('h5pid'); - $rcp->setAccessible(true); $h5pid = $rcp->getValue($h5pplayer); $editor = new editor(); @@ -122,7 +121,6 @@ class editor_test extends advanced_testcase { // Check we get the H5P content. $rc = new \ReflectionClass(editor::class); $rcp = $rc->getProperty('oldcontent'); - $rcp->setAccessible(true); $oldcontent = $rcp->getValue($editor); $core = (new factory)->get_core(); @@ -130,7 +128,6 @@ class editor_test extends advanced_testcase { // Check we get the file of the H5P content. $rcp = $rc->getProperty('oldfile'); - $rcp->setAccessible(true); $oldfile = $rcp->getValue($editor); $this->assertSame($file->get_contenthash(), $oldfile->get_contenthash()); @@ -154,7 +151,6 @@ class editor_test extends advanced_testcase { // Check that the library has the right value. $rc = new \ReflectionClass(editor::class); $rcp = $rc->getProperty('library'); - $rcp->setAccessible(true); $actual = $rcp->getValue($editor); $this->assertSame($library, $actual); @@ -171,7 +167,6 @@ class editor_test extends advanced_testcase { ]; $rcp = $rc->getProperty('filearea'); - $rcp->setAccessible(true); $actual = $rcp->getValue($editor); $this->assertEquals($expected, $actual); @@ -198,8 +193,6 @@ class editor_test extends advanced_testcase { $rc = new \ReflectionClass(page_requirements_manager::class); $rcp = $rc->getProperty('cssurls'); $rcp2 = $rc->getProperty('jsincludes'); - $rcp->setAccessible(true); - $rcp2->setAccessible(true); $actualcss = array_keys($rcp->getValue($PAGE->requires)); $actualjs = array_keys($rcp2->getValue($PAGE->requires)['head']); $cachebuster = helper::get_cache_buster(); diff --git a/h5p/tests/file_storage_test.php b/h5p/tests/file_storage_test.php index cbf0ee5a13e..a1f9b5c290a 100644 --- a/h5p/tests/file_storage_test.php +++ b/h5p/tests/file_storage_test.php @@ -69,11 +69,9 @@ class file_storage_test extends \advanced_testcase { // Get value of protected properties. $h5p_fs_rc = new \ReflectionClass(file_storage::class); $h5p_file_storage_context = $h5p_fs_rc->getProperty('context'); - $h5p_file_storage_context->setAccessible(true); $this->h5p_fs_context = $h5p_file_storage_context->getValue($this->h5p_file_storage); $h5p_file_storage_fs = $h5p_fs_rc->getProperty('fs'); - $h5p_file_storage_fs->setAccessible(true); $this->h5p_fs_fs = $h5p_file_storage_fs->getValue($this->h5p_file_storage); } @@ -625,7 +623,6 @@ class file_storage_test extends \advanced_testcase { // Set get_file method accessibility. $method = new ReflectionMethod(file_storage::class, 'get_file'); - $method->setAccessible(true); $contentfile = $method->invoke(new file_storage(), file_storage::CONTENT_FILEAREA, $h5pcontentid, $file); @@ -668,7 +665,6 @@ class file_storage_test extends \advanced_testcase { // Set get_file method accessibility. $method = new ReflectionMethod(file_storage::class, 'move_file'); - $method->setAccessible(true); $method->invoke(new file_storage(), $file, $h5pcontentid); diff --git a/h5p/tests/generator/lib.php b/h5p/tests/generator/lib.php index 3bfefc0df85..79edfec2e12 100644 --- a/h5p/tests/generator/lib.php +++ b/h5p/tests/generator/lib.php @@ -554,7 +554,6 @@ class core_h5p_generator extends \component_generator_base { // Call the method. We need the id of the new H5P content. $rc = new \ReflectionClass(player::class); $rcp = $rc->getProperty('h5pid'); - $rcp->setAccessible(true); $h5pid = $rcp->getValue($h5pplayer); // Get the info export file. diff --git a/lib/behat/classes/named_selector.php b/lib/behat/classes/named_selector.php index e683ffcf291..b390b759094 100644 --- a/lib/behat/classes/named_selector.php +++ b/lib/behat/classes/named_selector.php @@ -58,7 +58,6 @@ trait behat_named_selector { // This is due to an API limitation in Mink. $rc = new \ReflectionClass(\Behat\Mink\Selector\NamedSelector::class); $r = $rc->getProperty('replacements'); - $r->setAccessible(true); $replacements = $r->getValue($this); $selectorxpath = strtr($selector->get_combined_xpath(), $replacements); @@ -77,7 +76,6 @@ trait behat_named_selector { // This is due to an API limitation in Mink. $rc = new \ReflectionClass(\Behat\Mink\Selector\NamedSelector::class); $r = $rc->getProperty('replacements'); - $r->setAccessible(true); $existing = $r->getValue($this); $from = $replacement->get_from($component); diff --git a/lib/classes/scss.php b/lib/classes/scss.php index 31d73536eb1..301a7d65cdd 100644 --- a/lib/classes/scss.php +++ b/lib/classes/scss.php @@ -164,7 +164,6 @@ class core_scss extends \ScssPhp\ScssPhp\Compiler { // We need to find the import path relative to the directory of the currently processed file. $currentdirectory = new ReflectionProperty(\ScssPhp\ScssPhp\Compiler::class, 'currentDirectory'); - $currentdirectory->setAccessible(true); if ($path = $this->findImport($path, $currentdirectory->getValue($this))) { if ($this->is_valid_file($path)) { diff --git a/lib/ddl/tests/ddl_test.php b/lib/ddl/tests/ddl_test.php index 3dd3d07f22a..85456aec28e 100644 --- a/lib/ddl/tests/ddl_test.php +++ b/lib/ddl/tests/ddl_test.php @@ -1885,7 +1885,6 @@ class ddl_test extends \database_driver_testcase { $rc = new \ReflectionClass('moodle_database'); $rcm = $rc->getMethod('get_temp_tables_cache'); - $rcm->setAccessible(true); $metacachetemp = $rcm->invokeArgs($DB, []); // Data of test_table0 should be removed from the cache. @@ -1896,7 +1895,6 @@ class ddl_test extends \database_driver_testcase { $rc = new \ReflectionClass('moodle_database'); $rcm = $rc->getMethod('get_metacache'); - $rcm->setAccessible(true); $metacache = $rcm->invokeArgs($DB, []); // Data of test_table2 should be intact. diff --git a/lib/dml/tests/dml_mysqli_read_slave_test.php b/lib/dml/tests/dml_mysqli_read_slave_test.php index 7c797ebff4f..681fca72d11 100644 --- a/lib/dml/tests/dml_mysqli_read_slave_test.php +++ b/lib/dml/tests/dml_mysqli_read_slave_test.php @@ -117,7 +117,6 @@ class dml_mysqli_read_slave_test extends \base_testcase { $rc = new \ReflectionClass(\mysqli_native_moodle_database::class); $rcm = $rc->getMethod('insert_chunk_size'); - $rcm->setAccessible(true); $rcm->invoke($db2); $this->assertGreaterThan($reads, $reads = $db2->perf_get_reads()); $this->assertGreaterThan($readsprimary, $readsprimary = $reads - $db2->perf_get_reads_slave()); diff --git a/lib/dml/tests/dml_test.php b/lib/dml/tests/dml_test.php index 46fa06f032c..653f158c329 100644 --- a/lib/dml/tests/dml_test.php +++ b/lib/dml/tests/dml_test.php @@ -500,7 +500,7 @@ class dml_test extends \database_driver_testcase { $out = $fixture->four($sql); $expected = <<invoke() +-- line 64 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to ReflectionMethod->invoke() EOD; $this->assertEquals($this->unix_to_os_dirsep($expected), $out); @@ -508,8 +508,8 @@ EOD; $out = $fixture->four($sql); $expected = <<invoke() --- line 74 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->one() +-- line 64 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to ReflectionMethod->invoke() +-- line 73 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->one() EOD; $this->assertEquals($this->unix_to_os_dirsep($expected), $out); @@ -517,10 +517,10 @@ EOD; $out = $fixture->four($sql); $expected = <<invoke() --- line 74 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->one() --- line 83 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->two() --- line 92 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->three() +-- line 64 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to ReflectionMethod->invoke() +-- line 73 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->one() +-- line 82 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->two() +-- line 91 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->three() -- line 517 of /lib/dml/tests/dml_test.php: call to test_dml_sql_debugging_fixture->four() EOD; $this->assertEquals($this->unix_to_os_dirsep($expected), $out); @@ -6371,7 +6371,6 @@ EOD; $this->assertTrue(empty($cfg->dboptions['versionfromdb'])); $rc = new \ReflectionClass(\mysqli_native_moodle_database::class); $rcm = $rc->getMethod('should_db_version_be_read_from_db'); - $rcm->setAccessible(true); $this->assertFalse($rcm->invokeArgs($DB, [])); ['description' => $description, 'version' => $version] = $DB->get_server_info(); diff --git a/lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php b/lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php index 2aba9dead4c..c29268c0e09 100644 --- a/lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php +++ b/lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php @@ -61,7 +61,6 @@ class test_dml_sql_debugging_fixture { */ public function one(string $sql) { $method = new \ReflectionMethod($this->db, 'add_sql_debugging'); - $method->setAccessible(true); return $method->invoke($this->db, $sql); } diff --git a/lib/dml/tests/fixtures/test_moodle_read_slave_trait.php b/lib/dml/tests/fixtures/test_moodle_read_slave_trait.php index 07d21d8ae88..6826c3d9362 100644 --- a/lib/dml/tests/fixtures/test_moodle_read_slave_trait.php +++ b/lib/dml/tests/fixtures/test_moodle_read_slave_trait.php @@ -53,7 +53,6 @@ trait test_moodle_read_slave_trait { $this->prefix = 'test_'; // Default, not to leave empty. $rcp = new ReflectionProperty(parent::class, 'wantreadslave'); - $rcp->setAccessible(true); $rcp->setValue($this, true); $this->dbhwrite = $rw; diff --git a/lib/dml/tests/mysqli_native_moodle_database_test.php b/lib/dml/tests/mysqli_native_moodle_database_test.php index d40c5646d27..dd17338224a 100644 --- a/lib/dml/tests/mysqli_native_moodle_database_test.php +++ b/lib/dml/tests/mysqli_native_moodle_database_test.php @@ -70,7 +70,6 @@ class mysqli_native_moodle_database_test extends \advanced_testcase { $reflector = new ReflectionClass($db2); $rp = $reflector->getProperty('mysqli'); - $rp->setAccessible(true); return $rp->getValue($db2); } diff --git a/lib/dml/tests/pgsql_native_moodle_database_test.php b/lib/dml/tests/pgsql_native_moodle_database_test.php index 5e3986035b6..3e0a32e5546 100644 --- a/lib/dml/tests/pgsql_native_moodle_database_test.php +++ b/lib/dml/tests/pgsql_native_moodle_database_test.php @@ -89,7 +89,6 @@ class pgsql_native_moodle_database_test extends \advanced_testcase { global $DB; $reflector = new ReflectionClass($DB); $property = $reflector->getProperty('inorequaluniqueindex'); - $property->setAccessible(true); return (int) $property->getValue($DB); } @@ -390,7 +389,6 @@ class pgsql_native_moodle_database_test extends \advanced_testcase { $reflector = new ReflectionClass($db2); $rp = $reflector->getProperty('pgsql'); - $rp->setAccessible(true); return $rp->getValue($db2); } diff --git a/lib/dml/tests/sqlsrv_native_moodle_database_test.php b/lib/dml/tests/sqlsrv_native_moodle_database_test.php index 9e0f34b9f7e..0d4800a6e47 100644 --- a/lib/dml/tests/sqlsrv_native_moodle_database_test.php +++ b/lib/dml/tests/sqlsrv_native_moodle_database_test.php @@ -125,10 +125,8 @@ class sqlsrv_native_moodle_database_test extends \advanced_testcase { $reflector = new \ReflectionObject($sqlsrv); $method = $reflector->getMethod('add_no_lock_to_temp_tables'); - $method->setAccessible(true); $temptablesproperty = $reflector->getProperty('temptables'); - $temptablesproperty->setAccessible(true); $temptables = new temptables_tester(); $temptablesproperty->setValue($sqlsrv, $temptables); @@ -252,7 +250,6 @@ EOT // The has_query_order_by static method is protected. Use Reflection to call the method. $method = new \ReflectionMethod('sqlsrv_native_moodle_database', 'has_query_order_by'); - $method->setAccessible(true); $result = $method->invoke(null, $sql); $this->assertSame($expectedresult, $result); } diff --git a/lib/external/tests/external_api_test.php b/lib/external/tests/external_api_test.php index cc359cae229..f806785b779 100644 --- a/lib/external/tests/external_api_test.php +++ b/lib/external/tests/external_api_test.php @@ -469,7 +469,6 @@ class external_api_test extends \advanced_testcase { protected function get_context_from_params() { $rc = new \ReflectionClass(external_api::class); $method = $rc->getMethod('get_context_from_params'); - $method->setAccessible(true); return $method->invokeArgs(null, func_get_args()); } } diff --git a/lib/filestorage/tests/file_system_filedir_test.php b/lib/filestorage/tests/file_system_filedir_test.php index 2d7532f405d..69d5bca3462 100644 --- a/lib/filestorage/tests/file_system_filedir_test.php +++ b/lib/filestorage/tests/file_system_filedir_test.php @@ -218,7 +218,6 @@ class file_system_filedir_test extends \advanced_testcase { ->willReturn($expectedresult); $method = new \ReflectionMethod(file_system_filedir::class, 'get_remote_path_from_hash'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, [$contenthash]); $this->assertEquals($expectedresult, $result); @@ -294,7 +293,6 @@ class file_system_filedir_test extends \advanced_testcase { $fs = new file_system_filedir(); $method = new \ReflectionMethod(file_system_filedir::class, 'get_fulldir_from_hash'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, array($hash)); $expectedpath = sprintf('%s/filedir/%s', $CFG->dataroot, $hashdir); @@ -326,7 +324,6 @@ class file_system_filedir_test extends \advanced_testcase { $fs = new file_system_filedir(); $method = new \ReflectionMethod('file_system_filedir', 'get_fulldir_from_storedfile'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, array($file)); $expectedpath = sprintf('%s/filedir/%s', $CFG->dataroot, $hashdir); @@ -345,7 +342,6 @@ class file_system_filedir_test extends \advanced_testcase { */ public function test_get_contentdir_from_hash($hash, $hashdir) { $method = new \ReflectionMethod(file_system_filedir::class, 'get_contentdir_from_hash'); - $method->setAccessible(true); $fs = new file_system_filedir(); $result = $method->invokeArgs($fs, array($hash)); @@ -365,7 +361,6 @@ class file_system_filedir_test extends \advanced_testcase { */ public function test_get_contentpath_from_hash($hash, $hashdir) { $method = new \ReflectionMethod(file_system_filedir::class, 'get_contentpath_from_hash'); - $method->setAccessible(true); $fs = new file_system_filedir(); $result = $method->invokeArgs($fs, array($hash)); @@ -389,7 +384,6 @@ class file_system_filedir_test extends \advanced_testcase { $fs = new file_system_filedir(); $method = new \ReflectionMethod(file_system_filedir::class, 'get_trash_fullpath_from_hash'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, array($hash)); $expectedpath = sprintf('%s/trashdir/%s/%s', $CFG->dataroot, $hashdir, $hash); @@ -411,7 +405,6 @@ class file_system_filedir_test extends \advanced_testcase { $fs = new file_system_filedir(); $method = new \ReflectionMethod(file_system_filedir::class, 'get_trash_fulldir_from_hash'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, array($hash)); $expectedpath = sprintf('%s/trashdir/%s', $CFG->dataroot, $hashdir); @@ -486,7 +479,6 @@ class file_system_filedir_test extends \advanced_testcase { $fs = new file_system_filedir(); $method = new \ReflectionMethod(file_system_filedir::class, 'recover_file'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, array($file)); // Test the output. @@ -526,7 +518,6 @@ class file_system_filedir_test extends \advanced_testcase { $fs = new file_system_filedir(); $method = new \ReflectionMethod(file_system_filedir::class, 'recover_file'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, array($file)); // Test the output. @@ -564,7 +555,6 @@ class file_system_filedir_test extends \advanced_testcase { $fs = new file_system_filedir(); $method = new \ReflectionMethod(file_system_filedir::class, 'recover_file'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, array($file)); // Test the output. @@ -601,7 +591,6 @@ class file_system_filedir_test extends \advanced_testcase { $fs = new file_system_filedir(); $method = new \ReflectionMethod(file_system_filedir::class, 'recover_file'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, array($file)); // Test the output. @@ -635,7 +624,6 @@ class file_system_filedir_test extends \advanced_testcase { $fs = new file_system_filedir(); $method = new \ReflectionMethod(file_system_filedir::class, 'recover_file'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, array($file)); // Test the output. @@ -675,7 +663,6 @@ class file_system_filedir_test extends \advanced_testcase { $fs = new file_system_filedir(); $method = new \ReflectionMethod(file_system_filedir::class, 'recover_file'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, array($file)); // Test the output. @@ -1092,7 +1079,6 @@ class file_system_filedir_test extends \advanced_testcase { $fs = new file_system_filedir(); $method = new \ReflectionMethod(file_system_filedir::class, 'empty_trash'); - $method->setAccessible(true); $result = $method->invoke($fs); $this->assertTrue($vfileroot->hasChild('filedir/0f/f3/' . $contenthash)); diff --git a/lib/filestorage/tests/file_system_test.php b/lib/filestorage/tests/file_system_test.php index 9a854308ed9..edd1d8d1075 100644 --- a/lib/filestorage/tests/file_system_test.php +++ b/lib/filestorage/tests/file_system_test.php @@ -494,7 +494,6 @@ class file_system_test extends \advanced_testcase { $contenthash = \file_storage::hash_from_string($filecontent); $method = new \ReflectionMethod(file_system::class, 'is_file_removable'); - $method->setAccessible(true); $result = $method->invokeArgs(null, [$contenthash]); $this->assertFalse($result); } @@ -517,7 +516,6 @@ class file_system_test extends \advanced_testcase { $DB->method('record_exists')->willReturn(true); $method = new \ReflectionMethod(file_system::class, 'is_file_removable'); - $method->setAccessible(true); $result = $method->invokeArgs(null, [$contenthash]); $this->assertFalse($result); @@ -541,7 +539,6 @@ class file_system_test extends \advanced_testcase { $DB->method('record_exists')->willReturn(false); $method = new \ReflectionMethod(file_system::class, 'is_file_removable'); - $method->setAccessible(true); $result = $method->invokeArgs(null, [$contenthash]); $this->assertTrue($result); @@ -910,7 +907,6 @@ class file_system_test extends \advanced_testcase { $fs = $this->get_testable_mock(); $method = new \ReflectionMethod(file_system::class, 'get_imageinfo_from_path'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, [$filepath]); $this->assertArrayHasKey('width', $result); @@ -932,7 +928,6 @@ class file_system_test extends \advanced_testcase { $fs = $this->get_testable_mock(); $method = new \ReflectionMethod(file_system::class, 'get_imageinfo_from_path'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, [$filepath]); $this->assertFalse($result); @@ -949,7 +944,6 @@ class file_system_test extends \advanced_testcase { $fs = $this->get_testable_mock(); $method = new \ReflectionMethod(file_system::class, 'get_imageinfo_from_path'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, [$filepath]); $this->assertArrayHasKey('width', $result); @@ -971,7 +965,6 @@ class file_system_test extends \advanced_testcase { $fs = $this->get_testable_mock(); $method = new \ReflectionMethod(file_system::class, 'get_imageinfo_from_path'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, [$filepath]); $this->assertArrayHasKey('width', $result); @@ -993,7 +986,6 @@ class file_system_test extends \advanced_testcase { $fs = $this->get_testable_mock(); $method = new \ReflectionMethod(file_system::class, 'get_imageinfo_from_path'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, [$filepath]); $this->assertArrayHasKey('width', $result); @@ -1015,7 +1007,6 @@ class file_system_test extends \advanced_testcase { $fs = $this->get_testable_mock(); $method = new \ReflectionMethod(file_system::class, 'get_imageinfo_from_path'); - $method->setAccessible(true); $result = $method->invokeArgs($fs, [$filepath]); $this->assertFalse($result); diff --git a/lib/phpunit/classes/util.php b/lib/phpunit/classes/util.php index f12010d4769..86e8fa47cbe 100644 --- a/lib/phpunit/classes/util.php +++ b/lib/phpunit/classes/util.php @@ -973,7 +973,6 @@ class phpunit_util extends testing_util { public static function call_internal_method($object, $methodname, array $params, $classname) { $reflection = new \ReflectionClass($classname); $method = $reflection->getMethod($methodname); - $method->setAccessible(true); return $method->invokeArgs($object, $params); } diff --git a/lib/phpunit/tests/phpunit_dataset_test.php b/lib/phpunit/tests/phpunit_dataset_test.php index 4e0aa982f74..262ef52befb 100644 --- a/lib/phpunit/tests/phpunit_dataset_test.php +++ b/lib/phpunit/tests/phpunit_dataset_test.php @@ -54,11 +54,8 @@ class phpunit_dataset_test extends advanced_testcase { // We need public properties to check the basis. $dsref = new \ReflectionClass($ds); $dstables = $dsref->getProperty('tables'); - $dstables->setAccessible(true); $dscolumns = $dsref->getProperty('columns'); - $dscolumns->setAccessible(true); $dsrows = $dsref->getProperty('rows'); - $dsrows->setAccessible(true); // Expectations. $exptables = ['user', 'user2']; @@ -158,11 +155,8 @@ class phpunit_dataset_test extends advanced_testcase { // We need public properties to check the basis. $dsref = new \ReflectionClass($ds); $dstables = $dsref->getProperty('tables'); - $dstables->setAccessible(true); $dscolumns = $dsref->getProperty('columns'); - $dscolumns->setAccessible(true); $dsrows = $dsref->getProperty('rows'); - $dsrows->setAccessible(true); // We are expecting an exception. if (!empty($exception)) { @@ -251,11 +245,8 @@ class phpunit_dataset_test extends advanced_testcase { // We need public properties to check the basis. $dsref = new \ReflectionClass($ds); $dstables = $dsref->getProperty('tables'); - $dstables->setAccessible(true); $dscolumns = $dsref->getProperty('columns'); - $dscolumns->setAccessible(true); $dsrows = $dsref->getProperty('rows'); - $dsrows->setAccessible(true); // We are expecting an exception. if (!empty($exception)) { @@ -397,11 +388,8 @@ class phpunit_dataset_test extends advanced_testcase { // We need public properties to check the basis. $dsref = new \ReflectionClass($ds); $dstables = $dsref->getProperty('tables'); - $dstables->setAccessible(true); $dscolumns = $dsref->getProperty('columns'); - $dscolumns->setAccessible(true); $dsrows = $dsref->getProperty('rows'); - $dsrows->setAccessible(true); // We are expecting an exception. if (!empty($exception)) { @@ -491,11 +479,8 @@ class phpunit_dataset_test extends advanced_testcase { // We need public properties to check the basis. $dsref = new \ReflectionClass($ds); $dstables = $dsref->getProperty('tables'); - $dstables->setAccessible(true); $dscolumns = $dsref->getProperty('columns'); - $dscolumns->setAccessible(true); $dsrows = $dsref->getProperty('rows'); - $dsrows->setAccessible(true); // We are expecting an exception. if (!empty($exception)) { @@ -662,11 +647,8 @@ class phpunit_dataset_test extends advanced_testcase { // We need public properties to check the basis. $dsref = new \ReflectionClass($ds); $dstables = $dsref->getProperty('tables'); - $dstables->setAccessible(true); $dscolumns = $dsref->getProperty('columns'); - $dscolumns->setAccessible(true); $dsrows = $dsref->getProperty('rows'); - $dsrows->setAccessible(true); // We are expecting an exception. if (!empty($exception)) { diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index ba4f0f143ac..8b72994b1cc 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -1965,7 +1965,6 @@ class accesslib_test extends advanced_testcase { // the access.php works. $mockedcomponent = new ReflectionClass(core_component::class); $mockedplugins = $mockedcomponent->getProperty('plugins'); - $mockedplugins->setAccessible(true); $plugins = $mockedplugins->getValue(); $plugins['fake'] = [$pluginname => "{$CFG->dirroot}/lib/tests/fixtures/fakeplugins/$pluginname"]; $mockedplugins->setValue(null, $plugins); @@ -4877,7 +4876,6 @@ class accesslib_test extends advanced_testcase { ->getMock(); $rcp = new ReflectionProperty($context, '_path'); - $rcp->setAccessible(true); $rcp->setValue($context, $contextpath); $comparisoncontext = $this->getMockBuilder(\context::class) @@ -4889,7 +4887,6 @@ class accesslib_test extends advanced_testcase { ->getMock(); $rcp = new ReflectionProperty($comparisoncontext, '_path'); - $rcp->setAccessible(true); $rcp->setValue($comparisoncontext, $testpath); $this->assertEquals($expected, $context->is_parent_of($comparisoncontext, $testself)); @@ -4986,7 +4983,6 @@ class accesslib_test extends advanced_testcase { ->getMock(); $rcp = new ReflectionProperty($context, '_path'); - $rcp->setAccessible(true); $rcp->setValue($context, $contextpath); $comparisoncontext = $this->getMockBuilder(\context::class) @@ -4998,7 +4994,6 @@ class accesslib_test extends advanced_testcase { ->getMock(); $rcp = new ReflectionProperty($comparisoncontext, '_path'); - $rcp->setAccessible(true); $rcp->setValue($comparisoncontext, $testpath); $this->assertEquals($expected, $context->is_child_of($comparisoncontext, $testself)); diff --git a/lib/tests/analysers_test.php b/lib/tests/analysers_test.php index 1e5c3e813a8..875646c6b16 100644 --- a/lib/tests/analysers_test.php +++ b/lib/tests/analysers_test.php @@ -57,7 +57,6 @@ class analysers_test extends \advanced_testcase { // Just 1 sample per course. $class = new \ReflectionClass('\core\analytics\analyser\courses'); $method = $class->getMethod('get_all_samples'); - $method->setAccessible(true); list($sampleids, $samplesdata) = $method->invoke($analyser, $analysable); $this->assertCount(1, $sampleids); $sampleid = reset($sampleids); @@ -107,7 +106,6 @@ class analysers_test extends \advanced_testcase { $class = new \ReflectionClass('\core\analytics\analyser\site_courses'); $method = $class->getMethod('get_all_samples'); - $method->setAccessible(true); list($sampleids, $samplesdata) = $method->invoke($analyser, $analysable); $this->assertCount(3, $sampleids); @@ -159,7 +157,6 @@ class analysers_test extends \advanced_testcase { $class = new \ReflectionClass('\core\analytics\analyser\student_enrolments'); $method = $class->getMethod('get_all_samples'); - $method->setAccessible(true); list($sampleids, $samplesdata) = $method->invoke($analyser, $analysable); // Only students. $this->assertCount(2, $sampleids); diff --git a/lib/tests/client_test.php b/lib/tests/client_test.php index 2f6a7183847..66cdb3b7a7b 100644 --- a/lib/tests/client_test.php +++ b/lib/tests/client_test.php @@ -109,7 +109,6 @@ class client_test extends advanced_testcase { ]; $method = new ReflectionMethod("core\oauth2\client", "map_userinfo_to_fields"); - $method->setAccessible(true); $issuer = new \core\oauth2\issuer(0); $mockbuilder = $this->getMockBuilder('core\oauth2\client'); diff --git a/lib/tests/completionlib_test.php b/lib/tests/completionlib_test.php index ced754c46bf..fb0904bbb2d 100644 --- a/lib/tests/completionlib_test.php +++ b/lib/tests/completionlib_test.php @@ -966,7 +966,6 @@ class completionlib_test extends advanced_testcase { $completioninfo = new completion_info($this->course); $method = new ReflectionMethod("completion_info", "get_other_cm_completion_data"); - $method->setAccessible(true); // Check that fetching data for a module with custom completion provides its info. $choicecompletiondata = $method->invoke($completioninfo, $cmchoice, $user->id); @@ -1813,7 +1812,6 @@ class completionlib_test extends advanced_testcase { // We're testing a private method, so we need to setup reflector magic. $method = new ReflectionMethod($ccompletion, '_save'); - $method->setAccessible(true); // Allow accessing of private method. $completionid = $method->invoke($ccompletion); $completions = $DB->get_records('course_completions'); $this->assertEquals(count($completions), 1); @@ -1821,7 +1819,6 @@ class completionlib_test extends advanced_testcase { $ccompletion->id = 0; $method = new ReflectionMethod($ccompletion, '_save'); - $method->setAccessible(true); // Allow accessing of private method. $completionid = $method->invoke($ccompletion); $this->assertDebuggingCalled('Can not update data object, no id!'); $this->assertNull($completionid); diff --git a/lib/tests/component_test.php b/lib/tests/component_test.php index 5df2a1c34d8..d9c714cec5c 100644 --- a/lib/tests/component_test.php +++ b/lib/tests/component_test.php @@ -640,11 +640,9 @@ class component_test extends advanced_testcase { */ public function test_classloader($psr0, $psr4, $classname, $includedfiles): void { $psr0namespaces = new ReflectionProperty('core_component', 'psr0namespaces'); - $psr0namespaces->setAccessible(true); $psr0namespaces->setValue(null, $psr0); $psr4namespaces = new ReflectionProperty('core_component', 'psr4namespaces'); - $psr4namespaces->setAccessible(true); $psr4namespaces->setValue(null, $psr4); core_component::classloader($classname); @@ -775,16 +773,13 @@ class component_test extends advanced_testcase { */ public function test_psr_classloader($psr0, $psr4, $classname, $file): void { $psr0namespaces = new ReflectionProperty('core_component', 'psr0namespaces'); - $psr0namespaces->setAccessible(true); $psr0namespaces->setValue(null, $psr0); $psr4namespaces = new ReflectionProperty('core_component', 'psr4namespaces'); - $psr4namespaces->setAccessible(true); $psr4namespaces->setValue(null, $psr4); $component = new ReflectionClass('core_component'); $psrclassloader = $component->getMethod('psr_classloader'); - $psrclassloader->setAccessible(true); $returnvalue = $psrclassloader->invokeArgs(null, [$classname]); // Normalise to forward slashes for testing comparison. @@ -845,7 +840,6 @@ class component_test extends advanced_testcase { public function test_get_class_file($classname, $prefix, $path, $separators, $result): void { $component = new ReflectionClass('core_component'); $psrclassloader = $component->getMethod('get_class_file'); - $psrclassloader->setAccessible(true); $file = $psrclassloader->invokeArgs(null, [$classname, $prefix, $path, $separators]); $this->assertEquals($result, $file); diff --git a/lib/tests/core_renderer_template_exploit_test.php b/lib/tests/core_renderer_template_exploit_test.php index 771ad6be66a..992fa1f95bc 100644 --- a/lib/tests/core_renderer_template_exploit_test.php +++ b/lib/tests/core_renderer_template_exploit_test.php @@ -410,7 +410,6 @@ class core_renderer_template_exploit_test extends \advanced_testcase { // Get the mustache engine from the renderer. $reflection = new \ReflectionMethod($renderer, 'get_mustache'); - $reflection->setAccessible(true); $engine = $reflection->invoke($renderer); // Swap the loader out with an array loader so that we can set some diff --git a/lib/tests/external/check/get_result_admintree_test.php b/lib/tests/external/check/get_result_admintree_test.php index 5814e6c4a24..702e40acd40 100644 --- a/lib/tests/external/check/get_result_admintree_test.php +++ b/lib/tests/external/check/get_result_admintree_test.php @@ -227,7 +227,6 @@ class get_result_admintree_test extends externallib_advanced_testcase { $root = $this->setup_admin_tree($settings); $method = new ReflectionMethod(get_result_admintree::class, 'get_check_from_setting'); - $method->setAccessible(true); $result = $method->invoke(new get_result_admintree(), $searchid, $searchname, $root); diff --git a/lib/tests/filelib_test.php b/lib/tests/filelib_test.php index 1e3760a4bf2..6ed87509a20 100644 --- a/lib/tests/filelib_test.php +++ b/lib/tests/filelib_test.php @@ -2061,7 +2061,6 @@ class testable_curl extends curl { public function get_options() { // Access to private property. $rp = new \ReflectionProperty('curl', 'options'); - $rp->setAccessible(true); return $rp->getValue($this); } @@ -2073,7 +2072,6 @@ class testable_curl extends curl { public function set_options($options) { // Access to private property. $rp = new \ReflectionProperty('curl', 'options'); - $rp->setAccessible(true); $rp->setValue($this, $options); } @@ -2107,7 +2105,6 @@ class testable_curl extends curl { public function call_apply_opt($options = null) { // Access to private method. $rm = new \ReflectionMethod('curl', 'apply_opt'); - $rm->setAccessible(true); $ch = curl_init(); return $rm->invoke($this, $ch, $options); } diff --git a/lib/tests/filestorage_zip_archive_test.php b/lib/tests/filestorage_zip_archive_test.php index 06eb9db2fed..7ed42499503 100644 --- a/lib/tests/filestorage_zip_archive_test.php +++ b/lib/tests/filestorage_zip_archive_test.php @@ -44,7 +44,6 @@ class filestorage_zip_archive_test extends \advanced_testcase { $ziparchive = new zip_archive(); $method = new \ReflectionMethod('zip_archive', 'mangle_pathname'); - $method->setAccessible(true); $result = $method->invoke($ziparchive, $string); $this->assertSame($expected, $result); diff --git a/lib/tests/http_client_test.php b/lib/tests/http_client_test.php index 8d405ff9a46..b5cb24b97c5 100644 --- a/lib/tests/http_client_test.php +++ b/lib/tests/http_client_test.php @@ -57,12 +57,10 @@ class http_client_test extends \advanced_testcase { return $object->$attributename; } - $attribute->setAccessible(true); try { return $attribute->getValue($object); } finally { - $attribute->setAccessible(false); } } catch (\ReflectionException $e) { // Do nothing. diff --git a/lib/tests/medialib_test.php b/lib/tests/medialib_test.php index e95bda6f679..c5eddec9fe7 100644 --- a/lib/tests/medialib_test.php +++ b/lib/tests/medialib_test.php @@ -475,7 +475,6 @@ class medialib_test extends \advanced_testcase { */ public function get_players_test($manager) { $method = new \ReflectionMethod("core_media_manager", "get_players"); - $method->setAccessible(true); $players = $method->invoke($manager); $out = ''; foreach ($players as $player) { diff --git a/lib/tests/moodlenet/activity_packager_test.php b/lib/tests/moodlenet/activity_packager_test.php index c14ecfd9f94..e290c6c8e6b 100644 --- a/lib/tests/moodlenet/activity_packager_test.php +++ b/lib/tests/moodlenet/activity_packager_test.php @@ -54,10 +54,8 @@ class activity_packager_test extends \advanced_testcase { // Fetch all backup task settings. $rc = new \ReflectionClass(activity_packager::class); $rcmgetbackup = $rc->getMethod('get_backup_controller'); - $rcmgetbackup->setAccessible(true); $controller = $rcmgetbackup->invoke($packager); $rcmgetall = $rc->getMethod('get_all_task_settings'); - $rcmgetall->setAccessible(true); $tasksettings = $rcmgetall->invoke($packager, $controller); // Fetch the default settings and grab an example value (setting_root_users). @@ -80,7 +78,6 @@ class activity_packager_test extends \advanced_testcase { // Override the setting_root_users value, then re-fetch the settings to check the change is reflected. $overridevalue = ($oldvalue == 1) ? 0 : 1; $rcmoverridesetting = $rc->getMethod('override_task_setting'); - $rcmoverridesetting->setAccessible(true); $rcmoverridesetting->invoke($packager, $tasksettings, $testsettingname, $overridevalue); $tasksettings = $rcmgetall->invoke($packager, $controller); $rootsettings = $tasksettings[\backup_root_task::class]; diff --git a/lib/tests/moodlenet/activity_sender_test.php b/lib/tests/moodlenet/activity_sender_test.php index 3c106b9f569..352d847f243 100644 --- a/lib/tests/moodlenet/activity_sender_test.php +++ b/lib/tests/moodlenet/activity_sender_test.php @@ -95,7 +95,6 @@ class activity_sender_test extends \advanced_testcase { // Set get_file method accessibility. $method = new ReflectionMethod(activity_sender::class, 'prepare_share_contents'); - $method->setAccessible(true); // Test with invalid share format. $this->expectException(\moodle_exception::class); @@ -157,7 +156,6 @@ class activity_sender_test extends \advanced_testcase { // Set get_resource_description method accessibility. $method = new ReflectionMethod(activity_sender::class, 'get_resource_description'); - $method->setAccessible(true); // Test the processed description. $processeddescription = $method->invoke(new activity_sender( diff --git a/lib/tests/moodlenet/course_packager_test.php b/lib/tests/moodlenet/course_packager_test.php index 780cc365539..96b1e9af1a4 100644 --- a/lib/tests/moodlenet/course_packager_test.php +++ b/lib/tests/moodlenet/course_packager_test.php @@ -49,10 +49,8 @@ class course_packager_test extends \advanced_testcase { // Fetch all backup task settings. $rc = new \ReflectionClass(course_packager::class); $rcmgetbackup = $rc->getMethod('get_backup_controller'); - $rcmgetbackup->setAccessible(true); $controller = $rcmgetbackup->invoke($packager); $rcmgetall = $rc->getMethod('get_all_task_settings'); - $rcmgetall->setAccessible(true); $tasksettings = $rcmgetall->invoke($packager, $controller); // Fetch the default settings and grab an example value (setting_root_users). @@ -75,7 +73,6 @@ class course_packager_test extends \advanced_testcase { // Override the setting_root_users value, then re-fetch the settings to check the change is reflected. $overridevalue = ($oldvalue == 1) ? 0 : 1; $rcmoverridesetting = $rc->getMethod('override_task_setting'); - $rcmoverridesetting->setAccessible(true); $rcmoverridesetting->invoke($packager, $tasksettings, $testsettingname, $overridevalue); $tasksettings = $rcmgetall->invoke($packager, $controller); $rootsettings = $tasksettings[\backup_root_task::class]; diff --git a/lib/tests/moodlenet/course_partial_packager_test.php b/lib/tests/moodlenet/course_partial_packager_test.php index 996769ee8eb..d94c42a71f5 100644 --- a/lib/tests/moodlenet/course_partial_packager_test.php +++ b/lib/tests/moodlenet/course_partial_packager_test.php @@ -51,11 +51,9 @@ class course_partial_packager_test extends \advanced_testcase { // Fetch all backup task settings. $rc = new \ReflectionClass(course_partial_packager::class); $rcmgetbackup = $rc->getMethod('get_backup_controller'); - $rcmgetbackup->setAccessible(true); $controller = $rcmgetbackup->invoke($packager); $rcmremove = $rc->getMethod('remove_unselected_activities'); - $rcmremove->setAccessible(true); $rcmremove->invoke($packager, $controller); // Fetch all backup task settings for asserting them. diff --git a/lib/tests/moodlenet/course_partial_sender_test.php b/lib/tests/moodlenet/course_partial_sender_test.php index 0fc86fc84e6..271720e0520 100644 --- a/lib/tests/moodlenet/course_partial_sender_test.php +++ b/lib/tests/moodlenet/course_partial_sender_test.php @@ -95,7 +95,6 @@ class course_partial_sender_test extends \advanced_testcase { // Set get_file method accessibility. $method = new ReflectionMethod(course_partial_sender::class, 'prepare_share_contents'); - $method->setAccessible(true); $httpclient = new http_client(); $moodlenetclient = new moodlenet_client($httpclient, $this->mockoauthclient); @@ -151,7 +150,6 @@ class course_partial_sender_test extends \advanced_testcase { // Set get_resource_description method accessibility. $method = new ReflectionMethod(course_partial_sender::class, 'get_resource_description'); - $method->setAccessible(true); // Test the processed description. $httpclient = new http_client(); diff --git a/lib/tests/moodlenet/course_sender_test.php b/lib/tests/moodlenet/course_sender_test.php index 3827e5fdeae..c6a9739be97 100644 --- a/lib/tests/moodlenet/course_sender_test.php +++ b/lib/tests/moodlenet/course_sender_test.php @@ -90,7 +90,6 @@ class course_sender_test extends \advanced_testcase { // Set get_file method accessibility. $method = new ReflectionMethod(course_sender::class, 'prepare_share_contents'); - $method->setAccessible(true); // Test with invalid share format. $this->expectException(\moodle_exception::class); @@ -158,7 +157,6 @@ class course_sender_test extends \advanced_testcase { // Set get_resource_description method accessibility. $method = new ReflectionMethod(course_sender::class, 'get_resource_description'); - $method->setAccessible(true); // Test the processed description. $httpclient = new http_client(); diff --git a/lib/tests/myprofilelib_test.php b/lib/tests/myprofilelib_test.php index a444ef28da2..fd7344f484b 100644 --- a/lib/tests/myprofilelib_test.php +++ b/lib/tests/myprofilelib_test.php @@ -66,7 +66,6 @@ class myprofilelib_test extends \advanced_testcase { core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $categories = $reflector->getProperty('categories'); - $categories->setAccessible(true); $cats = $categories->getValue($this->tree); $this->assertArrayHasKey('contact', $cats); $this->assertArrayHasKey('coursedetails', $cats); @@ -76,7 +75,6 @@ class myprofilelib_test extends \advanced_testcase { $this->assertArrayHasKey('loginactivity', $cats); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('fullprofile', $nodes->getValue($this->tree)); } @@ -92,7 +90,6 @@ class myprofilelib_test extends \advanced_testcase { core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('fullprofile', $nodes->getValue($this->tree)); } @@ -106,7 +103,6 @@ class myprofilelib_test extends \advanced_testcase { core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('editprofile', $nodes->getValue($this->tree)); } @@ -120,7 +116,6 @@ class myprofilelib_test extends \advanced_testcase { core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('editprofile', $nodes->getValue($this->tree)); } @@ -134,7 +129,6 @@ class myprofilelib_test extends \advanced_testcase { core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('preferences', $nodes->getValue($this->tree)); $this->assertArrayHasKey('loginas', $nodes->getValue($this->tree)); } @@ -151,7 +145,6 @@ class myprofilelib_test extends \advanced_testcase { core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('loginas', $nodes->getValue($this->tree)); } @@ -189,7 +182,6 @@ class myprofilelib_test extends \advanced_testcase { core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, null); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); foreach ($hiddenfields as $field) { $this->assertArrayHasKey($field, $nodes->getValue($this->tree)); } @@ -214,7 +206,6 @@ class myprofilelib_test extends \advanced_testcase { core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, null); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); foreach ($hiddenfields as $field) { $this->assertArrayNotHasKey($field, $nodes->getValue($this->tree)); } @@ -262,7 +253,6 @@ class myprofilelib_test extends \advanced_testcase { $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); /** @var \core_user\output\myprofile\node[] $tree */ $tree = $nodes->getValue($this->tree); @@ -286,7 +276,6 @@ class myprofilelib_test extends \advanced_testcase { core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, null); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('firstaccess', $nodes->getValue($this->tree)); $this->assertArrayHasKey('lastaccess', $nodes->getValue($this->tree)); $this->assertArrayHasKey('lastip', $nodes->getValue($this->tree)); @@ -305,7 +294,6 @@ class myprofilelib_test extends \advanced_testcase { core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, null); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('firstaccess', $nodes->getValue($this->tree)); $this->assertArrayNotHasKey('lastaccess', $nodes->getValue($this->tree)); $this->assertArrayNotHasKey('lastip', $nodes->getValue($this->tree)); diff --git a/lib/tests/navigation/output/primary_test.php b/lib/tests/navigation/output/primary_test.php index 649ff0cefe9..b542762f687 100644 --- a/lib/tests/navigation/output/primary_test.php +++ b/lib/tests/navigation/output/primary_test.php @@ -168,7 +168,6 @@ class primary_test extends \advanced_testcase { $CFG->custommenuitems = $config; $output = new primary($PAGE); $method = new ReflectionMethod('core\navigation\output\primary', 'get_custom_menu'); - $method->setAccessible(true); $renderer = $PAGE->get_renderer('core'); // We can't assert the value of each menuitem "moremenuid" property (because it's random). @@ -375,7 +374,6 @@ class primary_test extends \advanced_testcase { $primary = new primary($PAGE); $method = new ReflectionMethod('core\navigation\output\primary', 'get_primary_nav'); - $method->setAccessible(true); $dataprimary = $method->invoke($primary); // Take this custom menu that would come from the setting custommenitems. @@ -395,7 +393,6 @@ class primary_test extends \advanced_testcase { $datacustom = $this->get_custom_menu($custommenuitems); $method = new ReflectionMethod('core\navigation\output\primary', 'merge_primary_and_custom'); - $method->setAccessible(true); $menucomplete = $method->invoke($primary, $dataprimary, $datacustom, $ismobile); return $menucomplete; } diff --git a/lib/tests/navigation/views/primary_test.php b/lib/tests/navigation/views/primary_test.php index 2551a9031b6..7e210bb8063 100644 --- a/lib/tests/navigation/views/primary_test.php +++ b/lib/tests/navigation/views/primary_test.php @@ -126,7 +126,6 @@ class primary_test extends \advanced_testcase { $primary = new primary($PAGE); $method = new ReflectionMethod('core\navigation\views\primary', 'search_and_set_active_node'); - $method->setAccessible(true); $result = $method->invoke($primary, $node); diff --git a/lib/tests/navigation/views/secondary_test.php b/lib/tests/navigation/views/secondary_test.php index 619f295293d..c99253ffd59 100644 --- a/lib/tests/navigation/views/secondary_test.php +++ b/lib/tests/navigation/views/secondary_test.php @@ -63,7 +63,6 @@ class secondary_test extends \advanced_testcase { ]; $method = new ReflectionMethod('core\navigation\views\secondary', 'get_leaf_nodes'); - $method->setAccessible(true); $sortednodes = $method->invoke($secondary, $secondary, $nodes); foreach ($sortednodes as $order => $node) { $this->assertEquals($expectednodes[$order], $node->key); @@ -216,7 +215,6 @@ class secondary_test extends \advanced_testcase { $node = $this->get_tree_initilised_to_set_activate($seturl); $secondary = new secondary($PAGE); $method = new ReflectionMethod('core\navigation\views\secondary', 'active_node_scan'); - $method->setAccessible(true); $result = $method->invoke($secondary, $node); @@ -274,7 +272,6 @@ class secondary_test extends \advanced_testcase { } $method = new ReflectionMethod('core\navigation\views\secondary', 'force_nodes_into_more_menu'); - $method->setAccessible(true); $method->invoke($secondary, $defaultmoremenunodes, $maxdisplayednodes); $actualmoremenunodes = []; @@ -465,7 +462,6 @@ class secondary_test extends \advanced_testcase { $PAGE->set_url($selectedurl); $secondary = new secondary($PAGE); $method = new ReflectionMethod('core\navigation\views\secondary', 'nodes_match_current_url'); - $method->setAccessible(true); $response = $method->invoke($secondary, $node); $this->assertSame($response->key ?? null, $expectednode); @@ -630,7 +626,6 @@ class secondary_test extends \advanced_testcase { $secondary = new secondary($PAGE); $method = new ReflectionMethod('core\navigation\views\secondary', 'get_node_with_first_action'); - $method->setAccessible(true); $response = $method->invoke($secondary, $selectednode, $selectednode); $this->assertEquals($expected, $response); } @@ -688,7 +683,6 @@ class secondary_test extends \advanced_testcase { } $method = new ReflectionMethod('core\navigation\views\secondary', 'add_external_nodes_to_secondary'); - $method->setAccessible(true); $method->invoke($secondary, $firstnode, $firstnode, $customparent); $actualnodes = $separatenode ? $customparent->get_children_key_list() : $secondary->get_children_key_list(); @@ -850,12 +844,10 @@ class secondary_test extends \advanced_testcase { } else { // Set the correct node as active. $method = new ReflectionMethod('core\navigation\views\secondary', 'scan_for_active_node'); - $method->setAccessible(true); $method->invoke($secondary, $secondary); } $method = new ReflectionMethod('core\navigation\views\secondary', 'get_overflow_menu_data'); - $method->setAccessible(true); $response = $method->invoke($secondary); if ($expectednull) { $this->assertNull($response); diff --git a/lib/tests/output/language_menu_test.php b/lib/tests/output/language_menu_test.php index 7587227f8f3..b7f9f82d930 100644 --- a/lib/tests/output/language_menu_test.php +++ b/lib/tests/output/language_menu_test.php @@ -61,7 +61,6 @@ class language_menu_test extends \advanced_testcase { $output = new language_menu($PAGE); $method = new ReflectionMethod('\core\output\language_menu', 'export_for_template'); - $method->setAccessible(true); $renderer = $PAGE->get_renderer('core'); $response = $method->invoke($output, $renderer); diff --git a/lib/tests/output/participants_action_bar_test.php b/lib/tests/output/participants_action_bar_test.php index 6a1468ec556..9c85e5358fb 100644 --- a/lib/tests/output/participants_action_bar_test.php +++ b/lib/tests/output/participants_action_bar_test.php @@ -57,7 +57,6 @@ class participants_action_bar_test extends \advanced_testcase { $PAGE->set_context($context); $output = new participants_action_bar($course, $PAGE, null); $method = new ReflectionMethod('\core\output\participants_action_bar', 'get_content_for_select'); - $method->setAccessible(true); $renderer = $PAGE->get_renderer('core'); $response = $method->invoke($output, $renderer); diff --git a/lib/tests/outputrequirementslib_test.php b/lib/tests/outputrequirementslib_test.php index 28e8bced8db..a0d9a8507c6 100644 --- a/lib/tests/outputrequirementslib_test.php +++ b/lib/tests/outputrequirementslib_test.php @@ -155,7 +155,6 @@ class outputrequirementslib_test extends \advanced_testcase { $CFG->slasharguments = $cfgslashargs; $rc = new \ReflectionClass(\page_requirements_manager::class); $rcm = $rc->getMethod('js_fix_url'); - $rcm->setAccessible(true); $requires = new \page_requirements_manager(); $actualmoodleurl = $rcm->invokeArgs($requires, [$moodleurl]); $this->assertEquals($expected, $actualmoodleurl->out(false)); @@ -239,7 +238,6 @@ class outputrequirementslib_test extends \advanced_testcase { $CFG->slasharguments = $cfgslashargs; $rc = new \ReflectionClass(\page_requirements_manager::class); $rcm = $rc->getMethod('js_fix_url'); - $rcm->setAccessible(true); $requires = new \page_requirements_manager(); $actualmoodleurl = $rcm->invokeArgs($requires, [$url]); $this->assertEquals($expected, $actualmoodleurl->out(false)); @@ -316,7 +314,6 @@ class outputrequirementslib_test extends \advanced_testcase { public function test_js_fix_url_coding_exception($url, string $exmessage) { $rc = new \ReflectionClass(\page_requirements_manager::class); $rcm = $rc->getMethod('js_fix_url'); - $rcm->setAccessible(true); $requires = new \page_requirements_manager(); $this->expectException(\coding_exception::class); $this->expectExceptionMessage($exmessage); diff --git a/lib/tests/session_manager_test.php b/lib/tests/session_manager_test.php index ad84b7f18cc..34239875caa 100644 --- a/lib/tests/session_manager_test.php +++ b/lib/tests/session_manager_test.php @@ -916,7 +916,6 @@ class session_manager_test extends \advanced_testcase { public function test_array_session_diff(array $a, array $b, array $expected) { $class = new \ReflectionClass('\core\session\manager'); $method = $class->getMethod('array_session_diff'); - $method->setAccessible(true); $result = $method->invokeArgs(null, [$a, $b]); $this->assertSame($expected, $result); diff --git a/lib/tests/session_redis_test.php b/lib/tests/session_redis_test.php index a77a3375f00..4d5af406a85 100644 --- a/lib/tests/session_redis_test.php +++ b/lib/tests/session_redis_test.php @@ -368,7 +368,6 @@ class session_redis_test extends \advanced_testcase { $sess = new \core\session\redis(); $prop = new \ReflectionProperty(\core\session\redis::class, 'host'); - $prop->setAccessible(true); $this->assertEquals('tls://' . TEST_SESSION_REDIS_HOST, $prop->getValue($sess)); } } diff --git a/lib/tests/setuplib_test.php b/lib/tests/setuplib_test.php index 0ef30f714a0..75413706af8 100644 --- a/lib/tests/setuplib_test.php +++ b/lib/tests/setuplib_test.php @@ -491,7 +491,6 @@ class setuplib_test extends \advanced_testcase { // The \core\uuid::generate_uuid_via_pecl_uuid_extension static method is protected. Use Reflection to call the method. $method = new \ReflectionMethod('\core\uuid', 'generate_uuid_via_pecl_uuid_extension'); - $method->setAccessible(true); $uuid = $method->invoke(null); $this->assertTrue(self::is_valid_uuid_v4($uuid), "Invalid v4 uuid: '$uuid'"); } @@ -508,7 +507,6 @@ class setuplib_test extends \advanced_testcase { // The \core\uuid::generate_uuid_via_random_bytes static method is protected. Use Reflection to call the method. $method = new \ReflectionMethod('\core\uuid', 'generate_uuid_via_random_bytes'); - $method->setAccessible(true); $uuid = $method->invoke(null); $this->assertTrue(self::is_valid_uuid_v4($uuid), "Invalid v4 uuid: '$uuid'"); } diff --git a/lib/tests/xhprof_test.php b/lib/tests/xhprof_test.php index 60ccbf910db..43fd556fda6 100644 --- a/lib/tests/xhprof_test.php +++ b/lib/tests/xhprof_test.php @@ -180,7 +180,6 @@ class xhprof_test extends \advanced_testcase { // Make moodle_xhprofrun::xhprof_topo_sort() accessible. $reflection = new \ReflectionClass('\moodle_xhprofrun'); $method = $reflection->getMethod('xhprof_topo_sort'); - $method->setAccessible(true); // Sort the data. $result = $method->invokeArgs(new \moodle_xhprofrun(), [$rundata]); $this->assertIsArray($result); @@ -227,7 +226,6 @@ class xhprof_test extends \advanced_testcase { // Make moodle_xhprofrun::reduce_run_data() accessible. $reflection = new \ReflectionClass('\moodle_xhprofrun'); $method = $reflection->getMethod('reduce_run_data'); - $method->setAccessible(true); // Reduce the data. $result = $method->invokeArgs(new \moodle_xhprofrun(), [$rundata]); $this->assertIsArray($result); diff --git a/mod/assign/feedback/editpdf/tests/document_services_test.php b/mod/assign/feedback/editpdf/tests/document_services_test.php index e39ec8accf0..7a62ef51a40 100644 --- a/mod/assign/feedback/editpdf/tests/document_services_test.php +++ b/mod/assign/feedback/editpdf/tests/document_services_test.php @@ -51,7 +51,6 @@ class document_services_test extends advanced_testcase { $this->getDataGenerator()->enrol_user($user->id, $course->id, 'student'); $method = new ReflectionMethod('\assignfeedback_editpdf\document_services', 'save_file'); - $method->setAccessible(true); $filearea = document_services::TMP_ROTATED_JPG_FILEAREA; $content = 'some random content'; @@ -82,7 +81,6 @@ class document_services_test extends advanced_testcase { $this->getDataGenerator()->enrol_user($user->id, $course->id, 'student'); $method = new ReflectionMethod('\assignfeedback_editpdf\document_services', 'save_rotated_image_file'); - $method->setAccessible(true); $imagecontent = file_get_contents($CFG->dirroot . '/lib/filestorage/tests/fixtures/testimage.png'); $imageresource = imagecreatefromstring($imagecontent); diff --git a/mod/assign/tests/downloader_test.php b/mod/assign/tests/downloader_test.php index d7716ec5113..fa80c4c5d80 100644 --- a/mod/assign/tests/downloader_test.php +++ b/mod/assign/tests/downloader_test.php @@ -134,7 +134,6 @@ class downloader_test extends \advanced_testcase { // Expose protected filelist attribute. $rc = new \ReflectionClass(downloader::class); $rcp = $rc->getProperty('filesforzipping'); - $rcp->setAccessible(true); // Add some replacements. $search = ['PARTICIPANT', 'DEFAULTTEAM']; diff --git a/mod/assign/tests/locallib_participants_test.php b/mod/assign/tests/locallib_participants_test.php index 7656238ac7f..6b7842c7441 100644 --- a/mod/assign/tests/locallib_participants_test.php +++ b/mod/assign/tests/locallib_participants_test.php @@ -168,7 +168,6 @@ class locallib_participants_test extends \advanced_testcase { $rc = new \ReflectionClass('assign'); $rcm = $rc->getMethod('update_submission'); - $rcm->setAccessible(true); $rcm->invokeArgs($assign, [$submission, $user->id, true, false]); $plugin = $assign->get_submission_plugin_by_type($type); diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index 0340c190f9e..144bc13d474 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -4015,7 +4015,6 @@ Anchor link 2:Link text // Call fix_null_grades(). $method = new \ReflectionMethod(\assign::class, 'fix_null_grades'); - $method->setAccessible(true); $result = $method->invoke($assign); $this->assertSame(true, $result); diff --git a/mod/bigbluebuttonbn/classes/test/subplugins_test_helper_trait.php b/mod/bigbluebuttonbn/classes/test/subplugins_test_helper_trait.php index 4844865a763..f2305d33dc0 100644 --- a/mod/bigbluebuttonbn/classes/test/subplugins_test_helper_trait.php +++ b/mod/bigbluebuttonbn/classes/test/subplugins_test_helper_trait.php @@ -49,27 +49,22 @@ trait subplugins_test_helper_trait { $mockedcomponent = new ReflectionClass(core_component::class); $mockedplugins = $mockedcomponent->getProperty('plugins'); - $mockedplugins->setAccessible(true); $plugins = $mockedplugins->getValue(); $plugins[extension::BBB_EXTENSION_PLUGIN_NAME] = [$pluginname => $bbbextpath . "/$pluginname"]; $mockedplugins->setValue(null, $plugins); $mockedplugintypes = $mockedcomponent->getProperty('plugintypes'); - $mockedplugintypes->setAccessible(true); $pluginstypes = $mockedplugintypes->getValue(); $pluginstypes[extension::BBB_EXTENSION_PLUGIN_NAME] = $bbbextpath; $mockedplugintypes->setValue(null, $pluginstypes); $fillclassmap = $mockedcomponent->getMethod('fill_classmap_cache'); - $fillclassmap->setAccessible(true); $fillclassmap->invoke(null); $fillfilemap = $mockedcomponent->getMethod('fill_filemap_cache'); - $fillfilemap->setAccessible(true); $fillfilemap->invoke(null); $mockedsubplugins = $mockedcomponent->getProperty('subplugins'); - $mockedsubplugins->setAccessible(true); $subplugins = $mockedsubplugins->getValue(); $subplugins['mod_bigbluebuttonbn'][extension::BBB_EXTENSION_PLUGIN_NAME][] = $pluginname; $mockedsubplugins->setValue(null, $subplugins); @@ -148,10 +143,8 @@ trait subplugins_test_helper_trait { $mockedcomponent = new ReflectionClass(core_component::class); // Here we reset the plugin caches. $mockedplugintypes = $mockedcomponent->getProperty('plugintypes'); - $mockedplugintypes->setAccessible(true); $mockedplugintypes->setValue(null, null); $fillclassmap = $mockedcomponent->getMethod('init'); - $fillclassmap->setAccessible(true); $fillclassmap->invoke(null); // Now uninstall the plugin and clean everything up for other tests. diff --git a/mod/bigbluebuttonbn/tests/behat/behat_mod_bigbluebuttonbn.php b/mod/bigbluebuttonbn/tests/behat/behat_mod_bigbluebuttonbn.php index 5bda0afbd36..ffe5bd69513 100644 --- a/mod/bigbluebuttonbn/tests/behat/behat_mod_bigbluebuttonbn.php +++ b/mod/bigbluebuttonbn/tests/behat/behat_mod_bigbluebuttonbn.php @@ -262,10 +262,8 @@ XPATH $this->setup_fake_plugin("simple"); $mockedcomponent = new ReflectionClass(core_component::class); $mockedplugintypes = $mockedcomponent->getProperty('plugintypes'); - $mockedplugintypes->setAccessible(true); $mockedplugintypes->setValue(null, null); $init = $mockedcomponent->getMethod('init'); - $init->setAccessible(true); $init->invoke(null); // I enable the plugin. $manager = core_plugin_manager::resolve_plugininfo_class(\mod_bigbluebuttonbn\extension::BBB_EXTENSION_PLUGIN_NAME); diff --git a/mod/bigbluebuttonbn/tests/instance_test.php b/mod/bigbluebuttonbn/tests/instance_test.php index 194b3c9aac3..6788f1e2ae9 100644 --- a/mod/bigbluebuttonbn/tests/instance_test.php +++ b/mod/bigbluebuttonbn/tests/instance_test.php @@ -632,7 +632,6 @@ class instance_test extends advanced_testcase { $instance = instance::get_from_instanceid($record->id); $instancereflection = new \ReflectionClass($instance); $getinstanceinforetriever = $instancereflection->getMethod('get_instance_info_retriever'); - $getinstanceinforetriever->setAccessible(true); $this->assertInstanceOf('\mod_bigbluebuttonbn\instance', $getinstanceinforetriever->invoke($instance, $record->id, instance::IDTYPE_INSTANCEID)); $this->assertEquals($cm->id, $instance->get_cm_id()); diff --git a/mod/bigbluebuttonbn/tests/lib_test.php b/mod/bigbluebuttonbn/tests/lib_test.php index b54be9fee76..ae24f29bba8 100644 --- a/mod/bigbluebuttonbn/tests/lib_test.php +++ b/mod/bigbluebuttonbn/tests/lib_test.php @@ -432,7 +432,6 @@ class lib_test extends \advanced_testcase { $form = new mod_bigbluebuttonbn_mod_form($data, 1, $bbactivitycm, $this->get_course()); $refclass = new ReflectionClass("mod_bigbluebuttonbn_mod_form"); $formprop = $refclass->getProperty('_form'); - $formprop->setAccessible(true); /* @var $mform MoodleQuickForm quickform object definition */ $mform = $formprop->getValue($form); diff --git a/mod/bigbluebuttonbn/tests/local/extension_test.php b/mod/bigbluebuttonbn/tests/local/extension_test.php index 51d5460f111..02561cb7bd5 100644 --- a/mod/bigbluebuttonbn/tests/local/extension_test.php +++ b/mod/bigbluebuttonbn/tests/local/extension_test.php @@ -76,7 +76,6 @@ class extension_test extends \advanced_testcase { // Make the method public so we can test it. $reflectionextension = new \ReflectionClass(extension::class); $getclassimplementing = $reflectionextension->getMethod('get_instances_implementing'); - $getclassimplementing->setAccessible(true); $allfoundinstances = $getclassimplementing->invoke(null, $apiclass); $foundclasses = array_map( function($instance) { diff --git a/mod/bigbluebuttonbn/tests/local/proxy/proxy_base_test.php b/mod/bigbluebuttonbn/tests/local/proxy/proxy_base_test.php index 7aba2c0be49..d019498959b 100644 --- a/mod/bigbluebuttonbn/tests/local/proxy/proxy_base_test.php +++ b/mod/bigbluebuttonbn/tests/local/proxy/proxy_base_test.php @@ -86,7 +86,6 @@ class proxy_base_test extends \advanced_testcase { protected static function get_status() { $rc = new \ReflectionClass(proxy_base::class); $rcm = $rc->getMethod('fetch_endpoint_xml'); - $rcm->setAccessible(true); return $rcm->invoke(null, ''); } } diff --git a/mod/bigbluebuttonbn/tests/task/base_send_notification_test.php b/mod/bigbluebuttonbn/tests/task/base_send_notification_test.php index fd9320d6377..2515ea008c0 100644 --- a/mod/bigbluebuttonbn/tests/task/base_send_notification_test.php +++ b/mod/bigbluebuttonbn/tests/task/base_send_notification_test.php @@ -54,7 +54,6 @@ class base_send_notification_test extends advanced_testcase { $rc = new \ReflectionClass(base_send_notification::class); $rcm = $rc->getMethod('get_instance'); - $rcm->setAccessible(true); $instance = $rcm->invoke($stub); $this->assertEquals($instancedata->id, $instance->get_instance_id()); diff --git a/mod/data/lib.php b/mod/data/lib.php index 10465c593d9..1cd71f23bb7 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -3347,7 +3347,6 @@ function data_presets_generate_xml($course, $cm, $data) { $preset = preset::create_from_instance($manager, $data->name); $reflection = new \ReflectionClass(preset::class); $method = $reflection->getMethod('generate_preset_xml'); - $method->setAccessible(true); return $method->invokeArgs($preset, []); } diff --git a/mod/data/tests/preset_test.php b/mod/data/tests/preset_test.php index 37f98566703..397b7876021 100644 --- a/mod/data/tests/preset_test.php +++ b/mod/data/tests/preset_test.php @@ -567,7 +567,6 @@ class preset_test extends \advanced_testcase { // Make accessible the method. $reflection = new \ReflectionClass(preset::class); $method = $reflection->getMethod('generate_preset_xml'); - $method->setAccessible(true); // The method should return empty string when trying to generate preset.xml for a plugin preset. $preset = preset::create_from_plugin(null, 'imagegallery'); diff --git a/mod/feedback/tests/item_test.php b/mod/feedback/tests/item_test.php index 8541f5a71c2..6be7eeb44aa 100644 --- a/mod/feedback/tests/item_test.php +++ b/mod/feedback/tests/item_test.php @@ -58,7 +58,6 @@ class item_test extends advanced_testcase { $itemclass = feedback_get_item_class('textarea'); $reflection = new ReflectionClass($itemclass); $method = $reflection->getMethod('get_analysed'); - $method->setAccessible(true); // Call the method and indicate it is being used for Excel. $actual = $method->invoke(new $itemclass(), $item, false, $course->id, true); diff --git a/mod/forum/tests/lib_test.php b/mod/forum/tests/lib_test.php index 2624f053abe..a3173056669 100644 --- a/mod/forum/tests/lib_test.php +++ b/mod/forum/tests/lib_test.php @@ -2866,7 +2866,6 @@ class lib_test extends \advanced_testcase { mod_forum_myprofile_navigation($tree, $user, $iscurrentuser, $course); $reflector = new \ReflectionObject($tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('forumposts', $nodes->getValue($tree)); $this->assertArrayHasKey('forumdiscussions', $nodes->getValue($tree)); } @@ -2891,7 +2890,6 @@ class lib_test extends \advanced_testcase { mod_forum_myprofile_navigation($tree, $USER, $iscurrentuser, $course); $reflector = new \ReflectionObject($tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('forumposts', $nodes->getValue($tree)); $this->assertArrayNotHasKey('forumdiscussions', $nodes->getValue($tree)); } @@ -2916,7 +2914,6 @@ class lib_test extends \advanced_testcase { mod_forum_myprofile_navigation($tree, $user, $iscurrentuser, $course); $reflector = new \ReflectionObject($tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('forumposts', $nodes->getValue($tree)); $this->assertArrayHasKey('forumdiscussions', $nodes->getValue($tree)); } diff --git a/mod/h5pactivity/tests/output/result/result_test.php b/mod/h5pactivity/tests/output/result/result_test.php index 64184abd78f..b33ee1fc1df 100644 --- a/mod/h5pactivity/tests/output/result/result_test.php +++ b/mod/h5pactivity/tests/output/result/result_test.php @@ -207,12 +207,10 @@ class result_test extends \advanced_testcase { $reflectionoutput = new \ReflectionClass($classname); $constructor = $reflectionoutput->getConstructor(); - $constructor->setAccessible(true); $resultoutput = $reflectionoutput->newInstanceWithoutConstructor(); $constructor->invoke($resultoutput, $result->get_data()); $exportoptions = $reflectionoutput->getMethod('export_options'); - $exportoptions->setAccessible(true); $data = $exportoptions->invoke($resultoutput); $useranswersdata = array_map(function($item) { diff --git a/mod/h5pactivity/tests/xapi/handler_test.php b/mod/h5pactivity/tests/xapi/handler_test.php index 02880e0c9da..fcaa807a885 100644 --- a/mod/h5pactivity/tests/xapi/handler_test.php +++ b/mod/h5pactivity/tests/xapi/handler_test.php @@ -421,7 +421,6 @@ class handler_test extends \advanced_testcase { $handler = handler::create($component); // Change the method visibility for validate_state in order to test it. $method = new \ReflectionMethod(handler::class, 'validate_state'); - $method->setAccessible(true); // The activity id should be numeric. $state = test_helper::create_state(['activity' => item_activity::create_from_id('AA')]); diff --git a/mod/quiz/accessrule/seb/tests/access_manager_test.php b/mod/quiz/accessrule/seb/tests/access_manager_test.php index 610c2c3f5e0..44bcfe5ca6f 100644 --- a/mod/quiz/accessrule/seb/tests/access_manager_test.php +++ b/mod/quiz/accessrule/seb/tests/access_manager_test.php @@ -55,7 +55,6 @@ class access_manager_test extends \advanced_testcase { $reflection = new \ReflectionClass('\quizaccess_seb\seb_access_manager'); $property = $reflection->getProperty('quizsettings'); - $property->setAccessible(true); $this->assertFalse($property->getValue($accessmanager)); } diff --git a/mod/quiz/accessrule/seb/tests/rule_test.php b/mod/quiz/accessrule/seb/tests/rule_test.php index 651bfa2c983..6da48695a3f 100644 --- a/mod/quiz/accessrule/seb/tests/rule_test.php +++ b/mod/quiz/accessrule/seb/tests/rule_test.php @@ -999,7 +999,6 @@ class rule_test extends \advanced_testcase { $reflection = new \ReflectionClass('quizaccess_seb'); $method = $reflection->getMethod('get_download_seb_button'); - $method->setAccessible(true); // The current default contents. $this->assertStringContainsString($this->get_seb_download_link(), $method->invoke($this->make_rule())); @@ -1022,7 +1021,6 @@ class rule_test extends \advanced_testcase { $reflection = new \ReflectionClass('quizaccess_seb'); $method = $reflection->getMethod('get_action_buttons'); - $method->setAccessible(true); $this->assertStringContainsString($this->get_seb_download_link(), $method->invoke($this->make_rule())); @@ -1042,7 +1040,6 @@ class rule_test extends \advanced_testcase { $reflection = new \ReflectionClass('quizaccess_seb'); $method = $reflection->getMethod('get_action_buttons'); - $method->setAccessible(true); $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]); @@ -1084,7 +1081,6 @@ class rule_test extends \advanced_testcase { $reflection = new \ReflectionClass('quizaccess_seb'); $method = $reflection->getMethod('get_action_buttons'); - $method->setAccessible(true); set_config('showseblinks', 'seb,http', 'quizaccess_seb'); $this->assertStringContainsString($this->get_seb_launch_link(), $method->invoke($this->make_rule())); @@ -1118,7 +1114,6 @@ class rule_test extends \advanced_testcase { // Set-up the button to be called. $reflection = new \ReflectionClass('quizaccess_seb'); $method = $reflection->getMethod('get_quit_button'); - $method->setAccessible(true); $button = $method->invoke($this->make_rule()); $this->assertStringContainsString("http://test.quit.link", $button); @@ -1205,7 +1200,6 @@ class rule_test extends \advanced_testcase { // We will check if we show only fake blocks. Which means no other blocks on a page. $reflection = new \ReflectionClass('block_manager'); $property = $reflection->getProperty('fakeblocksonly'); - $property->setAccessible(true); $this->assertFalse($property->getValue($PAGE->blocks)); @@ -1241,7 +1235,6 @@ class rule_test extends \advanced_testcase { // We will check if we show only fake blocks. Which means no other blocks on a page. $reflection = new \ReflectionClass('block_manager'); $property = $reflection->getProperty('fakeblocksonly'); - $property->setAccessible(true); $this->assertFalse($property->getValue($PAGE->blocks)); diff --git a/mod/quiz/classes/adminpresets/adminpresets_review_setting.php b/mod/quiz/classes/adminpresets/adminpresets_review_setting.php index e365bc22c56..7893e0a4a65 100644 --- a/mod/quiz/classes/adminpresets/adminpresets_review_setting.php +++ b/mod/quiz/classes/adminpresets/adminpresets_review_setting.php @@ -36,7 +36,6 @@ class adminpresets_review_setting extends adminpresets_setting { // Getting the masks descriptions (review_setting protected method). $reflectiontimes = new ReflectionMethod('mod_quiz\admin\review_setting', 'times'); - $reflectiontimes->setAccessible(true); $times = $reflectiontimes->invoke(null); $visiblevalue = ''; diff --git a/mod/quiz/report/overview/tests/report_test.php b/mod/quiz/report/overview/tests/report_test.php index f7b13bb244e..4372a41e9fc 100644 --- a/mod/quiz/report/overview/tests/report_test.php +++ b/mod/quiz/report/overview/tests/report_test.php @@ -230,7 +230,6 @@ class report_test extends \advanced_testcase { $reflectionobject = $parent; } $prefsproperty = $reflectionobject->getProperty('prefs'); - $prefsproperty->setAccessible(true); $prefs = $prefsproperty->getValue($table); $prefs['i_first'] = 'A'; $prefsproperty->setValue($table, $prefs); diff --git a/mod/quiz/report/statistics/tests/quiz_statistics_report_test.php b/mod/quiz/report/statistics/tests/quiz_statistics_report_test.php index 0170a3769fe..8e32faee8b2 100644 --- a/mod/quiz/report/statistics/tests/quiz_statistics_report_test.php +++ b/mod/quiz/report/statistics/tests/quiz_statistics_report_test.php @@ -79,7 +79,6 @@ class quiz_statistics_report_test extends \advanced_testcase { } $reflectiondb = new \ReflectionProperty($lockfactory, 'db'); - $reflectiondb->setAccessible(true); $reflectiondb->setValue($lockfactory, self::$lockdb); self::$lockfactory = $lockfactory; } diff --git a/mod/quiz/report/statistics/tests/statistics_table_test.php b/mod/quiz/report/statistics/tests/statistics_table_test.php index 1169112d545..1161026012c 100644 --- a/mod/quiz/report/statistics/tests/statistics_table_test.php +++ b/mod/quiz/report/statistics/tests/statistics_table_test.php @@ -39,7 +39,6 @@ class statistics_table_test extends \advanced_testcase { // The format_percentage method is protected. Use Reflection to call the method. $reflector = new \ReflectionClass('quiz_statistics_table'); $method = $reflector->getMethod('format_percentage'); - $method->setAccessible(true); $this->assertEquals( '84.758%', @@ -58,7 +57,6 @@ class statistics_table_test extends \advanced_testcase { // The format_percentage_range method is protected. Use Reflection to call the method. $reflector = new \ReflectionClass('quiz_statistics_table'); $method = $reflector->getMethod('format_percentage_range'); - $method->setAccessible(true); $this->assertEquals( '54.400% − 84.758%', @@ -77,7 +75,6 @@ class statistics_table_test extends \advanced_testcase { // The format_range method is protected. Use Reflection to call the method. $reflector = new \ReflectionClass('quiz_statistics_table'); $method = $reflector->getMethod('format_range'); - $method->setAccessible(true); $this->assertEquals( '5 − 10', diff --git a/mod/quiz/tests/local_structure_slot_random_test.php b/mod/quiz/tests/local_structure_slot_random_test.php index 3a29b7e5757..cf7d12d7ccb 100644 --- a/mod/quiz/tests/local_structure_slot_random_test.php +++ b/mod/quiz/tests/local_structure_slot_random_test.php @@ -82,7 +82,6 @@ class local_structure_slot_random_test extends \advanced_testcase { $rc = new \ReflectionClass('\mod_quiz\local\structure\slot_random'); $rcp = $rc->getProperty('filtercondition'); - $rcp->setAccessible(true); $record = json_decode($rcp->getValue($randomslot)); $this->assertEquals($quiz->id, $randomslot->get_quiz()->id); @@ -90,7 +89,6 @@ class local_structure_slot_random_test extends \advanced_testcase { $this->assertTrue($record->filters->category->filteroptions->includesubcategories); $rcp = $rc->getProperty('record'); - $rcp->setAccessible(true); $record = $rcp->getValue($randomslot); $this->assertEquals(1, $record->maxmark); } @@ -168,7 +166,6 @@ class local_structure_slot_random_test extends \advanced_testcase { $rc = new \ReflectionClass('\mod_quiz\local\structure\slot_random'); $rcp = $rc->getProperty('quiz'); - $rcp->setAccessible(true); $quizpropery = $rcp->getValue($randomslot); $this->assertEquals($quiz, $quizpropery); @@ -223,7 +220,6 @@ class local_structure_slot_random_test extends \advanced_testcase { $rc = new \ReflectionClass('\mod_quiz\local\structure\slot_random'); $rcp = $rc->getProperty('filtercondition'); - $rcp->setAccessible(true); $tagspropery = $rcp->getValue($randomslot); $this->assertEquals([$tags['foo']->id, $tags['bar']->id], diff --git a/mod/workshop/allocation/scheduled/tests/scheduled_allocator_test.php b/mod/workshop/allocation/scheduled/tests/scheduled_allocator_test.php index d227143fab1..5a9bb7c1f1c 100644 --- a/mod/workshop/allocation/scheduled/tests/scheduled_allocator_test.php +++ b/mod/workshop/allocation/scheduled/tests/scheduled_allocator_test.php @@ -135,7 +135,6 @@ class scheduled_allocator_test extends \advanced_testcase { $allocator = new \workshop_scheduled_allocator($this->workshop); $storesettingsmethod = new \ReflectionMethod('workshop_scheduled_allocator', 'store_settings'); - $storesettingsmethod->setAccessible(true); $storesettingsmethod->invoke($allocator, true, true, $settings, new \workshop_allocation_result($allocator)); } diff --git a/mod/workshop/tests/locallib_test.php b/mod/workshop/tests/locallib_test.php index 802163fcf58..adb540535f5 100644 --- a/mod/workshop/tests/locallib_test.php +++ b/mod/workshop/tests/locallib_test.php @@ -866,7 +866,6 @@ class locallib_test extends \advanced_testcase { $reflector = new \ReflectionObject($this->workshop); $initialbarprefsprop = $reflector->getProperty('initialbarprefs'); - $initialbarprefsprop->setAccessible(true); $initialbarprefs = $initialbarprefsprop->getValue($this->workshop); return $initialbarprefs; diff --git a/mod/workshop/tests/portfolio_caller_test.php b/mod/workshop/tests/portfolio_caller_test.php index 195f9101eb2..6507ab46418 100644 --- a/mod/workshop/tests/portfolio_caller_test.php +++ b/mod/workshop/tests/portfolio_caller_test.php @@ -81,7 +81,6 @@ class portfolio_caller_test extends \advanced_testcase { $reflector = new \ReflectionObject($portfoliocaller); $propertysubmission = $reflector->getProperty('submission'); - $propertysubmission->setAccessible(true); $submission = $propertysubmission->getValue($portfoliocaller); $this->assertEquals($subid1, $submission->id); diff --git a/notes/tests/lib_test.php b/notes/tests/lib_test.php index 2ec419bfdd0..b0b5296e616 100644 --- a/notes/tests/lib_test.php +++ b/notes/tests/lib_test.php @@ -75,7 +75,6 @@ class lib_test extends \advanced_testcase { core_notes_myprofile_navigation($this->tree, $USER, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('notes', $nodes->getValue($this->tree)); } @@ -92,7 +91,6 @@ class lib_test extends \advanced_testcase { core_notes_myprofile_navigation($this->tree, $USER, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('notes', $nodes->getValue($this->tree)); } @@ -112,7 +110,6 @@ class lib_test extends \advanced_testcase { core_notes_myprofile_navigation($this->tree, $USER, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('notes', $nodes->getValue($this->tree)); } } diff --git a/privacy/tests/contextlist_test.php b/privacy/tests/contextlist_test.php index b81cdd631d3..43370f72479 100644 --- a/privacy/tests/contextlist_test.php +++ b/privacy/tests/contextlist_test.php @@ -127,7 +127,6 @@ class contextlist_test extends advanced_testcase { $rc = new \ReflectionClass(contextlist::class); $rcm = $rc->getMethod('guess_id_field_from_sql'); - $rcm->setAccessible(true); $actual = $rcm->invoke(new contextlist(), $sql); $this->assertEquals($expected, $actual, 'Unable to guess context id field in: '.$sql); diff --git a/privacy/tests/moodle_content_writer_test.php b/privacy/tests/moodle_content_writer_test.php index e2d8de216fe..8ad701fc7c5 100644 --- a/privacy/tests/moodle_content_writer_test.php +++ b/privacy/tests/moodle_content_writer_test.php @@ -1250,11 +1250,9 @@ class moodle_content_writer_test extends advanced_testcase { if (null === $subcontext) { $rcm = $rc->getMethod('get_context_path'); - $rcm->setAccessible(true); $path = $rcm->invoke($writer); } else { $rcm = $rc->getMethod('get_path'); - $rcm->setAccessible(true); $path = $rcm->invoke($writer, $subcontext, $name); } diff --git a/question/bank/statistics/tests/helper_test.php b/question/bank/statistics/tests/helper_test.php index d8c467e5d39..e6ba911afe0 100644 --- a/question/bank/statistics/tests/helper_test.php +++ b/question/bank/statistics/tests/helper_test.php @@ -51,7 +51,6 @@ class helper_test extends \advanced_testcase { $this->setAdminUser(); $rcm = new \ReflectionMethod(helper::class, 'get_all_places_where_questions_were_attempted'); - $rcm->setAccessible(true); // Create a course. $course = $this->getDataGenerator()->create_course(); @@ -252,7 +251,6 @@ class helper_test extends \advanced_testcase { private function extract_item_value(all_calculated_for_qubaid_condition $statistics, int $questionid, string $item): ?float { $rcm = new \ReflectionMethod(helper::class, 'extract_item_value'); - $rcm->setAccessible(true); return $rcm->invoke(null, $statistics, $questionid, $item); } @@ -264,7 +262,6 @@ class helper_test extends \advanced_testcase { */ private function load_quiz_statistics_for_place(\context $context): ?all_calculated_for_qubaid_condition { $rcm = new \ReflectionMethod(helper::class, 'load_statistics_for_place'); - $rcm->setAccessible(true); return $rcm->invoke(null, 'mod_quiz', $context); } diff --git a/question/engine/tests/datalib_test.php b/question/engine/tests/datalib_test.php index 373f5cbbaf0..df6f4f89184 100644 --- a/question/engine/tests/datalib_test.php +++ b/question/engine/tests/datalib_test.php @@ -272,7 +272,6 @@ class datalib_test extends \qbehaviour_walkthrough_test_base { $newstep = new \question_attempt_step(); $newstep->set_state(null); $addstepmethod = new \ReflectionMethod('question_attempt', 'add_step'); - $addstepmethod->setAccessible(true); $addstepmethod->invoke($quba->get_question_attempt($slot), $newstep); // Verify that trying to save this throws an exception. diff --git a/question/engine/tests/question_engine_test.php b/question/engine/tests/question_engine_test.php index edb2aa9fcf8..10b81ecaedb 100644 --- a/question/engine/tests/question_engine_test.php +++ b/question/engine/tests/question_engine_test.php @@ -299,7 +299,6 @@ class question_engine_test extends advanced_testcase { $renderer = new \core_question_renderer($PAGE, 'core_question'); $rc = new \ReflectionClass($renderer); $rcm = $rc->getMethod('number'); - $rcm->setAccessible(true); $this->assertEquals($expected, $rcm->invoke($renderer, $value)); } diff --git a/question/tests/local/statistics/statistics_bulk_loader_test.php b/question/tests/local/statistics/statistics_bulk_loader_test.php index 6d51575a752..81d2477e55a 100644 --- a/question/tests/local/statistics/statistics_bulk_loader_test.php +++ b/question/tests/local/statistics/statistics_bulk_loader_test.php @@ -62,7 +62,6 @@ class statistics_bulk_loader_test extends advanced_testcase { $this->setAdminUser(); $rcm = new ReflectionMethod(statistics_bulk_loader::class, 'get_all_places_where_questions_were_attempted'); - $rcm->setAccessible(true); // Create a course. $course = $this->getDataGenerator()->create_course(); @@ -273,7 +272,6 @@ class statistics_bulk_loader_test extends advanced_testcase { private function extract_item_value(all_calculated_for_qubaid_condition $statistics, int $questionid, string $item): ?float { $rcm = new ReflectionMethod(statistics_bulk_loader::class, 'extract_item_value'); - $rcm->setAccessible(true); return $rcm->invoke(null, $statistics, $questionid, $item); } @@ -285,7 +283,6 @@ class statistics_bulk_loader_test extends advanced_testcase { */ private function load_quiz_statistics_for_place(context $context): ?all_calculated_for_qubaid_condition { $rcm = new ReflectionMethod(statistics_bulk_loader::class, 'load_statistics_for_place'); - $rcm->setAccessible(true); return $rcm->invoke(null, 'mod_quiz', $context); } diff --git a/question/tests/version_test.php b/question/tests/version_test.php index 547beeae818..516e7290a19 100644 --- a/question/tests/version_test.php +++ b/question/tests/version_test.php @@ -344,7 +344,6 @@ class version_test extends \advanced_testcase { $question3 = $this->qgenerator->update_question($question2, null, ['idnumber' => 'id2']); $latestversioninspector = new \ReflectionProperty('question_definition', 'latestversion'); - $latestversioninspector->setAccessible(true); $this->assertEmpty(question_version_info::$pendingdefinitions); $questiondef1 = question_bank::load_question($question1->id); diff --git a/question/type/ddwtos/tests/form/edit_form_test.php b/question/type/ddwtos/tests/form/edit_form_test.php index 62e54436958..d0ca6bead78 100644 --- a/question/type/ddwtos/tests/form/edit_form_test.php +++ b/question/type/ddwtos/tests/form/edit_form_test.php @@ -72,7 +72,6 @@ class edit_form_test extends \advanced_testcase { list($form) = $this->get_form('qtype_ddwtos_edit_form'); // Use reflection to get the protected property we need. $property = new \ReflectionProperty('qtype_ddwtos_edit_form', '_form'); - $property->setAccessible(true); $mform = $property->getValue($form); $choices = $mform->getElement('choices[0]'); $groupoptions = $choices->_elements[1]; diff --git a/question/type/gapselect/tests/form/edit_form_test.php b/question/type/gapselect/tests/form/edit_form_test.php index 17e890b4fd4..da69ef1e48e 100644 --- a/question/type/gapselect/tests/form/edit_form_test.php +++ b/question/type/gapselect/tests/form/edit_form_test.php @@ -146,7 +146,6 @@ class edit_form_test extends \advanced_testcase { list($form) = $this->get_form('qtype_gapselect_edit_form'); // Use reflection to get the protected property we need. $property = new \ReflectionProperty('qtype_gapselect_edit_form', '_form'); - $property->setAccessible(true); $mform = $property->getValue($form); $choices = $mform->getElement('choices[0]'); $groupoptions = $choices->_elements[1]; diff --git a/question/type/numerical/tests/answerprocessor_test.php b/question/type/numerical/tests/answerprocessor_test.php index dd764665b5d..fe3f9210f11 100644 --- a/question/type/numerical/tests/answerprocessor_test.php +++ b/question/type/numerical/tests/answerprocessor_test.php @@ -62,7 +62,6 @@ class answerprocessor_test extends \advanced_testcase { $rc = new \ReflectionClass($ap); $rcm = $rc->getMethod('parse_response'); - $rcm->setAccessible(true); $this->assertEquals($expected, $rcm->invoke($ap, $args)); } diff --git a/report/log/tests/lib_test.php b/report/log/tests/lib_test.php index 722d1b9bb0b..c3984cf12c2 100644 --- a/report/log/tests/lib_test.php +++ b/report/log/tests/lib_test.php @@ -91,7 +91,6 @@ class lib_test extends \advanced_testcase { report_log_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('alllogs', $nodes->getValue($this->tree)); $this->assertArrayHasKey('todayslogs', $nodes->getValue($this->tree)); } @@ -108,7 +107,6 @@ class lib_test extends \advanced_testcase { report_log_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('alllogs', $nodes->getValue($this->tree)); $this->assertArrayNotHasKey('todayslogs', $nodes->getValue($this->tree)); } diff --git a/report/outline/tests/lib_test.php b/report/outline/tests/lib_test.php index 5a3d16989be..bffc1fc2dbf 100644 --- a/report/outline/tests/lib_test.php +++ b/report/outline/tests/lib_test.php @@ -100,7 +100,6 @@ class lib_test extends \advanced_testcase { report_outline_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('outline', $nodes->getValue($this->tree)); $this->assertArrayHasKey('complete', $nodes->getValue($this->tree)); } @@ -115,7 +114,6 @@ class lib_test extends \advanced_testcase { report_outline_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('outline', $nodes->getValue($this->tree)); $this->assertArrayNotHasKey('complete', $nodes->getValue($this->tree)); } diff --git a/report/stats/tests/lib_test.php b/report/stats/tests/lib_test.php index 0da9f424606..f0d901b3042 100644 --- a/report/stats/tests/lib_test.php +++ b/report/stats/tests/lib_test.php @@ -89,7 +89,6 @@ class lib_test extends \advanced_testcase { report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('stats', $nodes->getValue($this->tree)); } @@ -106,7 +105,6 @@ class lib_test extends \advanced_testcase { report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('stats', $nodes->getValue($this->tree)); } @@ -124,7 +122,6 @@ class lib_test extends \advanced_testcase { report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('stats', $nodes->getValue($this->tree)); } } diff --git a/report/usersessions/tests/lib_test.php b/report/usersessions/tests/lib_test.php index 30e1609bea6..7e0962995b2 100644 --- a/report/usersessions/tests/lib_test.php +++ b/report/usersessions/tests/lib_test.php @@ -71,7 +71,6 @@ class lib_test extends \advanced_testcase { report_usersessions_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('usersessions', $nodes->getValue($this->tree)); } @@ -85,7 +84,6 @@ class lib_test extends \advanced_testcase { report_usersessions_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayHasKey('usersessions', $nodes->getValue($this->tree)); } @@ -99,7 +97,6 @@ class lib_test extends \advanced_testcase { report_usersessions_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('usersessions', $nodes->getValue($this->tree)); } @@ -115,7 +112,6 @@ class lib_test extends \advanced_testcase { report_usersessions_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); $reflector = new \ReflectionObject($this->tree); $nodes = $reflector->getProperty('nodes'); - $nodes->setAccessible(true); $this->assertArrayNotHasKey('usersessions', $nodes->getValue($this->tree)); } diff --git a/reportbuilder/tests/datasource_test.php b/reportbuilder/tests/datasource_test.php index 66a01fcad2e..7b0bae70790 100644 --- a/reportbuilder/tests/datasource_test.php +++ b/reportbuilder/tests/datasource_test.php @@ -89,7 +89,6 @@ class datasource_test extends advanced_testcase { $instance = $this->get_datasource_test_source(); $method = (new ReflectionClass($instance))->getMethod('add_columns_from_entity'); - $method->setAccessible(true); $method->invoke($instance, 'user', $include, $exclude); // Get all our user entity columns. @@ -146,7 +145,6 @@ class datasource_test extends advanced_testcase { $instance = $this->get_datasource_test_source(); $method = (new ReflectionClass($instance))->getMethod('add_filters_from_entity'); - $method->setAccessible(true); $method->invoke($instance, 'user', $include, $exclude); // Get all our user entity filters. @@ -203,7 +201,6 @@ class datasource_test extends advanced_testcase { $instance = $this->get_datasource_test_source(); $method = (new ReflectionClass($instance))->getMethod('add_conditions_from_entity'); - $method->setAccessible(true); $method->invoke($instance, 'user', $include, $exclude); // Get all our user entity conditions. @@ -225,7 +222,6 @@ class datasource_test extends advanced_testcase { $instance = $this->get_datasource_test_source(); $method = (new ReflectionClass($instance))->getMethod('add_all_from_entity'); - $method->setAccessible(true); $method->invoke($instance, 'user', ['username'], ['firstname'], ['lastname']); // Assert the column we added (plus one we didn't). diff --git a/reportbuilder/tests/local/report/base_test.php b/reportbuilder/tests/local/report/base_test.php index 63ea6aa792d..25c71114834 100644 --- a/reportbuilder/tests/local/report/base_test.php +++ b/reportbuilder/tests/local/report/base_test.php @@ -198,7 +198,6 @@ class base_test extends advanced_testcase { $systemreport = system_report_factory::create(system_report_available::class, context_system::instance()); $method = (new ReflectionClass($systemreport))->getMethod('annotate_entity'); - $method->setAccessible(true); $method->invoke($systemreport, 'test', new lang_string('yes')); $this->assertEquals(new lang_string('yes'), $systemreport->get_entity_title('test')); @@ -213,7 +212,6 @@ class base_test extends advanced_testcase { $systemreport = system_report_factory::create(system_report_available::class, context_system::instance()); $method = (new ReflectionClass($systemreport))->getMethod('annotate_entity'); - $method->setAccessible(true); $this->expectException(coding_exception::class); $this->expectExceptionMessage('Entity name must be comprised of alphanumeric character, underscore or dash'); @@ -229,7 +227,6 @@ class base_test extends advanced_testcase { $systemreport = system_report_factory::create(system_report_available::class, context_system::instance()); $method = (new ReflectionClass($systemreport))->getMethod('annotate_entity'); - $method->setAccessible(true); $method->invoke($systemreport, 'test', new lang_string('yes')); diff --git a/repository/dropbox/tests/api_test.php b/repository/dropbox/tests/api_test.php index cec67079f1a..1d2635f7c92 100644 --- a/repository/dropbox/tests/api_test.php +++ b/repository/dropbox/tests/api_test.php @@ -160,7 +160,6 @@ class api_test extends \advanced_testcase { $rc = new \ReflectionClass(\repository_dropbox\dropbox::class); $rcm = $rc->getMethod('check_and_handle_api_errors'); - $rcm->setAccessible(true); if ($exception) { $this->expectException($exception); @@ -334,7 +333,6 @@ class api_test extends \advanced_testcase { // Make the call. $rc = new \ReflectionClass(\repository_dropbox\dropbox::class); $rcm = $rc->getMethod('fetch_dropbox_data'); - $rcm->setAccessible(true); $rcm->invoke($mock, $endpoint); } @@ -361,7 +359,6 @@ class api_test extends \advanced_testcase { // Make the call. $rc = new \ReflectionClass(\repository_dropbox\dropbox::class); $rcm = $rc->getMethod('fetch_dropbox_data'); - $rcm->setAccessible(true); $rcm->invoke($mock, $endpoint, null); } @@ -389,7 +386,6 @@ class api_test extends \advanced_testcase { // Make the call. $rc = new \ReflectionClass(\repository_dropbox\dropbox::class); $rcm = $rc->getMethod('fetch_dropbox_data'); - $rcm->setAccessible(true); $rcm->invoke($mock, $endpoint, $data); } @@ -430,7 +426,6 @@ class api_test extends \advanced_testcase { // Make the call. $rc = new \ReflectionClass(\repository_dropbox\dropbox::class); $rcm = $rc->getMethod('fetch_dropbox_data'); - $rcm->setAccessible(true); $result = $rcm->invoke($mock, $endpoint, null, 'matches'); $this->assertEquals([ @@ -496,7 +491,6 @@ class api_test extends \advanced_testcase { // Make the call. $rc = new \ReflectionClass(\repository_dropbox\dropbox::class); $rcm = $rc->getMethod('fetch_dropbox_content'); - $rcm->setAccessible(true); $result = $rcm->invoke($mock, $endpoint, $data); $this->assertEquals($response, $result); diff --git a/repository/nextcloud/tests/access_controlled_link_manager_test.php b/repository/nextcloud/tests/access_controlled_link_manager_test.php index 4dc409c964e..502329cd55c 100644 --- a/repository/nextcloud/tests/access_controlled_link_manager_test.php +++ b/repository/nextcloud/tests/access_controlled_link_manager_test.php @@ -612,7 +612,6 @@ XML; protected function set_private_property($value, $propertyname, $class) { $refclient = new \ReflectionClass($class); $private = $refclient->getProperty($propertyname); - $private->setAccessible(true); $private->setValue($class, $value); return $private; } @@ -626,7 +625,6 @@ XML; protected function get_private_property($propertyname, $class) { $refclient = new \ReflectionClass($class); $private = $refclient->getProperty($propertyname); - $private->setAccessible(true); $property = $private->getValue($private); return $property; } diff --git a/repository/nextcloud/tests/lib_test.php b/repository/nextcloud/tests/lib_test.php index 190b1ba30b3..a0d20e8a315 100644 --- a/repository/nextcloud/tests/lib_test.php +++ b/repository/nextcloud/tests/lib_test.php @@ -618,7 +618,6 @@ JSON; $refclient = new \ReflectionClass($dav); $property = $refclient->getProperty('_port'); - $property->setAccessible(true); $port = $property->getValue($dav); @@ -977,7 +976,6 @@ XML; $curl->method('get_info')->willReturn(['http_code' => 200]); $reflectionproperty = new \ReflectionProperty($this->repo, 'curl'); - $reflectionproperty->setAccessible(true); $reflectionproperty->setValue($this->repo, $curl); } } else { @@ -1002,7 +1000,6 @@ XML; protected function set_private_property($value, $propertyname) { $refclient = new \ReflectionClass($this->repo); $private = $refclient->getProperty($propertyname); - $private->setAccessible(true); $private->setValue($this->repo, $value); return $private; diff --git a/theme/boost/tests/boostnavbar_test.php b/theme/boost/tests/boostnavbar_test.php index 86e756b54db..6c9c8e0102f 100644 --- a/theme/boost/tests/boostnavbar_test.php +++ b/theme/boost/tests/boostnavbar_test.php @@ -209,12 +209,10 @@ class boostnavbar_test extends \advanced_testcase { $rc = new \ReflectionClass(boostnavbar::class); $rcp = $rc->getProperty('items'); - $rcp->setAccessible(true); $rcp->setValue($boostnavbar, $page->navbar->get_items()); // Make the call to the function. $rcm = $rc->getMethod('remove_no_link_items'); - $rcm->setAccessible(true); $rcm->invoke($boostnavbar, $removesectionnodes); // Get the value for the class variable that the function modifies. @@ -388,12 +386,10 @@ class boostnavbar_test extends \advanced_testcase { $rc = new \ReflectionClass(boostnavbar::class); $rcp = $rc->getProperty('items'); - $rcp->setAccessible(true); $rcp->setValue($boostnavbar, $page->navbar->get_items()); // Make the call to the function. $rcm = $rc->getMethod('remove_duplicate_items'); - $rcm->setAccessible(true); $rcm->invoke($boostnavbar); // Get the value for the class variable that the function modifies. @@ -527,12 +523,10 @@ class boostnavbar_test extends \advanced_testcase { $rc = new \ReflectionClass(boostnavbar::class); $rcp = $rc->getProperty('items'); - $rcp->setAccessible(true); $rcp->setValue($boostnavbar, $page->navbar->get_items()); // Make the call to the function. $rcm = $rc->getMethod('remove_items_that_exist_in_navigation'); - $rcm->setAccessible(true); $rcm->invoke($boostnavbar, $navigationmenu); // Get the value for the class variable that the function modifies. diff --git a/webservice/rest/tests/server_test.php b/webservice/rest/tests/server_test.php index e1b781b1faa..c1cb4319cd7 100644 --- a/webservice/rest/tests/server_test.php +++ b/webservice/rest/tests/server_test.php @@ -207,7 +207,6 @@ class server_test extends \advanced_testcase { */ public function test_xmlize($description, $value, $expected) { $method = new \ReflectionMethod('webservice_rest_server', 'xmlize_result'); - $method->setAccessible(true); $this->assertEquals($expected, $method->invoke(null, $value, $description)); } -- 2.43.0