diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index ece5852a056..c4c12211f67 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -128,7 +128,7 @@ jobs: - name: Setting up redis service run: | - choco install redis-64 --version 3.0.503 --no-progress + choco install redis --version 5.0.7 --no-progress nssm install redis redis-server nssm start redis diff --git a/lib/dml/tests/dml_mysqli_read_replica_test.php b/lib/dml/tests/dml_mysqli_read_replica_test.php index a52f7dfbb3d..6a7006ab2a1 100644 --- a/lib/dml/tests/dml_mysqli_read_replica_test.php +++ b/lib/dml/tests/dml_mysqli_read_replica_test.php @@ -158,19 +158,18 @@ final class dml_mysqli_read_replica_test extends \database_driver_testcase { $this->resetDebugging(); $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); + $this->assertNotEmpty($db2->get_records('user')); $debugging = array_map(function ($d) { return $d->message; }, $this->getDebuggingMessages()); $this->resetDebugging(); - $this->assertEquals(2, count($debugging)); + $this->assertCount(2, $debugging); $this->assertMatchesRegularExpression( sprintf( '/%s%s/', preg_quote("Readonly db connection failed for host {$invalidhost}:"), - '.* Name or service not known', - $cfg->dbname + '.*' ), $debugging[0] ); @@ -214,22 +213,23 @@ final class dml_mysqli_read_replica_test extends \database_driver_testcase { return $d->message; }, $this->getDebuggingMessages()); $this->resetDebugging(); - $this->assertEquals(2, count($debugging)); + $this->assertCount(2, $debugging); + // Read-only attempt to connect to the non-existent replica database will fail. + // Note: The expected regex pattern is a bit generic because the actual error message may vary between operating systems. $this->assertMatchesRegularExpression( sprintf( '/%s%s/', preg_quote("Readonly db connection failed for host {$cfg->dbhost}: "), - "Access denied for user .* to database '$invaliddb'", - $cfg->dbname + ".* database '$invaliddb'" ), $debugging[0] ); + // Read-write attempt to connect to the non-existent replica database will also fail. $this->assertMatchesRegularExpression( sprintf( '/%s%s/', preg_quote("Readwrite db connection failed for host {$cfg->dbhost}: "), - 'Access denied for user .* '.preg_quote("to database '$invaliddb'"), - $cfg->dbname + ".* '$invaliddb" ), $debugging[1] ); diff --git a/lib/dml/tests/dml_pgsql_read_replica_test.php b/lib/dml/tests/dml_pgsql_read_replica_test.php index d164923e378..781c9e04b53 100644 --- a/lib/dml/tests/dml_pgsql_read_replica_test.php +++ b/lib/dml/tests/dml_pgsql_read_replica_test.php @@ -282,22 +282,24 @@ class dml_pgsql_read_replica_test extends \advanced_testcase { $this->resetDebugging(); $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); + $this->assertNotEmpty($db2->get_records('user')); $debugging = array_map(function ($d) { return $d->message; }, $this->getDebuggingMessages()); $this->resetDebugging(); - $this->assertEquals(2, count($debugging)); + $this->assertCount(2, $debugging); + // Attempt to connect to the non-existent replica host will fail. + // Note: The expected regex pattern is a bit generic because the actual error message may vary between operating systems. $this->assertMatchesRegularExpression( sprintf( '/%s%s/', preg_quote("Readonly db connection failed for host {$invalidhost}: "), - '.* Name or service not known', - $cfg->dbname + '.*' ), $debugging[0] ); + // Attempt to connect to the existing DB host will succeed. $this->assertEquals("Readwrite db connection succeeded for host {$cfg->dbhost}", $debugging[1]); } } diff --git a/lib/tests/component_test.php b/lib/tests/component_test.php index 29f88ad1aa9..b8825588c32 100644 --- a/lib/tests/component_test.php +++ b/lib/tests/component_test.php @@ -1349,10 +1349,10 @@ final class component_test extends \advanced_testcase { foreach ($paths as $path) { // The composer.json can specify any arbitrary directory within the folder. - // It always contains a leading slash (/). + // It always contains a leading slash (/) or backslash (\) on Windows. // It may also have an optional trailing slash (/). // Concatenate the parts and removes the slashes. - $relativenamespacepath = trim("{$relativepath}/{$path}", '/'); + $relativenamespacepath = trim("{$relativepath}/{$path}", '/\\'); // The Moodle PSR-4 autoloader data has two formats: // - a string, for a single source; or @@ -1377,7 +1377,7 @@ final class component_test extends \advanced_testcase { // The Moodle composer file autoloads are a simple string[]. $autoloadnamefiles = $rc->getProperty('composerautoloadfiles')->getValue(null); foreach ($composer['autoload']['files'] as $file) { - $this->assertContains(trim($relativepath, '/') . "/{$file}", $autoloadnamefiles); + $this->assertContains(trim($relativepath, '/\\') . "/{$file}", $autoloadnamefiles); } } }