Skip to content

Commit

Permalink
MDL-74279 phpunit: Tests using sqlsrv AdoDB must reset settings
Browse files Browse the repository at this point in the history
AdoDB SQL*Server drivers use to modify some error and
logging preferences. As far as the connection is shared
with the main one, that implies that those settings
remain for the whole remaining execution.

We don't want his in tests, because can affect to other
tests at distance.

We are fixing this here, only for tests, because it
doesn't affect normal requests and because, once we
remove AdoDB this won't be needed anymore.
  • Loading branch information
stronk7 committed Mar 26, 2022
1 parent efda17d commit 8f414e4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions auth/db/tests/db_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ class auth_db_testcase extends advanced_testcase {
/** @var int The amount of users to create for the large user set deletion test */
protected $largedeletionsetsize = 128;

public static function tearDownAfterClass(): void {
global $DB;
// Apply sqlsrv native driver error and logging default
// settings while finishing the AdoDB tests.
if ($DB->get_dbfamily() === 'mssql') {
sqlsrv_configure("WarningsReturnAsErrors", false);
sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_OFF);
sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_ERROR);
}
}

protected function init_auth_database() {
global $DB, $CFG;
require_once("$CFG->dirroot/auth/db/auth.php");
Expand Down
12 changes: 12 additions & 0 deletions enrol/database/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class lib_test extends \advanced_testcase {

public static function tearDownAfterClass(): void {
global $DB;
// Apply sqlsrv native driver error and logging default
// settings while finishing the AdoDB tests.
if ($DB->get_dbfamily() === 'mssql') {
sqlsrv_configure("WarningsReturnAsErrors", false);
sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_OFF);
sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_ERROR);
}
}

/**
* Test for getting user enrolment actions.
*/
Expand Down
11 changes: 11 additions & 0 deletions enrol/database/tests/sync_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ class sync_test extends \advanced_testcase {
/** @var string Original error log */
protected $oldlog;

public static function tearDownAfterClass(): void {
global $DB;
// Apply sqlsrv native driver error and logging default
// settings while finishing the AdoDB tests.
if ($DB->get_dbfamily() === 'mssql') {
sqlsrv_configure("WarningsReturnAsErrors", false);
sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_OFF);
sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_ERROR);
}
}

protected function init_enrol_database() {
global $DB, $CFG;

Expand Down

0 comments on commit 8f414e4

Please sign in to comment.