Skip to content

Commit

Permalink
MDL-81523 phpunit: Add all missing setUp/tearDown parent calls
Browse files Browse the repository at this point in the history
All setUp(), tearDown(), setUpBeforeClass() and tearDownAfterClass()
must, always, call to parent, to ensure that everything is properly
set and cleaned.

While in a lot of situations this is not needed (parents may not
have anything to run), with PHPUnit >= 10 this can become more
important because we are going to move the reset code from current
placement @ runBare() to setUp()/tearDown().

Note that all the changes performed in this commit have been detected
and fixed by moodle-cs (ParentSetUpTearDownSniffTest).
  • Loading branch information
stronk7 committed Jun 8, 2024
1 parent d3ae139 commit 209cf0e
Show file tree
Hide file tree
Showing 432 changed files with 495 additions and 0 deletions.
1 change: 1 addition & 0 deletions admin/presets/tests/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class manager_test extends \advanced_testcase {
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->libdir.'/adminlib.php');
parent::setUpBeforeClass();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class get_entity_generator_test extends \advanced_testcase {
* @return void
*/
public function setUp(): void {
parent::setUp();
$this->resetAfterTest();
$this->setAdminUser();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class questionanswers_test extends \advanced_testcase {
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
parent::setUpBeforeClass();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class questiontext_test extends area_test_base {
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
parent::setUpBeforeClass();
}

/**
Expand Down
1 change: 1 addition & 0 deletions admin/tool/brickfield/tests/registration_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static function setUpBeforeClass(): void {

require_once($CFG->dirroot . '/admin/tool/brickfield/tests/generator/mock_registration.php');
require_once($CFG->dirroot . '/admin/tool/brickfield/tests/generator/mock_brickfieldconnect.php');
parent::setUpBeforeClass();
}

/**
Expand Down
1 change: 1 addition & 0 deletions admin/tool/capability/tests/event/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class events_test extends \advanced_testcase {
* Setup testcase.
*/
public function setUp(): void {
parent::setUp();
$this->setAdminUser();
$this->resetAfterTest();
}
Expand Down
1 change: 1 addition & 0 deletions admin/tool/cohortroles/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class api_test extends \advanced_testcase {
* Setup function- we will create a course and add an assign instance to it.
*/
protected function setUp(): void {
parent::setUp();
$this->resetAfterTest(true);

// Create some users.
Expand Down
1 change: 1 addition & 0 deletions admin/tool/cohortroles/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class provider_test extends \core_privacy\tests\provider_testcase {
* Overriding setUp() function to always reset after tests.
*/
public function setUp(): void {
parent::setUp();
$this->resetAfterTest(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class expired_data_requests_test extends data_privacy_testcase {
*/
public function tearDown(): void {
\core_privacy\local\request\writer::reset();
parent::tearDown();
}

/**
Expand Down
1 change: 1 addition & 0 deletions admin/tool/dataprivacy/tests/task/task_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class task_test extends \data_privacy_testcase {
*/
public function tearDown(): void {
\core_privacy\local\request\writer::reset();
parent::tearDown();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
class steprunner_test extends \advanced_testcase {
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
// Call the init method to include all behat libraries and attributes.
$runner = new runner();
$runner->init();
Expand Down
1 change: 1 addition & 0 deletions admin/tool/langimport/tests/event/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class events_test extends \advanced_testcase {
* Setup testcase.
*/
public function setUp(): void {
parent::setUp();
$this->setAdminUser();
$this->resetAfterTest();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class provider_test extends provider_testcase {

public function setUp(): void {
global $CFG;
parent::setUp();
$this->resetAfterTest();
$this->preventResetByRollback(); // Logging waits till the transaction gets committed.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
class provider_test extends provider_testcase {

public function setUp(): void {
parent::setUp();
$this->resetAfterTest();
$this->preventResetByRollback(); // Logging waits till the transaction gets committed.
}
Expand Down
1 change: 1 addition & 0 deletions admin/tool/log/store/standard/tests/store_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,5 +547,6 @@ public function tearDown(): void {
gc_enable();
}
$this->wedisabledgc = false;
parent::tearDown();
}
}
1 change: 1 addition & 0 deletions admin/tool/log/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
class provider_test extends provider_testcase {

public function setUp(): void {
parent::setUp();
$this->resetAfterTest();
$this->preventResetByRollback(); // Logging waits till the transaction gets committed.
}
Expand Down
1 change: 1 addition & 0 deletions admin/tool/lp/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class externallib_test extends externallib_advanced_testcase {
*/
protected function setUp(): void {
global $DB, $CFG;
parent::setUp();

$this->resetAfterTest(true);

Expand Down
1 change: 1 addition & 0 deletions admin/tool/lpmigrate/tests/processor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class processor_test extends \advanced_testcase {
* Then we attach some competencies from the first framework to courses and CM.
*/
public function setUp(): void {
parent::setUp();
$this->resetAfterTest(true);
$dg = $this->getDataGenerator();
$lpg = $dg->get_plugin_generator('core_competency');
Expand Down
1 change: 1 addition & 0 deletions admin/tool/messageinbound/tests/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class manager_test extends provider_testcase {

public function setUp(): void {
global $CFG;
parent::setUp();
$this->resetAfterTest();

// Pretend the system is enabled.
Expand Down
1 change: 1 addition & 0 deletions admin/tool/messageinbound/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class provider_test extends provider_testcase {

public function setUp(): void {
global $CFG;
parent::setUp();
$this->resetAfterTest();

// Pretend the system is enabled.
Expand Down
1 change: 1 addition & 0 deletions admin/tool/mfa/factor/token/tests/factor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class factor_test extends \advanced_testcase {
public \factor_token\factor $factor;

public function setUp(): void {
parent::setUp();
$this->resetAfterTest();
$this->factor = new \factor_token\factor('token');
}
Expand Down
1 change: 1 addition & 0 deletions admin/tool/mobile/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class provider_test extends \core_privacy\tests\provider_testcase {
* Basic setup for these tests.
*/
public function setUp(): void {
parent::setUp();
$this->resetAfterTest(true);
}

Expand Down
1 change: 1 addition & 0 deletions admin/tool/monitor/tests/event/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class events_test extends \advanced_testcase {
* Tests set up.
*/
public function setUp(): void {
parent::setUp();
set_config('enablemonitor', 1, 'tool_monitor');
$this->resetAfterTest();
}
Expand Down
1 change: 1 addition & 0 deletions admin/tool/monitor/tests/eventobservers_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class eventobservers_test extends \advanced_testcase {
* Set up method.
*/
public function setUp(): void {
parent::setUp();
// Enable monitor.
set_config('enablemonitor', 1, 'tool_monitor');
}
Expand Down
1 change: 1 addition & 0 deletions admin/tool/monitor/tests/generator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class generator_test extends \advanced_testcase {
* Set up method.
*/
public function setUp(): void {
parent::setUp();
// Enable monitor.
set_config('enablemonitor', 1, 'tool_monitor');
}
Expand Down
1 change: 1 addition & 0 deletions admin/tool/monitor/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class provider_test extends provider_testcase {
* Set up method.
*/
public function setUp(): void {
parent::setUp();
$this->resetAfterTest();
// Enable monitor.
set_config('enablemonitor', 1, 'tool_monitor');
Expand Down
1 change: 1 addition & 0 deletions admin/tool/monitor/tests/rule_manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class rule_manager_test extends \advanced_testcase {
* Set up method.
*/
public function setUp(): void {
parent::setUp();
// Enable monitor.
set_config('enablemonitor', 1, 'tool_monitor');
}
Expand Down
1 change: 1 addition & 0 deletions admin/tool/monitor/tests/subscription_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class subscription_test extends \advanced_testcase {
* Test set up.
*/
public function setUp(): void {
parent::setUp();
$this->resetAfterTest(true);

// Create the mock subscription.
Expand Down
1 change: 1 addition & 0 deletions admin/tool/monitor/tests/task_check_subscriptions_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class task_check_subscriptions_test extends \advanced_testcase {
*/
public function setUp(): void {
global $DB;
parent::setUp();
set_config('enablemonitor', 1, 'tool_monitor');
$this->resetAfterTest(true);

Expand Down
1 change: 1 addition & 0 deletions admin/tool/monitor/tests/task_clean_events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class task_clean_events_test extends \advanced_testcase {
* Test set up.
*/
public function setUp(): void {
parent::setUp();
set_config('enablemonitor', 1, 'tool_monitor');
$this->resetAfterTest(true);
}
Expand Down
1 change: 1 addition & 0 deletions admin/tool/policy/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class externallib_test extends externallib_advanced_testcase {
* Setup function- we will create some policy docs.
*/
public function setUp(): void {
parent::setUp();
$this->resetAfterTest(true);
$this->setAdminUser();

Expand Down
1 change: 1 addition & 0 deletions admin/tool/policy/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class provider_test extends \core_privacy\tests\provider_testcase {
* Setup function. Will create a user.
*/
protected function setUp(): void {
parent::setUp();
$this->resetAfterTest();

$generator = $this->getDataGenerator();
Expand Down
1 change: 1 addition & 0 deletions admin/tool/recyclebin/tests/category_bin_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class category_bin_test extends \advanced_testcase {
* Setup for each test.
*/
protected function setUp(): void {
parent::setUp();
$this->resetAfterTest();
$this->setAdminUser();

Expand Down
1 change: 1 addition & 0 deletions admin/tool/recyclebin/tests/course_bin_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class course_bin_test extends \advanced_testcase {
* Setup for each test.
*/
protected function setUp(): void {
parent::setUp();
$this->resetAfterTest(true);
$this->setAdminUser();

Expand Down
1 change: 1 addition & 0 deletions admin/tool/recyclebin/tests/event/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class events_test extends \advanced_testcase {
* This is executed before running any test in this file.
*/
public function setUp(): void {
parent::setUp();
$this->resetAfterTest();

// We want the category and course bin to be enabled.
Expand Down
1 change: 1 addition & 0 deletions admin/tool/uploaduser/tests/upload_users_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static function setUpBeforeClass(): void {
global $CFG;

require_once("{$CFG->dirroot}/{$CFG->admin}/tool/uploaduser/locallib.php");
parent::setUpBeforeClass();
}

/**
Expand Down
1 change: 1 addition & 0 deletions admin/tool/usertours/tests/accessdate_filter_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
class accessdate_filter_test extends \advanced_testcase {
public function setUp(): void {
parent::setUp();
$this->resetAfterTest(true);
}

Expand Down
2 changes: 2 additions & 0 deletions admin/tool/usertours/tests/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class manager_test extends \advanced_testcase {
*/
public function setUp(): void {
global $DB;
parent::setUp();

$this->db = $DB;
}
Expand All @@ -55,6 +56,7 @@ public function tearDown(): void {
global $DB;

$DB = $this->db;
parent::tearDown();
}

/**
Expand Down
1 change: 1 addition & 0 deletions admin/tool/usertours/tests/role_filter_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class role_filter_test extends \advanced_testcase {

public function setUp(): void {
global $DB;
parent::setUp();

$this->resetAfterTest(true);
$generator = $this->getDataGenerator();
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/usertours/tests/step_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class step_test extends \advanced_testcase {
*/
public function setUp(): void {
global $DB;
parent::setUp();

$this->db = $DB;
}
Expand All @@ -51,6 +52,7 @@ public function tearDown(): void {
global $DB;

$DB = $this->db;
parent::tearDown();
}

/**
Expand Down
3 changes: 3 additions & 0 deletions admin/tool/usertours/tests/tour_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ class tour_test extends \advanced_testcase {
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->libdir . '/formslib.php');
parent::setUpBeforeClass();
}

/**
* Setup to store the DB reference.
*/
public function setUp(): void {
global $DB;
parent::setUp();

$this->db = $DB;
}
Expand All @@ -51,6 +53,7 @@ public function tearDown(): void {
global $DB;

$DB = $this->db;
parent::tearDown();
}

/**
Expand Down
1 change: 1 addition & 0 deletions analytics/tests/course_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class course_test extends \advanced_testcase {

public function setUp(): void {
global $DB;
parent::setUp();

$this->course = $this->getDataGenerator()->create_course(['startdate' => 0]);
$this->stu1 = $this->getDataGenerator()->create_user();
Expand Down
1 change: 1 addition & 0 deletions analytics/tests/dataset_manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class dataset_manager_test extends \advanced_testcase {
* @return null
*/
public function setUp(): void {
parent::setUp();
$this->resetAfterTest(true);

$this->sharedtoprows = array(
Expand Down
1 change: 1 addition & 0 deletions analytics/tests/model_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class model_test extends \advanced_testcase {
protected $modelobj;

public function setUp(): void {
parent::setUp();

$this->setAdminUser();

Expand Down
1 change: 1 addition & 0 deletions analytics/tests/prediction_actions_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class prediction_actions_test extends \advanced_testcase {
*/
public function setUp(): void {
global $DB;
parent::setUp();

$this->setAdminUser();
$target = \core_analytics\manager::get_target('test_target_shortname');
Expand Down
1 change: 1 addition & 0 deletions analytics/tests/prediction_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function tearDown(): void {
foreach ($models as $model) {
$model->delete();
}
parent::tearDown();
}

/**
Expand Down
Loading

0 comments on commit 209cf0e

Please sign in to comment.