fopen_variation5.phpt [plain text]
--TEST--
Test fopen() function : variation: use include path and stream context (absolute directories in path)
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
$thisTestDir = basename(__FILE__, ".php") . ".dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$workingDir = "workdir";
$filename = basename(__FILE__, ".php") . ".tmp";
$scriptDir = dirname(__FILE__);
$baseDir = getcwd();
$secondFile = $baseDir."/dir2/".$filename;
$firstFile = "../dir1/".$filename;
$scriptFile = $scriptDir.'/'.$filename;
$newdirs = array("dir1", "dir2", "dir3");
$pathSep = ":";
$newIncludePath = "";
if(substr(PHP_OS, 0, 3) == 'WIN' ) {
$pathSep = ";";
}
foreach($newdirs as $newdir) {
mkdir($newdir);
$newIncludePath .= $baseDir.'/'.$newdir.$pathSep;
}
mkdir($workingDir);
chdir($workingDir);
echo "\n--- testing include path ---\n";
set_include_path($newIncludePath);
$modes = array("r", "r+", "rt");
foreach($modes as $mode) {
test_fopen($mode);
}
restore_include_path();
chdir($baseDir);
rmdir($workingDir);
foreach($newdirs as $newdir) {
rmdir($newdir);
}
chdir("..");
rmdir($thisTestDir);
function test_fopen($mode) {
global $scriptFile, $secondFile, $firstFile, $filename;
$h = fopen($secondFile, "w");
fwrite($h, (binary) "in dir2");
fclose($h);
echo "\n** testing with mode=$mode **\n";
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
$h = fopen($firstFile, "w");
fwrite($h, (binary) "in dir1");
fclose($h);
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
$h = fopen($filename, "w");
fwrite($h, (binary) "in working dir");
fclose($h);
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
unlink($firstFile);
unlink($secondFile);
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
$h = fopen($scriptFile, "w");
fwrite($h, (binary) "in script dir");
fclose($h);
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
unlink($filename);
unlink($scriptFile);
}
?>
===DONE===
--EXPECTF--
--- testing include path ---
** testing with mode=r **
in dir2
in dir1
in dir1
in working dir
in script dir
** testing with mode=r+ **
in dir2
in dir1
in dir1
in working dir
in script dir
** testing with mode=rt **
in dir2
in dir1
in dir1
in working dir
in script dir
===DONE===