Permalink
Browse files

Use built-in PHP temp file functions to create temp files.

  • Loading branch information...
1 parent f4d9c5f commit 83a5829625997231e05d65604c7d36760bc94630 @gauthierm committed Jan 2, 2012
Showing with 13 additions and 19 deletions.
  1. +13 −19 tests/setup.php
View
@@ -6,16 +6,14 @@
return;
}
-$tmpdir = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
- ? getenv('TMP')
- : '/tmp';
+$tempdir = (function_exists('sys_get_temp_dir'))
+ ? sys_get_temp_dir()
+ : (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
+ ? getenv('TMP')
+ : '/tmp';
-if (!chdir($tmpdir)) exit("Can't change into temporary directory");
-
-@mkdir('File_SearchReplace/');
-@mkdir('File_SearchReplace/dir');
-
-$onefilename = "stripiframetest.html";
+//$onefilename = "stripiframetest.html";
+$onefilename = tempnam($tempdir, 'one');
$onefilecontents = <<<IFRAME
</td>
</tr>
@@ -73,18 +71,16 @@
<td><img src="http://images.sourceforge.net/prdownloads/blank.gif" width="1" height="1" alt=""></td>
IFRAME;
-$f = fopen($tmpdir."/".$onefilename, "w");
-fwrite($f, $onefilecontents);
-fclose($f);
+file_put_contents($onefilename, $onefilecontents);
-$files[] = "tweakcopyright.php";
+$files[] = tempnam($tempdir, 'copyright');
$conts[] = "<?php
// +-----------------------------------------------------------------------+
// | Copyright (c) 2002-2003, Richard Heyes |
// | All rights reserved. |
// | |";
-$files[] = "File_SearchReplace/dir/tweakversion.phps";
+$files[] = tempnam($tempdir, 'version');
$conts[] = "/**
// +-----------------------------------------------------------------------+
// | Copyright (c) 2002-2003, Richard Heyes |
@@ -96,11 +92,9 @@
* @package File
*/";
-$files[] = "File_SearchReplace/empty.file";
+$files[] = tempnam($tempdir, 'empty');
$conts[] = "";
-foreach ($files as $k => $f) {
- $f = fopen($tmpdir."/".$f, "w");
- fwrite($f, $conts[$k]);
- fclose($f);
+foreach ($files as $k => $filename) {
+ file_put_contents($filename, $conts[$k]);
}

0 comments on commit 83a5829

Please sign in to comment.