Skip to content

Commit

Permalink
MDL-73713 dml: test namespaces fix - a noop
Browse files Browse the repository at this point in the history
  • Loading branch information
srdjan-catalyst committed Mar 23, 2022
1 parent 8a386d6 commit 343384d
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 18 deletions.
7 changes: 5 additions & 2 deletions lib/dml/tests/dml_mysqli_read_slave_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
* @category dml
* @copyright 2018 Srdjan Janković, Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \mysqli_native_moodle_database
*/

namespace core;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/fixtures/read_slave_moodle_database_mock_mysqli.php');
Expand All @@ -35,7 +38,7 @@
* @copyright 2018 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_dml_mysqli_read_slave_testcase extends base_testcase {
class dml_mysqli_read_slave_test extends \base_testcase {
/**
* Test readonly handle is not used for reading from special pg_*() call queries,
* pg_try_advisory_lock and pg_advisory_unlock.
Expand Down Expand Up @@ -80,7 +83,7 @@ public function test_real_readslave_connect_fail() : void {
'connecttimeout' => 1
];

$db2 = moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary);
$db2 = \moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary);
$db2->connect($cfg->dbhost, $cfg->dbuser, $cfg->dbpass, $cfg->dbname, $cfg->prefix, $cfg->dboptions);
$this->assertTrue(count($db2->get_records('user')) > 0);
}
Expand Down
13 changes: 8 additions & 5 deletions lib/dml/tests/dml_pgsql_read_slave_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
* @category dml
* @copyright 2018 Srdjan Janković, Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \pgsql_native_moodle_database
*/

namespace core;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/fixtures/read_slave_moodle_database_mock_pgsql.php');
Expand All @@ -35,7 +38,7 @@
* @copyright 2018 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_dml_pgsql_read_slave_testcase extends base_testcase {
class dml_pgsql_read_slave_test extends \base_testcase {
/**
* Test correct database handles are used for cursors
*
Expand Down Expand Up @@ -135,12 +138,12 @@ public function test_temp_table() : void {
}

// Get a separate disposable db connection handle with guaranteed 'readonly' config.
$db2 = moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary);
$db2 = \moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary);
$db2->connect($cfg->dbhost, $cfg->dbuser, $cfg->dbpass, $cfg->dbname, $cfg->prefix, $cfg->dboptions);

$dbman = $db2->get_manager();

$table = new xmldb_table('silly_test_table');
$table = new \xmldb_table('silly_test_table');
$table->add_field('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->add_field('msg', XMLDB_TYPE_CHAR, 255);
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
Expand All @@ -155,7 +158,7 @@ public function test_temp_table() : void {
$db2->get_records('silly_test_table');
$this->assertEquals($reads, $db2->perf_get_reads_slave());

$table2 = new xmldb_table('silly_test_table2');
$table2 = new \xmldb_table('silly_test_table2');
$table2->add_field('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table2->add_field('msg', XMLDB_TYPE_CHAR, 255);
$table2->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
Expand Down Expand Up @@ -193,7 +196,7 @@ public function test_real_readslave_connect_fail() : void {
'connecttimeout' => 1
];

$db2 = moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary);
$db2 = \moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary);
$db2->connect($cfg->dbhost, $cfg->dbuser, $cfg->dbpass, $cfg->dbname, $cfg->prefix, $cfg->dboptions);
$this->assertTrue(count($db2->get_records('user')) > 0);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/dml/tests/dml_read_slave_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* @coversDefaultClass \moodle_temptables
*/

namespace core;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/fixtures/read_slave_moodle_database_table_names.php');
Expand Down
6 changes: 4 additions & 2 deletions lib/dml/tests/fixtures/read_slave_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/test_moodle_database.php');
Expand All @@ -37,7 +39,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class read_slave_moodle_database extends test_moodle_database {
use moodle_read_slave_trait;
use \moodle_read_slave_trait;

/** @var string */
protected $handle;
Expand All @@ -58,7 +60,7 @@ public function raw_connect(string $dbhost, string $dbuser, string $dbpass, stri
$this->prefix = $prefix;

if ($dbhost == 'test_ro_fail') {
throw new dml_connection_exception($dbhost);
throw new \dml_connection_exception($dbhost);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/../../mysqli_native_moodle_database.php');
Expand All @@ -36,7 +38,7 @@
* @copyright 2018 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class read_slave_moodle_database_mock_mysqli extends mysqli_native_moodle_database {
class read_slave_moodle_database_mock_mysqli extends \mysqli_native_moodle_database {
use test_moodle_read_slave_trait;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/../../pgsql_native_moodle_database.php');
Expand All @@ -36,6 +38,6 @@
* @copyright 2018 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class read_slave_moodle_database_mock_pgsql extends pgsql_native_moodle_database {
class read_slave_moodle_database_mock_pgsql extends \pgsql_native_moodle_database {
use test_moodle_read_slave_trait;
}
2 changes: 2 additions & 0 deletions lib/dml/tests/fixtures/read_slave_moodle_database_special.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/read_slave_moodle_database.php');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/read_slave_moodle_database.php');
Expand Down
6 changes: 4 additions & 2 deletions lib/dml/tests/fixtures/test_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/../../moodle_database.php');
Expand All @@ -38,7 +40,7 @@
* @copyright 2018 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class test_moodle_database extends moodle_database {
abstract class test_moodle_database extends \moodle_database {

/** @var string */
private $error;
Expand All @@ -53,7 +55,7 @@ abstract class test_moodle_database extends moodle_database {
public function __construct($external = false) {
parent::__construct($external);

$this->temptables = new moodle_temptables($this);
$this->temptables = new \moodle_temptables($this);
}

/**
Expand Down
6 changes: 2 additions & 4 deletions lib/dml/tests/fixtures/test_moodle_read_slave_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/../../pgsql_native_moodle_database.php');
namespace core;

/**
* Read slave helper that exposes selected moodle_read_slave_trait metods
Expand Down Expand Up @@ -55,7 +53,7 @@ public function __construct($external = false) {
$this->dbhreadonly = $ro;
$this->set_db_handle($this->dbhwrite);

$this->temptables = new moodle_temptables($this);
$this->temptables = new \moodle_temptables($this);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/dml/tests/fixtures/test_sql_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace core;

defined('MOODLE_INTERNAL') || die();

require_once(__DIR__.'/../../../ddl/sql_generator.php');
Expand All @@ -36,7 +38,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
class test_sql_generator extends sql_generator {
class test_sql_generator extends \sql_generator {
// phpcs:disable moodle.NamingConventions.ValidFunctionName.LowercaseMethod

/**
Expand Down

0 comments on commit 343384d

Please sign in to comment.