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:
@@ -228,7 +228,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);
|
||||
@@ -245,7 +245,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;
|
||||
@@ -259,7 +259,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;
|
||||
@@ -622,28 +622,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}";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -747,6 +750,24 @@ abstract class advanced_testcase extends base_testcase {
|
||||
$tasks->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get the path to a fixture.
|
||||
*
|
||||
* @param string $component
|
||||
* @param string $path
|
||||
* @throws coding_exception
|
||||
*/
|
||||
protected static function get_fixture_path(
|
||||
string $component,
|
||||
string $path
|
||||
): string {
|
||||
return sprintf(
|
||||
"%s/tests/fixtures/%s",
|
||||
\core_component::get_component_directory($component),
|
||||
$path,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to load a fixture from a component's fixture directory.
|
||||
*
|
||||
@@ -758,15 +779,6 @@ abstract class advanced_testcase extends base_testcase {
|
||||
string $component,
|
||||
string $path
|
||||
): void {
|
||||
$fullpath = 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");
|
||||
}
|
||||
|
||||
global $ADMIN;
|
||||
global $CFG;
|
||||
global $DB;
|
||||
@@ -778,6 +790,12 @@ abstract class advanced_testcase extends base_testcase {
|
||||
global $COURSE;
|
||||
global $SITE;
|
||||
|
||||
$fullpath = static::get_fixture_path($component, $path);
|
||||
|
||||
if (!file_exists($fullpath)) {
|
||||
throw new \coding_exception("Fixture file not found: $fullpath");
|
||||
}
|
||||
|
||||
require_once($fullpath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class phpunit_dataset_test extends advanced_testcase {
|
||||
/**
|
||||
* test_from_file() data provider.
|
||||
*/
|
||||
public function from_file_provider() {
|
||||
public static function from_file_provider(): array {
|
||||
// Create an unreadable file with vfsStream.
|
||||
$vfsfile = vfsStream::newFile('unreadable', 0222);
|
||||
vfsStream::setup('root')->addChild($vfsfile);
|
||||
@@ -183,7 +183,7 @@ class phpunit_dataset_test extends advanced_testcase {
|
||||
/**
|
||||
* test_from_string() data provider.
|
||||
*/
|
||||
public function from_string_provider() {
|
||||
public static function from_string_provider(): array {
|
||||
|
||||
return [
|
||||
'wrong type' => [
|
||||
@@ -276,7 +276,7 @@ class phpunit_dataset_test extends advanced_testcase {
|
||||
/**
|
||||
* test_from_array() data provider.
|
||||
*/
|
||||
public function from_array_provider() {
|
||||
public static function from_array_provider(): array {
|
||||
return [
|
||||
'repeated array table many structures' => [
|
||||
'structure' => [
|
||||
@@ -425,7 +425,7 @@ class phpunit_dataset_test extends advanced_testcase {
|
||||
/**
|
||||
* test_load_csv() data provider.
|
||||
*/
|
||||
public function load_csv_provider() {
|
||||
public static function load_csv_provider(): array {
|
||||
|
||||
return [
|
||||
'repeated csv table many files' => [
|
||||
@@ -516,7 +516,7 @@ class phpunit_dataset_test extends advanced_testcase {
|
||||
/**
|
||||
* test_load_xml() data provider.
|
||||
*/
|
||||
public function load_xml_provider() {
|
||||
public static function load_xml_provider(): array {
|
||||
|
||||
return [
|
||||
'repeated xml table multiple files' => [
|
||||
@@ -687,7 +687,7 @@ class phpunit_dataset_test extends advanced_testcase {
|
||||
/**
|
||||
* test_to_database() data provider.
|
||||
*/
|
||||
public function to_database_provider() {
|
||||
public static function to_database_provider(): array {
|
||||
|
||||
return [
|
||||
'wrong table requested' => [
|
||||
@@ -842,7 +842,7 @@ class phpunit_dataset_test extends advanced_testcase {
|
||||
/**
|
||||
* test_get_rows() data provider.
|
||||
*/
|
||||
public function get_rows_provider() {
|
||||
public static function get_rows_provider(): array {
|
||||
|
||||
return [
|
||||
'wrong table requested' => [
|
||||
|
||||
@@ -36,7 +36,7 @@ class util_test extends \advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
public function set_table_modified_by_sql_provider() {
|
||||
public static function set_table_modified_by_sql_provider(): array {
|
||||
global $DB;
|
||||
$prefix = $DB->get_prefix();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user