MDL-81521 core: Update all possibly data providers to be static

Note: Some data providers could not be automatically be converted to
being static. These will be handled in a separate issue.
This commit is contained in:
Andrew Nicols
2024-11-15 12:50:44 +08:00
parent e1d05182a6
commit c370c0cc5e
407 changed files with 1449 additions and 1430 deletions
+20 -17
View File
@@ -191,7 +191,7 @@ abstract class advanced_testcase extends base_testcase {
* @param array $files full paths to CSV or XML files to load.
* @return phpunit_dataset
*/
protected function dataset_from_files(array $files) {
protected static function dataset_from_files(array $files) {
// We ignore $delimiter, $enclosure and $escape, use the default ones in your fixtures.
$dataset = new phpunit_dataset();
$dataset->from_files($files);
@@ -208,7 +208,7 @@ abstract class advanced_testcase extends base_testcase {
* @param string $table name of the table which the file belongs to (only for CSV files).
* @return phpunit_dataset
*/
protected function dataset_from_string(string $content, string $type, ?string $table = null) {
protected static function dataset_from_string(string $content, string $type, ?string $table = null) {
$dataset = new phpunit_dataset();
$dataset->from_string($content, $type, $table);
return $dataset;
@@ -222,7 +222,7 @@ abstract class advanced_testcase extends base_testcase {
* @param array $data array of tables, see {@see phpunit_dataset::from_array()} for supported formats.
* @return phpunit_dataset
*/
protected function dataset_from_array(array $data) {
protected static function dataset_from_array(array $data) {
$dataset = new phpunit_dataset();
$dataset->from_array($data);
return $dataset;
@@ -607,28 +607,31 @@ abstract class advanced_testcase extends base_testcase {
* @param bool $https true if https required
* @return string url
*/
public function getExternalTestFileUrl($path, $https = false) {
public static function getExternalTestFileUrl(
string $path,
bool $https = false,
): string {
$path = ltrim($path, '/');
if ($path) {
$path = '/' . $path;
$path = "/{$path}";
}
if ($https) {
if (defined('TEST_EXTERNAL_FILES_HTTPS_URL')) {
if (!TEST_EXTERNAL_FILES_HTTPS_URL) {
$this->markTestSkipped('Tests using external https test files are disabled');
self::markTestSkipped('Tests using external https test files are disabled');
}
return TEST_EXTERNAL_FILES_HTTPS_URL . $path;
}
return 'https://download.moodle.org/unittest' . $path;
return "https://download.moodle.org/unittest/{$path}";
}
if (defined('TEST_EXTERNAL_FILES_HTTP_URL')) {
if (!TEST_EXTERNAL_FILES_HTTP_URL) {
$this->markTestSkipped('Tests using external http test files are disabled');
self::markTestSkipped('Tests using external http test files are disabled');
}
return TEST_EXTERNAL_FILES_HTTP_URL . $path;
}
return 'http://download.moodle.org/unittest' . $path;
return "http://download.moodle.org/unittest/{$path}";
}
/**
@@ -845,17 +848,11 @@ abstract class advanced_testcase extends base_testcase {
string $component,
string $path,
): string {
$fullpath = sprintf(
return sprintf(
"%s/tests/fixtures/%s",
\core_component::get_component_directory($component),
$path,
);
if (!file_exists($fullpath)) {
throw new \coding_exception("Fixture file not found: $fullpath");
}
return $fullpath;
}
/**
@@ -880,7 +877,13 @@ abstract class advanced_testcase extends base_testcase {
global $COURSE;
global $SITE;
require_once(static::get_fixture_path($component, $path));
$fullpath = static::get_fixture_path($component, $path);
if (!file_exists($fullpath)) {
throw new \coding_exception("Fixture file not found: $fullpath");
}
require_once($fullpath);
}
/**