From 03db8c14c469fc9800c633efa756151df26f8f4f Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 4 May 2019 22:52:00 +0100 Subject: [PATCH] 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 --- tests/phpunit/MediaWikiTestCase.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; -- 2.20.1