$output = strtr( $output, $pairs );
}
- # Windows, or at least the fc utility, is retarded
- $slash = wfIsWindows() ? '\\' : '/';
- $prefix = wfTempDir() . "{$slash}mwParser-" . mt_rand();
-
- $infile = "$prefix-$inFileTail";
+ $infile = tempnam( wfTempDir(), "mwParser-$inFileTail" );
$this->dumpToFile( $input, $infile );
- $outfile = "$prefix-$outFileTail";
+ $outfile = tempnam( wfTempDir(), "mwParser-$outFileTail" );
$this->dumpToFile( $output, $outfile );
global $wgDiff3;
* @return string Absolute name of the temporary directory
*/
protected function getNewTempDirectory() {
- // Starting of with a temporary /file/.
+ // Starting of with a temporary *file*.
$fileName = $this->getNewTempFile();
- // Converting the temporary /file/ to a /directory/
+ // Converting the temporary file to a *directory*.
// The following is not atomic, but at least we now have a single place,
- // where temporary directory creation is bundled and can be improved
+ // where temporary directory creation is bundled and can be improved.
unlink( $fileName );
- $this->assertTrue( wfMkdirParents( $fileName ) );
+ // If this fails for some reason, PHP will warn and fail the test.
+ mkdir( $fileName, 0777, /* recursive = */ true );
return $fileName;
}
* @covers CSSMin::getMimeType
*/
public function testGetMimeType( $fileContents, $fileExtension, $expected ) {
- $fileName = wfTempDir() . DIRECTORY_SEPARATOR . uniqid( 'MW_PHPUnit_CSSMinTest_' ) . '.'
- . $fileExtension;
- $this->addTmpFiles( $fileName );
+ // Automatically removed when it falls out of scope (including if the test fails)
+ $file = TempFSFile::factory( 'PHPUnit_CSSMinTest_', $fileExtension, wfTempDir() );
+ $fileName = $file->getPath();
file_put_contents( $fileName, $fileContents );
$this->assertSame( $expected, CSSMin::getMimeType( $fileName ) );
}
protected function doGetLocalCopyMulti( array $params ) {
$tmpFiles = []; // (path => MockFSFile)
foreach ( $params['srcs'] as $src ) {
- $tmpFiles[$src] = new MockFSFile( wfTempDir() . '/' . wfRandomString( 32 ) );
+ $tmpFiles[$src] = new MockFSFile( "Fake path for $src" );
}
return $tmpFiles;
}
* @since 1.28
*/
class MockLocalRepo extends LocalRepo {
- function getLocalCopy( $virtualUrl ) {
- return new MockFSFile( wfTempDir() . '/' . wfRandomString( 32 ) );
+ public function getLocalCopy( $virtualUrl ) {
+ return new MockFSFile( "Fake path for $virtualUrl" );
}
- function getLocalReference( $virtualUrl ) {
- return new MockFSFile( wfTempDir() . '/' . wfRandomString( 32 ) );
+ public function getLocalReference( $virtualUrl ) {
+ return new MockFSFile( "Fake path for $virtualUrl" );
}
- function getFileProps( $virtualUrl ) {
+ public function getFileProps( $virtualUrl ) {
$fsFile = $this->getLocalReference( $virtualUrl );
-
return $fsFile->getProps();
}
}