This commit is contained in:
Sara Arjona
2025-01-20 16:47:56 +01:00
112 changed files with 1913 additions and 1759 deletions
@@ -1,4 +1,6 @@
<?php
use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\Attributes\Before;
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -55,14 +57,11 @@ abstract class database_driver_testcase extends base_testcase {
* Constructs a test case with the given name.
*
* @param string $name
* @param array $data
* @param string $dataName
*/
final public function __construct($name = null, array $data = array(), $dataName = '') {
parent::__construct($name, $data, $dataName);
final public function __construct($name = null) {
parent::__construct($name);
$this->setBackupGlobals(false);
$this->setBackupStaticAttributes(false);
$this->setRunTestInSeparateProcess(false);
}
@@ -100,9 +99,9 @@ abstract class database_driver_testcase extends base_testcase {
self::$extradb = $d;
}
protected function setUp(): void {
#[Before]
protected function setup_extradb(): void {
global $DB;
parent::setUp();
if (self::$extradb) {
$this->tdb = self::$extradb;
@@ -111,7 +110,8 @@ abstract class database_driver_testcase extends base_testcase {
}
}
protected function tearDown(): void {
#[After]
protected function teardown_extradb(): void {
// delete all test tables
$dbman = $this->tdb->get_manager();
$tables = $this->tdb->get_tables(false);
@@ -121,7 +121,6 @@ abstract class database_driver_testcase extends base_testcase {
$dbman->drop_table($table);
}
}
parent::tearDown();
}
public static function tearDownAfterClass(): void {
@@ -133,34 +132,13 @@ abstract class database_driver_testcase extends base_testcase {
parent::tearDownAfterClass();
}
/**
* Runs the bare test sequence.
* @return void
*/
public function runBare(): void {
try {
parent::runBare();
// Deal with any debugging messages.
$debugerror = phpunit_util::display_debugging_messages(true);
$this->resetDebugging();
if (!empty($debugerror)) {
trigger_error('Unexpected debugging() call detected.' . "\n" . $debugerror, E_USER_NOTICE);
}
} catch (Exception $ex) {
$e = $ex;
} catch (Throwable $ex) {
// Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
$e = $ex;
}
if (isset($e)) {
if ($this->tdb->is_transaction_started()) {
$this->tdb->force_transaction_rollback();
}
$this->tearDown();
throw $e;
#[After]
public function check_debugging(): void {
// Deal with any debugging messages.
$debugerror = phpunit_util::display_debugging_messages(true);
$this->resetDebugging();
if (!empty($debugerror)) {
trigger_error('Unexpected debugging() call detected.' . "\n" . $debugerror, E_USER_NOTICE);
}
}