MDL-69356 unit tests: make some assertions dir separator agnostic
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Sun, 26 Jul 2020 15:13:36 +0000 (17:13 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Fri, 7 Aug 2020 00:09:15 +0000 (02:09 +0200)
lib/dml/tests/dml_test.php

index c244a11..fd6c81c 100644 (file)
@@ -51,6 +51,19 @@ class core_dml_testcase extends database_driver_testcase {
         return $table;
     }
 
+    /**
+     * Convert a unix string to a OS (dir separator) dependent string.
+     *
+     * @param string $source the original srting, using unix dir separators and newlines.
+     * @return string the resulting string, using current OS dir separators newlines.
+     */
+    private function unix_to_os_dirsep(string $source): string {
+        if (DIRECTORY_SEPARATOR !== '/') {
+            return str_replace('/', DIRECTORY_SEPARATOR, $source);
+        }
+        return $source; // No changes, so far.
+    }
+
     public function test_diagnose() {
         $DB = $this->tdb;
         $result = $DB->diagnose();
@@ -461,7 +474,7 @@ class core_dml_testcase extends database_driver_testcase {
 SELECT * FROM {users}
 -- line 65 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to ReflectionMethod->invoke()
 EOD;
-        $this->assertEquals($expected, $out);
+        $this->assertEquals($this->unix_to_os_dirsep($expected), $out);
 
         $CFG->debugsqltrace = 2;
         $out = $fixture->four($sql);
@@ -470,7 +483,7 @@ SELECT * FROM {users}
 -- line 65 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to ReflectionMethod->invoke()
 -- line 74 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->one()
 EOD;
-        $this->assertEquals($expected, $out);
+        $this->assertEquals($this->unix_to_os_dirsep($expected), $out);
 
         $CFG->debugsqltrace = 5;
         $out = $fixture->four($sql);
@@ -480,9 +493,9 @@ SELECT * FROM {users}
 -- line 74 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->one()
 -- line 83 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->two()
 -- line 92 of /lib/dml/tests/fixtures/test_dml_sql_debugging_fixture.php: call to test_dml_sql_debugging_fixture->three()
--- line 476 of /lib/dml/tests/dml_test.php: call to test_dml_sql_debugging_fixture->four()
+-- line 489 of /lib/dml/tests/dml_test.php: call to test_dml_sql_debugging_fixture->four()
 EOD;
-        $this->assertEquals($expected, $out);
+        $this->assertEquals($this->unix_to_os_dirsep($expected), $out);
 
         $CFG->debugsqltrace = 0;
     }