tests: Avoid namespace slashes in getNewTempFile() utility
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 4 May 2019 21:52:00 +0000 (22:52 +0100)
committerKrinkle <krinklemail@gmail.com>
Sat, 4 May 2019 22:01:20 +0000 (22:01 +0000)
This will make things easier to reason about.

I'm hoping this will fix the issue that (unmerged) Iff28c27990 is
triggering in WikibaseMediaInfo tests.

Change-Id: I7eb4a8c6bf6f6f7103190b9f225579176a7440d6

tests/phpunit/MediaWikiTestCase.php

index ebc3b79..b37f4aa 100644 (file)
@@ -472,7 +472,17 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
         * @return string Absolute name of the temporary file
         */
        protected function getNewTempFile() {
-               $fileName = tempnam( wfTempDir(), 'MW_PHPUnit_' . static::class . '_' );
+               $fileName = tempnam(
+                       wfTempDir(),
+                       // Avoid backslashes here as they result in inconsistent results
+                       // between Windows and other OS, as well as between functions
+                       // that try to normalise these in one or both directions.
+                       // For example, tempnam rejects directory separators in the prefix which
+                       // means it rejects any namespaced class on Windows.
+                       // And then there is, wfMkdirParents which normalises paths always
+                       // whereas most other PHP and MW functions do not.
+                       'MW_PHPUnit_' . strtr( static::class, [ '\\' => '_' ] ) . '_'
+               );
                $this->tmpFiles[] = $fileName;
 
                return $fileName;