MDL-67673 phpunit: Fix the return type of template methods

All the setup/teardown/pre/post/conditions template methods
now are required to return void. This was warned with phpunit 7
and now is enforced.

At the same time, fix a few wrong function names,
provider data and param types, return statements...
This commit is contained in:
Eloy Lafuente (stronk7) 2020-08-02 10:59:12 +02:00
parent c611109ed7
commit d81a94807b
421 changed files with 531 additions and 531 deletions

View file

@ -29,7 +29,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
/** @var string temporary file used in testing */
protected $tempfile;
protected function setUp() {
protected function setUp(): void {
$this->resetAfterTest();
// Create tempfile.
@ -38,7 +38,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
touch($this->tempfile);
}
protected function tearDown() {
protected function tearDown(): void {
@unlink($this->tempfile);
}

View file

@ -31,7 +31,7 @@ class core_ddl_testcase extends database_driver_testcase {
/** @var array table name => array of stdClass test records loaded into that table. Created in setUp. */
private $records = array();
protected function setUp() {
protected function setUp(): void {
parent::setUp();
$dbman = $this->tdb->get_manager(); // Loads DDL libs.

View file

@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die();
class core_dml_testcase extends database_driver_testcase {
protected function setUp() {
protected function setUp(): void {
parent::setUp();
$dbman = $this->tdb->get_manager(); // Loads DDL libs.
}

View file

@ -44,7 +44,7 @@ class pgsql_native_recordset_testcase extends basic_testcase {
/**
* Creates a second db connection and a temp table with values in for testing.
*/
protected function setUp() {
protected function setUp(): void {
global $DB;
parent::setUp();
@ -87,7 +87,7 @@ class pgsql_native_recordset_testcase extends basic_testcase {
/**
* Gets rid of the second db connection.
*/
protected function tearDown() {
protected function tearDown(): void {
if ($this->specialdb) {
$table = new xmldb_table('silly_test_table');
$this->specialdb->get_manager()->drop_table($table);

View file

@ -35,7 +35,7 @@ defined('MOODLE_INTERNAL') || die();
*/
class core_recordset_walk_testcase extends advanced_testcase {
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->resetAfterTest();
}

View file

@ -38,7 +38,7 @@ require_once($CFG->dirroot.'/lib/dml/sqlsrv_native_moodle_database.php');
*/
class sqlsrv_native_moodle_database_testcase extends advanced_testcase {
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->resetAfterTest();
}

View file

@ -59,7 +59,7 @@ class file_browser_testcase extends advanced_testcase {
/**
* Set up
*/
public function setUp() {
public function setUp(): void {
global $DB;
$this->resetAfterTest();

View file

@ -43,7 +43,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
/**
* Shared test setUp.
*/
public function setUp() {
public function setUp(): void {
// Reset the file storage so that subsequent fetches to get_file_storage are called after
// configuration is prepared.
get_file_storage(true);
@ -52,7 +52,7 @@ class core_files_file_system_filedir_testcase extends advanced_testcase {
/**
* Shared teset tearDown.
*/
public function tearDown() {
public function tearDown(): void {
// Reset the file storage so that subsequent tests will use the standard file storage.
get_file_storage(true);
}

View file

@ -39,11 +39,11 @@ require_once($CFG->libdir . '/filestorage/file_system.php');
*/
class core_files_file_system_testcase extends advanced_testcase {
public function setUp() {
public function setUp(): void {
get_file_storage(true);
}
public function tearDown() {
public function tearDown(): void {
get_file_storage(true);
}

View file

@ -37,7 +37,7 @@ class core_files_zip_packer_testcase extends advanced_testcase implements file_p
*/
protected $progress;
protected function setUp() {
protected function setUp(): void {
parent::setUp();
$this->testfile = __DIR__.'/fixtures/test.txt';

View file

@ -50,7 +50,7 @@ class core_form_dateselector_testcase extends advanced_testcase {
/**
* Initalize test wide variable, it is called in start of the testcase
*/
protected function setUp() {
protected function setUp(): void {
global $CFG;
parent::setUp();

View file

@ -50,7 +50,7 @@ class core_form_datetimeselector_testcase extends advanced_testcase {
/**
* Initalize test wide variable, it is called in start of the testcase
*/
protected function setUp() {
protected function setUp(): void {
global $CFG;
parent::setUp();

View file

@ -49,7 +49,7 @@ abstract class grade_base_testcase extends advanced_testcase {
protected $courseid;
protected $userid;
protected function setUp() {
protected function setUp(): void {
global $CFG;
parent::setup();

View file

@ -67,7 +67,7 @@ abstract class database_driver_testcase extends base_testcase {
$this->setRunTestInSeparateProcess(false);
}
public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
global $CFG;
parent::setUpBeforeClass();
@ -101,7 +101,7 @@ abstract class database_driver_testcase extends base_testcase {
self::$extradb = $d;
}
protected function setUp() {
protected function setUp(): void {
global $DB;
parent::setUp();
@ -112,7 +112,7 @@ abstract class database_driver_testcase extends base_testcase {
}
}
protected function tearDown() {
protected function tearDown(): void {
// delete all test tables
$dbman = $this->tdb->get_manager();
$tables = $this->tdb->get_tables(false);
@ -125,7 +125,7 @@ abstract class database_driver_testcase extends base_testcase {
parent::tearDown();
}
public static function tearDownAfterClass() {
public static function tearDownAfterClass(): void {
if (self::$extradb) {
self::$extradb->dispose();
self::$extradb = null;

View file

@ -51,7 +51,7 @@ abstract class restore_date_testcase extends advanced_testcase {
/**
* Setup.
*/
public function setUp() {
public function setUp(): void {
global $CFG;
parent::setUp();
@ -160,4 +160,4 @@ abstract class restore_date_testcase extends advanced_testcase {
return ($this->restorestartdate - $this->startdate);
}
}
}

View file

@ -37,7 +37,7 @@ defined('MOODLE_INTERNAL') || die();
class core_phpunit_basic_testcase extends basic_testcase {
protected $testassertexecuted = false;
protected function setUp() {
protected function setUp(): void {
parent::setUp();
if ($this->getName() === 'test_setup_assert') {
$this->assertTrue(true);

View file

@ -29,7 +29,7 @@ class core_ajaxlib_testcase extends advanced_testcase {
/** @var string Original error log */
protected $oldlog;
protected function setUp() {
protected function setUp(): void {
global $CFG;
parent::setUp();
@ -38,7 +38,7 @@ class core_ajaxlib_testcase extends advanced_testcase {
ini_set('error_log', "$CFG->dataroot/testlog.log");
}
protected function tearDown() {
protected function tearDown(): void {
ini_set('error_log', $this->oldlog);
parent::tearDown();
}

View file

@ -29,7 +29,7 @@ require_once(__DIR__ . '/fixtures/testable_antivirus.php');
class core_antivirus_testcase extends advanced_testcase {
protected $tempfile;
protected function setUp() {
protected function setUp(): void {
global $CFG;
// Use our special testable fixture plugin.
$CFG->antiviruses = 'testable';
@ -42,7 +42,7 @@ class core_antivirus_testcase extends advanced_testcase {
touch($this->tempfile);
}
protected function tearDown() {
protected function tearDown(): void {
@unlink($this->tempfile);
}

View file

@ -39,7 +39,7 @@ class core_blocklib_testcase extends advanced_testcase {
protected $blockmanager;
protected $isediting = null;
protected function setUp() {
protected function setUp(): void {
parent::setUp();
$this->testpage = new moodle_page();
$this->testpage->set_context(context_system::instance());
@ -47,7 +47,7 @@ class core_blocklib_testcase extends advanced_testcase {
$this->blockmanager = new testable_block_manager($this->testpage);
}
protected function tearDown() {
protected function tearDown(): void {
$this->testpage = null;
$this->blockmanager = null;
parent::tearDown();

View file

@ -39,7 +39,7 @@ class core_calendar_cron_task_testcase extends advanced_testcase {
/**
* Tests set up
*/
protected function setUp() {
protected function setUp(): void {
$this->resetAfterTest();
}

View file

@ -48,7 +48,7 @@ class core_collator_testcase extends advanced_testcase {
/**
* Prepares things for this test case.
*/
protected function setUp() {
protected function setUp(): void {
global $SESSION;
if (isset($SESSION->lang)) {
$this->initiallang = $SESSION->lang;
@ -65,7 +65,7 @@ class core_collator_testcase extends advanced_testcase {
/**
* Cleans things up after this test case has run.
*/
protected function tearDown() {
protected function tearDown(): void {
global $SESSION;
parent::tearDown();
if ($this->initiallang !== null) {

View file

@ -38,7 +38,7 @@ class core_component_testcase extends advanced_testcase {
*/
const SUBSYSTEMCOUNT = 71;
public function setUp() {
public function setUp(): void {
$psr0namespaces = new ReflectionProperty('core_component', 'psr0namespaces');
$psr0namespaces->setAccessible(true);
$this->oldpsr0namespaces = $psr0namespaces->getValue(null);
@ -47,7 +47,7 @@ class core_component_testcase extends advanced_testcase {
$psr4namespaces->setAccessible(true);
$this->oldpsr4namespaces = $psr4namespaces->getValue(null);
}
public function tearDown() {
public function tearDown(): void {
$psr0namespaces = new ReflectionProperty('core_component', 'psr0namespaces');
$psr0namespaces->setAccessible(true);
$psr0namespaces->setValue(null, $this->oldpsr0namespaces);

View file

@ -40,7 +40,7 @@ class core_media_player_native_testcase extends advanced_testcase {
/**
* Pre-test setup.
*/
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->resetAfterTest();
}
@ -160,4 +160,4 @@ class core_media_player_native_testcase extends advanced_testcase {
$this->assertNotContains('<source src="http://example.org/some_filename.mp4" />', $content);
$this->assertNotContains('<source src="http://example.org/some_filename_hires.mp4" />', $content);
}
}
}

View file

@ -36,7 +36,7 @@ class core_csvclass_testcase extends advanced_testcase {
protected $teststring3 = '';
protected $teststring4 = '';
protected function setUp() {
protected function setUp(): void {
$this->resetAfterTest();

View file

@ -103,7 +103,7 @@ class customcontext_testcase extends advanced_testcase {
/**
* Perform setup before every test. This tells Moodle's phpunit to reset the database after every test.
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();
$this->resetAfterTest(true);
}

View file

@ -39,7 +39,7 @@ class contentbank_content_created_testcase extends \advanced_testcase {
/**
* Setup to ensure that fixtures are loaded.
*/
public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/contentbank/tests/fixtures/testable_contenttype.php');

View file

@ -39,7 +39,7 @@ class contentbank_content_deleted_testcase extends \advanced_testcase {
/**
* Setup to ensure that fixtures are loaded.
*/
public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/contentbank/tests/fixtures/testable_contenttype.php');

View file

@ -39,7 +39,7 @@ class contentbank_content_updated_testcase extends \advanced_testcase {
/**
* Setup to ensure that fixtures are loaded.
*/
public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/contentbank/tests/fixtures/testable_contenttype.php');

View file

@ -41,7 +41,7 @@ class contentbank_content_uploaded_testcase extends \advanced_testcase {
/**
* Setup to ensure that fixtures are loaded.
*/
public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/contentbank/tests/fixtures/testable_contenttype.php');

View file

@ -39,7 +39,7 @@ class contentbank_content_viewed_testcase extends \advanced_testcase {
/**
* Setup to ensure that fixtures are loaded.
*/
public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/contentbank/tests/fixtures/testable_contenttype.php');

View file

@ -42,7 +42,7 @@ class core_event_profile_field_testcase extends advanced_testcase {
/**
* Test set up.
*/
public function setUp() {
public function setUp(): void {
$this->resetAfterTest();
}

View file

@ -44,7 +44,7 @@ class core_event_user_graded_testcase extends advanced_testcase {
/**
* Tests set up.
*/
public function setUp() {
public function setUp(): void {
$this->resetAfterTest();
}

View file

@ -34,7 +34,7 @@ class core_events_testcase extends advanced_testcase {
*
* This is executed before running any test in this file.
*/
public function setUp() {
public function setUp(): void {
$this->resetAfterTest();
}

View file

@ -39,7 +39,7 @@ class core_exporter_testcase extends advanced_testcase {
protected $validdata = null;
protected $invaliddata = null;
public function setUp() {
public function setUp(): void {
$s = new stdClass();
$this->validrelated = array(
'simplestdClass' => $s,

View file

@ -32,11 +32,11 @@ require_once($CFG->libdir . '/externallib.php');
class core_externallib_testcase extends advanced_testcase {
protected $DB;
public function setUp() {
public function setUp(): void {
$this->DB = null;
}
public function tearDown() {
public function tearDown(): void {
global $DB;
if ($this->DB !== null) {
$DB = $this->DB;

View file

@ -38,7 +38,7 @@ class core_gdlib_testcase extends basic_testcase {
private $fixturepath = null;
public function setUp() {
public function setUp(): void {
$this->fixturepath = __DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR;
}

View file

@ -38,7 +38,7 @@ defined('MOODLE_INTERNAL') || die();
*/
class h5p_get_content_types_task_testcase extends advanced_testcase {
protected function setup() {
protected function setup(): void {
global $CFG;
parent::setUp();

View file

@ -39,7 +39,7 @@ class lock_testcase extends advanced_testcase {
/**
* Some lock types will store data in the database.
*/
protected function setUp() {
protected function setUp(): void {
$this->resetAfterTest(true);
}

View file

@ -34,7 +34,7 @@ class core_medialib_testcase extends advanced_testcase {
/**
* Pre-test setup. Preserves $CFG.
*/
public function setUp() {
public function setUp(): void {
parent::setUp();
// Reset $CFG and $SERVER.
@ -496,4 +496,4 @@ class core_medialib_testcase extends advanced_testcase {
}
return $out;
}
}
}

View file

@ -37,7 +37,7 @@ class core_moodle_page_testcase extends advanced_testcase {
*/
protected $testpage;
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->resetAfterTest();
$this->testpage = new testable_moodle_page();

View file

@ -51,7 +51,7 @@ class core_myprofilelib_testcase extends advanced_testcase {
*/
private $tree;
public function setUp() {
public function setUp(): void {
// Set the $PAGE->url value so core_myprofile_navigation() doesn't complain.
global $PAGE;
$PAGE->set_url('/test');

View file

@ -42,7 +42,7 @@ class core_notification_testcase extends advanced_testcase {
* This includes emptying the list of notifications on the session, resetting any session which exists, and setting
* up a new moodle_page object.
*/
public function setUp() {
public function setUp(): void {
global $PAGE, $SESSION;
parent::setUp();
@ -57,7 +57,7 @@ class core_notification_testcase extends advanced_testcase {
* This includes emptying the list of notifications on the session, resetting any session which exists, and setting
* up a new moodle_page object.
*/
public function tearDown() {
public function tearDown(): void {
global $PAGE, $SESSION;
$PAGE = null;

View file

@ -34,7 +34,7 @@ global $CFG;
*/
class core_persistent_testcase extends advanced_testcase {
public function setUp() {
public function setUp(): void {
$this->make_persistent_table();
$this->resetAfterTest();
}

View file

@ -34,7 +34,7 @@ require_once($CFG->dirroot.'/lib/tests/fixtures/testable_plugininfo_base.php');
*/
class core_plugin_manager_testcase extends advanced_testcase {
public function tearDown() {
public function tearDown(): void {
// The caches of the testable singleton must be reset explicitly. It is
// safer to kill the whole testable singleton at the end of every test.
testable_core_plugin_manager::reset_caches();

View file

@ -50,7 +50,7 @@ class base_testcase extends \advanced_testcase {
/**
* Tear down the testable plugin manager singleton between tests.
*/
public function tearDown() {
public function tearDown(): void {
// The caches of the testable singleton must be reset explicitly. It is
// safer to kill the whole testable singleton at the end of every test.
testable_core_plugin_manager::reset_caches();

View file

@ -49,7 +49,7 @@ class core_questionlib_testcase extends advanced_testcase {
*
* This is executed before running any test in this file.
*/
public function setUp() {
public function setUp(): void {
$this->resetAfterTest();
}

View file

@ -40,7 +40,7 @@ class core_rsslib_testcase extends advanced_testcase {
// The number of seconds tests should wait for the server to respond (high to prevent false positives).
const TIMEOUT = 10;
protected function setUp() {
protected function setUp(): void {
moodle_simplepie::reset_cache();
}

View file

@ -47,7 +47,7 @@ class core_session_redis_testcase extends advanced_testcase {
/** @var $redis The current testing redis connection */
protected $redis = null;
public function setUp() {
public function setUp(): void {
global $CFG;
if (!extension_loaded('redis')) {
@ -79,7 +79,7 @@ class core_session_redis_testcase extends advanced_testcase {
$this->redis->connect(TEST_SESSION_REDIS_HOST);
}
public function tearDown() {
public function tearDown(): void {
if (!extension_loaded('redis') || !defined('TEST_SESSION_REDIS_HOST')) {
return;
}

View file

@ -52,7 +52,7 @@ class core_statslib_testcase extends advanced_testcase {
* Setup function
* - Allow changes to CFG->debug for testing purposes.
*/
protected function setUp() {
protected function setUp(): void {
global $CFG, $DB;
parent::setUp();

View file

@ -43,7 +43,7 @@ class task_database_logger_testcase extends advanced_testcase {
/**
* Setup to backup the database before mocking.
*/
public function setUp() {
public function setUp(): void {
global $DB;
$this->DB = $DB;
@ -52,7 +52,7 @@ class task_database_logger_testcase extends advanced_testcase {
/**
* Tear down to unmock the database where it was mocked.
*/
public function tearDown() {
public function tearDown(): void {
global $DB;
$DB = $this->DB;

View file

@ -43,7 +43,7 @@ class core_task_logmanager extends advanced_testcase {
/**
* Relevant tearDown for logging tests.
*/
public function tearDown() {
public function tearDown(): void {
global $DB;
// Ensure that any logging is always ended.

View file

@ -44,7 +44,7 @@ class core_analytics_time_splittings_testcase extends advanced_testcase {
*
* @return void
*/
public function setUp() {
public function setUp(): void {
$this->resetAfterTest(true);

View file

@ -34,7 +34,7 @@ class core_user_testcase extends advanced_testcase {
/**
* Setup test data.
*/
protected function setUp() {
protected function setUp(): void {
$this->resetAfterTest(true);
}

View file

@ -34,7 +34,7 @@ class core_useragent_testcase extends advanced_testcase {
/**
* Restores the user agent to the default one.
*/
public function tearDown() {
public function tearDown(): void {
core_useragent::instance(true);
}

View file

@ -64,7 +64,7 @@ class post_statement_testcase extends externallib_advanced_testcase {
/**
* Setup test.
*/
public function setUp() {
public function setUp(): void {
global $CFG;
// We disable group actors on the test xapi_handler.
$CFG->xapitestforcegroupactors = false;