MDL-82988 PHPUnit: Add helper to get path to fixture

This commit is contained in:
Andrew Nicols 2024-10-27 15:45:19 +07:00 committed by meirzamoodle
parent f960ce6d5b
commit 7bec161984

View File

@ -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));
}
}