From: Timo Tijhof Date: Sat, 4 May 2019 21:52:00 +0000 (+0100) Subject: tests: Avoid namespace slashes in getNewTempFile() utility X-Git-Tag: 1.34.0-rc.0~1796^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=03db8c14c469fc9800c633efa756151df26f8f4f;p=lhc%2Fweb%2Fwiklou.git tests: Avoid namespace slashes in getNewTempFile() utility 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 --- diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index ebc3b79c3f..b37f4aac59 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -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;