Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
use PHPUnit\Framework\Attributes\After;
-
 
3
use PHPUnit\Framework\Attributes\Before;
2
// This file is part of Moodle - http://moodle.org/
4
// This file is part of Moodle - http://moodle.org/
3
//
5
//
4
// Moodle is free software: you can redistribute it and/or modify
6
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
7
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
8
// the Free Software Foundation, either version 3 of the License, or
Línea 34... Línea 36...
34
 *                         initialisation (the database can be empty).
36
 *                         initialisation (the database can be empty).
35
 * $CFG->phpunit_extra_drivers = array(
37
 * $CFG->phpunit_extra_drivers = array(
36
 *      1=>array('dbtype'=>'mysqli', 'dbhost'=>'localhost', 'dbname'=>'moodle', 'dbuser'=>'root', 'dbpass'=>'', 'prefix'=>'phpu2_'),
38
 *      1=>array('dbtype'=>'mysqli', 'dbhost'=>'localhost', 'dbname'=>'moodle', 'dbuser'=>'root', 'dbpass'=>'', 'prefix'=>'phpu2_'),
37
 *      2=>array('dbtype'=>'pgsql', 'dbhost'=>'localhost', 'dbname'=>'moodle', 'dbuser'=>'postgres', 'dbpass'=>'', 'prefix'=>'phpu2_'),
39
 *      2=>array('dbtype'=>'pgsql', 'dbhost'=>'localhost', 'dbname'=>'moodle', 'dbuser'=>'postgres', 'dbpass'=>'', 'prefix'=>'phpu2_'),
38
 *      3=>array('dbtype'=>'sqlsrv', 'dbhost'=>'127.0.0.1', 'dbname'=>'moodle', 'dbuser'=>'sa', 'dbpass'=>'', 'prefix'=>'phpu2_'),
40
 *      3=>array('dbtype'=>'sqlsrv', 'dbhost'=>'127.0.0.1', 'dbname'=>'moodle', 'dbuser'=>'sa', 'dbpass'=>'', 'prefix'=>'phpu2_'),
39
 *      4=>array('dbtype'=>'oci', 'dbhost'=>'127.0.0.1', 'dbname'=>'XE', 'dbuser'=>'sa', 'dbpass'=>'', 'prefix'=>'t_'),
-
 
40
 * );
41
 * );
41
 * define('PHPUNIT_TEST_DRIVER')=1; //number is index in the previous array
42
 * define('PHPUNIT_TEST_DRIVER')=1; //number is index in the previous array
42
 *
43
 *
43
 * @package    core
44
 * @package    core
44
 * @category   phpunit
45
 * @category   phpunit
Línea 54... Línea 55...
54
 
55
 
55
    /**
56
    /**
56
     * Constructs a test case with the given name.
57
     * Constructs a test case with the given name.
57
     *
58
     *
58
     * @param string $name
-
 
59
     * @param array  $data
-
 
60
     * @param string $dataName
59
     * @param string $name
61
     */
60
     */
62
    final public function __construct($name = null, array $data = array(), $dataName = '') {
61
    final public function __construct($name = null) {
Línea 63... Línea 62...
63
        parent::__construct($name, $data, $dataName);
62
        parent::__construct($name);
64
 
-
 
65
        $this->setBackupGlobals(false);
63
 
66
        $this->setBackupStaticAttributes(false);
64
        $this->setBackupGlobals(false);
Línea 67... Línea 65...
67
        $this->setRunTestInSeparateProcess(false);
65
        $this->setRunTestInSeparateProcess(false);
68
    }
66
    }
Línea 99... Línea 97...
99
        $d->connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
97
        $d->connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
Línea 100... Línea 98...
100
 
98
 
101
        self::$extradb = $d;
99
        self::$extradb = $d;
Línea -... Línea 100...
-
 
100
    }
102
    }
101
 
103
 
102
    #[Before]
104
    protected function setUp(): void {
-
 
Línea 105... Línea 103...
105
        global $DB;
103
    protected function setup_extradb(): void {
106
        parent::setUp();
104
        global $DB;
107
 
105
 
108
        if (self::$extradb) {
106
        if (self::$extradb) {
109
            $this->tdb = self::$extradb;
107
            $this->tdb = self::$extradb;
110
        } else {
108
        } else {
Línea -... Línea 109...
-
 
109
            $this->tdb = $DB;
111
            $this->tdb = $DB;
110
        }
112
        }
111
    }
113
    }
112
 
114
 
113
    #[After]
115
    protected function tearDown(): void {
114
    protected function teardown_extradb(): void {
116
        // delete all test tables
115
        // delete all test tables
117
        $dbman = $this->tdb->get_manager();
116
        $dbman = $this->tdb->get_manager();
118
        $tables = $this->tdb->get_tables(false);
117
        $tables = $this->tdb->get_tables(false);
119
        foreach($tables as $tablename) {
118
        foreach($tables as $tablename) {
120
            if (strpos($tablename, 'test_table') === 0) {
119
            if (strpos($tablename, 'test_table') === 0) {
121
                $table = new xmldb_table($tablename);
-
 
122
                $dbman->drop_table($table);
120
                $table = new xmldb_table($tablename);
Línea 123... Línea 121...
123
            }
121
                $dbman->drop_table($table);
124
        }
122
            }
125
        parent::tearDown();
123
        }
Línea 132... Línea 130...
132
        }
130
        }
133
        phpunit_util::reset_all_data(null);
131
        phpunit_util::reset_all_data(null);
134
        parent::tearDownAfterClass();
132
        parent::tearDownAfterClass();
135
    }
133
    }
Línea 136... Línea -...
136
 
-
 
137
    /**
-
 
138
     * Runs the bare test sequence.
-
 
139
     * @return void
134
 
140
     */
135
    #[After]
141
    public function runBare(): void {
-
 
142
        try {
-
 
143
            parent::runBare();
-
 
144
 
136
    public function check_debugging(): void {
145
            // Deal with any debugging messages.
137
        // Deal with any debugging messages.
146
            $debugerror = phpunit_util::display_debugging_messages(true);
138
        $debugerror = phpunit_util::display_debugging_messages(true);
147
            $this->resetDebugging();
139
        $this->resetDebugging();
148
            if (!empty($debugerror)) {
140
        if (!empty($debugerror)) {
149
                trigger_error('Unexpected debugging() call detected.' . "\n" . $debugerror, E_USER_NOTICE);
-
 
150
            }
-
 
151
 
-
 
152
        } catch (Exception $ex) {
-
 
153
            $e = $ex;
-
 
154
        } catch (Throwable $ex) {
-
 
155
            // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
-
 
156
            $e = $ex;
-
 
157
        }
-
 
158
 
-
 
159
        if (isset($e)) {
-
 
160
            if ($this->tdb->is_transaction_started()) {
-
 
161
                $this->tdb->force_transaction_rollback();
-
 
162
            }
-
 
163
            $this->tearDown();
-
 
164
            throw $e;
141
            trigger_error('Unexpected debugging() call detected.' . "\n" . $debugerror, E_USER_NOTICE);
165
        }
142
        }
Línea 166... Línea 143...
166
    }
143
    }
167
 
144