mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-82988 PHPUnit: Add helper to get path to fixture
This commit is contained in:
parent
f960ce6d5b
commit
7bec161984
@ -830,6 +830,30 @@ abstract class advanced_testcase extends base_testcase {
|
||||
$this->resetDebugging();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
$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");
|
||||
}
|
||||
|
||||
return $fullpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to load a fixture from a component's fixture directory.
|
||||
*
|
||||
@ -841,15 +865,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;
|
||||
@ -861,6 +876,6 @@ abstract class advanced_testcase extends base_testcase {
|
||||
global $COURSE;
|
||||
global $SITE;
|
||||
|
||||
require_once($fullpath);
|
||||
require_once(static::get_fixture_path($component, $path));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user