Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
1441 ariadna 2
use PHPUnit\Framework\Attributes\After;
1 efrain 3
// This file is part of Moodle - http://moodle.org/
4
//
5
// Moodle is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// Moodle is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
/**
19
 * The simplest PHPUnit test case customised for Moodle
20
 *
21
 * It is intended for isolated tests that do not modify database or any globals.
22
 *
23
 * @package    core
24
 * @category   phpunit
25
 * @copyright  2012 Petr Skoda {@link http://skodak.org}
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
abstract class basic_testcase extends base_testcase {
29
    /**
30
     * Constructs a test case with the given name.
31
     *
32
     *
33
     * @param string $name
34
     */
1441 ariadna 35
    final public function __construct($name = null) {
36
        parent::__construct($name);
1 efrain 37
 
38
        $this->setBackupGlobals(false);
39
        $this->setRunTestInSeparateProcess(false);
40
    }
41
 
42
    /**
1441 ariadna 43
     * Teardown method to reset data after tests.
1 efrain 44
     */
1441 ariadna 45
    #[After]
46
    final public function teardown_after_test(): void {
1 efrain 47
        global $DB;
48
 
49
        if ($DB->is_transaction_started()) {
50
            phpunit_util::reset_all_data();
1441 ariadna 51
            throw new coding_exception('basic_testcase ' . $this->getName() . ' is not supposed to use database transactions!');
1 efrain 52
        }
53
 
54
        phpunit_util::reset_all_data(true);
55
    }
1441 ariadna 56
 
57
    /**
58
     * Get the name of the test.
59
     *
60
     * Replaces the original PHPUnit method.
61
     * @return string
62
     */
63
    final public function getName(): string {
64
        return $this->name();
65
    }
1 efrain 66
}