. /** * The simplest PHPUnit test case customised for Moodle * * It is intended for isolated tests that do not modify database or any globals. * * @package core * @category phpunit * @copyright 2012 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ abstract class basic_testcase extends base_testcase { /** * Constructs a test case with the given name. * * * @param string $name */ final public function __construct($name = null) { parent::__construct($name); $this->setBackupGlobals(false); $this->setRunTestInSeparateProcess(false); } /** * Teardown method to reset data after tests. */ #[After] final public function teardown_after_test(): void { global $DB; if ($DB->is_transaction_started()) { phpunit_util::reset_all_data(); throw new coding_exception('basic_testcase ' . $this->getName() . ' is not supposed to use database transactions!'); } phpunit_util::reset_all_data(true); } /** * Get the name of the test. * * Replaces the original PHPUnit method. * @return string */ final public function getName(): string { return $this->name(); } }