File system tests: checked on PHP 6.0 latest snap (Windows, Linux and Linux 64 bit) - there are quite a large number of failing test cases (all marked with an XFAIL section), they wiill have bugs raised to cover the issues real soon now...

This commit is contained in:
Ant Phillips 2008-11-26 17:48:41 +00:00
parent 3c06283750
commit 977a9400fe
212 changed files with 20493 additions and 1423 deletions

View File

@ -1,5 +1,7 @@
--TEST--
File type functions
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
@ -10,7 +12,6 @@ if (substr(PHP_OS, 0, 3) != 'WIN') {
<?php
chdir(dirname(__FILE__));
@unlink('test.file');
@unlink('test.link');
if (file_exists('test.file')) {
echo "test.file exists\n";
} else {
@ -23,22 +24,11 @@ if (file_exists('test.file')) {
} else {
echo "test.file does not exist\n";
}
sleep (2);
if (file_exists('test.link')) {
echo "test.link exists\n";
} else {
echo "test.link does not exist\n";
}
if (is_link('test.file')) {
echo "test.file is a symlink\n";
} else {
echo "test.file is not a symlink\n";
}
if (is_link('test.link')) {
echo "test.link is a symlink\n";
} else {
echo "test.link is not a symlink\n";
}
if (file_exists('test.file')) {
echo "test.file exists\n";
} else {
@ -52,7 +42,6 @@ for ($i = 0; $i <= 12; $i++) {
}
}
echo "test.file is " . filetype('test.file') . "\n";
echo "test.link is " . filetype('test.link') . "\n";
printf ("test.file permissions are 0%o\n", 0777 & fileperms('test.file'));
echo "test.file size is " . filesize('test.file') . "\n";
if (is_writeable('test.file')) {
@ -70,16 +59,6 @@ if (is_file('test.file')) {
} else {
echo "test.file is not a regular file\n";
}
if (is_file('test.link')) {
echo "test.link is a regular file\n";
} else {
echo "test.link is not a regular file\n";
}
if (is_dir('test.link')) {
echo "test.link is a directory\n";
} else {
echo "test.link is not a directory\n";
}
if (is_dir('../file')) {
echo "../file is a directory\n";
} else {
@ -106,20 +85,16 @@ if (file_exists('test.file')) {
--EXPECT--
test.file does not exist
test.file exists
test.link does not exist
test.file is not a symlink
test.link is not a symlink
test.file exists
test.file is file
test.link is file
test.file permissions are 0666
test.file size is 0
test.file is writeable
test.file is readable
test.file is a regular file
test.link is not a regular file
test.link is not a directory
../file is a directory
test.file is not a directory
test.file does not exist
test.file does not exist

View File

@ -0,0 +1,125 @@
--TEST--
Test fileatime(), filemtime(), filectime() & touch() functions : usage variation
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
die('skip.. only for Windows');
}
?>
--FILE--
<?php
/*
Prototype: int fileatime ( string $filename );
Description: Returns the time the file was last accessed, or FALSE
in case of an error. The time is returned as a Unix timestamp.
Prototype: int filemtime ( string $filename );
Description: Returns the time the file was last modified, or FALSE
in case of an error.
Prototype: int filectime ( string $filename );
Description: Returns the time the file was last changed, or FALSE
in case of an error. The time is returned as a Unix timestamp.
Prototype: bool touch ( string $filename [, int $time [, int $atime]] );
Description: Attempts to set the access and modification times of the file
named in the filename parameter to the value given in time.
*/
/*
Prototype: void stat_fn(string $filename);
Description: Prints access, modification and change times of a file
*/
function stat_fn( $filename ) {
echo "\n-- File '$filename' --\n";
echo "-- File access time is => ";
echo fileatime($filename)."\n";
clearstatcache();
echo "-- File modification time is => ";
echo filemtime($filename)."\n";
clearstatcache();
echo "-- inode change time is => ";
echo filectime($filename)."\n";
clearstatcache();
}
echo "*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***\n";
echo "\n*** testing file info ***";
stat_fn(NULL);
stat_fn(false);
stat_fn('');
stat_fn(' ');
stat_fn('|');
echo "\n*** testing touch ***";
var_dump(touch(NULL));
var_dump(touch(false));
var_dump(touch(''));
//php generates permission denied, we generate No such file or dir.
var_dump(touch(' '));
var_dump(touch('|'));
echo "Done";
?>
--EXPECTF--
*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***
*** testing file info ***
-- File '' --
-- File access time is =>
-- File modification time is =>
-- inode change time is =>
-- File '' --
-- File access time is =>
-- File modification time is =>
-- inode change time is =>
-- File '' --
-- File access time is =>
-- File modification time is =>
-- inode change time is =>
-- File ' ' --
-- File access time is =>
Warning: fileatime(): stat failed for in %s on line %d
-- File modification time is =>
Warning: filemtime(): stat failed for in %s on line %d
-- inode change time is =>
Warning: filectime(): stat failed for in %s on line %d
-- File '|' --
-- File access time is =>
Warning: fileatime(): stat failed for | in %s on line %d
-- File modification time is =>
Warning: filemtime(): stat failed for | in %s on line %d
-- inode change time is =>
Warning: filectime(): stat failed for | in %s on line %d
*** testing touch ***
Warning: touch(): Unable to create file because No such file or directory in %s on line %d
bool(false)
Warning: touch(): Unable to create file because No such file or directory in %s on line %d
bool(false)
Warning: touch(): Unable to create file because No such file or directory in %s on line %d
bool(false)
Warning: touch(): Unable to create file because %s in %s on line %d
bool(false)
Warning: touch(): Unable to create file | because %s in %s on line %d
bool(false)
Done

View File

@ -0,0 +1,113 @@
--TEST--
Test fileatime(), filemtime(), filectime() & touch() functions : usage variation
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip.. only for Non Windows Systems');
}
?>
--FILE--
<?php
/*
Prototype: int fileatime ( string $filename );
Description: Returns the time the file was last accessed, or FALSE
in case of an error. The time is returned as a Unix timestamp.
Prototype: int filemtime ( string $filename );
Description: Returns the time the file was last modified, or FALSE
in case of an error.
Prototype: int filectime ( string $filename );
Description: Returns the time the file was last changed, or FALSE
in case of an error. The time is returned as a Unix timestamp.
Prototype: bool touch ( string $filename [, int $time [, int $atime]] );
Description: Attempts to set the access and modification times of the file
named in the filename parameter to the value given in time.
*/
/*
Prototype: void stat_fn(string $filename);
Description: Prints access, modification and change times of a file
*/
function stat_fn( $filename ) {
echo "\n-- File '$filename' --\n";
echo "-- File access time is => ";
echo fileatime($filename)."\n";
clearstatcache();
echo "-- File modification time is => ";
echo filemtime($filename)."\n";
clearstatcache();
echo "-- inode change time is => ";
echo filectime($filename)."\n";
clearstatcache();
}
echo "*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***\n";
echo "\n*** testing touch ***\n";
var_dump(touch(NULL));
var_dump(touch(false));
var_dump(touch(''));
var_dump(touch(' '));
var_dump(touch('|'));
echo "\n*** testing file info ***";
stat_fn(NULL);
stat_fn(false);
stat_fn('');
stat_fn(' ');
stat_fn('|');
var_dump(unlink(' '));
var_dump(unlink('|'));
echo "Done";
?>
--EXPECTF--
*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***
*** testing touch ***
Warning: touch(): Unable to create file because No such file or directory in %s on line %d
bool(false)
Warning: touch(): Unable to create file because No such file or directory in %s on line %d
bool(false)
Warning: touch(): Unable to create file because No such file or directory in %s on line %d
bool(false)
bool(true)
bool(true)
*** testing file info ***
-- File '' --
-- File access time is =>
-- File modification time is =>
-- inode change time is =>
-- File '' --
-- File access time is =>
-- File modification time is =>
-- inode change time is =>
-- File '' --
-- File access time is =>
-- File modification time is =>
-- inode change time is =>
-- File ' ' --
-- File access time is => %d
-- File modification time is => %d
-- inode change time is => %d
-- File '|' --
-- File access time is => %d
-- File modification time is => %d
-- inode change time is => %d
bool(true)
bool(true)
Done

View File

@ -11,7 +11,7 @@ $fp = fopen($filename, 'w');
fclose($fp);
if(fileowner($filename) == 0) {
unlink ($filename);
die('skip cannot be run as root');
die('skip...cannot be run as root\n');
}
unlink($filename);
@ -68,13 +68,13 @@ unlink( dirname(__FILE__)."/006_error.tmp");
--EXPECTF--
*** Testing error conditions for fileperms(), chmod() ***
Warning: chmod(): %s in %s on line %d
Warning: chmod(): Operation not permitted in %s on line %d
bool(false)
100644
%d
Warning: chmod(): %s in %s on line %d
Warning: chmod(): Operation not permitted in %s on line %d
bool(false)
40755
%d
Warning: chmod(): No such file or directory in %s on line %d
bool(false)
@ -105,3 +105,4 @@ Warning: fileperms() expects exactly 1 parameter, 2 given in %s on line %d
NULL
*** Done ***

View File

@ -11,7 +11,7 @@ $fp = fopen($filename, 'w');
fclose($fp);
if(fileowner($filename) == 0) {
unlink ($filename);
die('skip cannot be run as root');
die('skip...cannot be run as root\n');
}
unlink($filename);
@ -88,99 +88,100 @@ chmod(dirname(__FILE__)."/006_variation2", 0777);
unlink(dirname(__FILE__)."/006_variation2.tmp");
rmdir(dirname(__FILE__)."/006_variation2");
?>
--EXPECTF--
--EXPECTF--
*** Testing fileperms() & chmod() : usage variations ***
*** Testing fileperms(), chmod() with miscellaneous permissions ***
-- Iteration 1 --
bool(true)
107777
%d
bool(true)
47777
%d
-- Iteration 2 --
bool(true)
100000
%d
bool(true)
40000
%d
-- Iteration 3 --
bool(true)
101000
%d
bool(true)
41000
%d
-- Iteration 4 --
bool(true)
101111
%d
bool(true)
41111
%d
-- Iteration 5 --
bool(true)
107001
%d
bool(true)
47001
%d
-- Iteration 6 --
bool(true)
100001
%d
bool(true)
40001
%d
-- Iteration 7 --
bool(true)
101411
%d
bool(true)
41411
%d
-- Iteration 8 --
bool(true)
107141
%d
bool(true)
47141
%d
-- Iteration 9 --
bool(true)
100637
%d
bool(true)
40637
%d
-- Iteration 10 --
bool(true)
103567
%d
bool(true)
43567
%d
-- Iteration 11 --
bool(true)
103567
%d
bool(true)
43567
%d
-- Iteration 12 --
Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d
NULL
103567
%d
Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d
NULL
43567
%d
-- Iteration 13 --
Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d
NULL
103567
%d
Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d
NULL
43567
%d
-- Iteration 14 --
Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d
NULL
103567
%d
Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d
NULL
43567
%d
-- Iteration 15 --
Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d
NULL
103567
%d
Warning: chmod() expects parameter 2 to be long, Unicode string given in %s on line %d
NULL
43567
%d
*** Done ***

View File

@ -1,5 +1,9 @@
--TEST--
Test fopen, fclose() & feof() functions: error conditions
--XFAIL--
Return values are inconsistent (and have changed from previous versions)
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/*
@ -44,7 +48,6 @@ var_dump( feof($fp, "handle"));
fclose($fp);
/* test invalid arguments : non-resources */
chdir(dirname(__FILE__));
echo "-- Testing fopen(), fclose() & feof() with invalid arguments --\n";
$invalid_args = array (
"string",
@ -74,32 +77,32 @@ bool(false)
Warning: fopen() expects at least 2 parameters, 0 given in %s on line %d
bool(false)
Warning: fclose(): %d is not a valid stream resource in %s on line %d
Warning: fclose(): 5 is not a valid stream resource in %s on line %d
bool(false)
Warning: fclose() expects parameter 1 to be resource, Unicode string given in %s on line %d
NULL
bool(false)
Warning: fclose() expects exactly 1 parameter, 0 given in %s on line %d
NULL
bool(false)
Warning: feof(): %d is not a valid stream resource in %s on line %d
Warning: feof(): 5 is not a valid stream resource in %s on line %d
bool(false)
Warning: feof() expects parameter 1 to be resource, Unicode string given in %s on line %d
NULL
bool(false)
Warning: feof() expects exactly 1 parameter, 0 given in %s on line %d
NULL
bool(false)
Warning: fopen() expects at most 4 parameters, 5 given in %s on line %d
bool(false)
Warning: fclose() expects exactly 1 parameter, 2 given in %s on line %d
NULL
bool(false)
Warning: feof() expects exactly 1 parameter, 2 given in %s on line %d
NULL
bool(false)
-- Testing fopen(), fclose() & feof() with invalid arguments --
-- Iteration 1 --
@ -107,65 +110,66 @@ Warning: fopen(string): failed to open stream: No such file or directory in %s o
bool(false)
Warning: fclose() expects parameter 1 to be resource, Unicode string given in %s on line %d
NULL
bool(false)
Warning: feof() expects parameter 1 to be resource, Unicode string given in %s on line %d
NULL
bool(false)
-- Iteration 2 --
Warning: fopen(10): failed to open stream: No such file or directory in %s on line %d
bool(false)
Warning: fclose() expects parameter 1 to be resource, integer given in %s on line %d
NULL
bool(false)
Warning: feof() expects parameter 1 to be resource, integer given in %s on line %d
NULL
bool(false)
-- Iteration 3 --
Warning: fopen(10.5): failed to open stream: No such file or directory in %s on line %d
bool(false)
Warning: fclose() expects parameter 1 to be resource, double given in %s on line %d
NULL
bool(false)
Warning: feof() expects parameter 1 to be resource, double given in %s on line %d
NULL
bool(false)
-- Iteration 4 --
Warning: fopen(1): failed to open stream: No such file or directory in %s on line %d
bool(false)
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
NULL
bool(false)
Warning: feof() expects parameter 1 to be resource, boolean given in %s on line %d
NULL
bool(false)
-- Iteration 5 --
Notice: Array to string conversion in %s on line %d
Warning: fopen(Array): failed to open stream: No such file or directory in %s on line %d
Warning: fopen() expects parameter 1 to be string, array given in %s on line %d
bool(false)
Warning: fclose() expects parameter 1 to be resource, array given in %s on line %d
NULL
bool(false)
Warning: feof() expects parameter 1 to be resource, array given in %s on line %d
NULL
bool(false)
-- Iteration 6 --
bool(false)
Warning: fclose() expects parameter 1 to be resource, null given in %s on line %d
NULL
bool(false)
Warning: feof() expects parameter 1 to be resource, null given in %s on line %d
NULL
bool(false)
-- Iteration 7 --
bool(false)
Warning: fclose() expects parameter 1 to be resource, Unicode string given in %s on line %d
NULL
bool(false)
Warning: feof() expects parameter 1 to be resource, Unicode string given in %s on line %d
NULL
bool(false)

View File

@ -0,0 +1,341 @@
--TEST--
basename
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
die('skip Windows only basename tests');
}
?>
--FILE--
<?php
/*
* proto string basename(string path [, string suffix])
* Function is implemented in ext/standard/string.c
*/
$file_paths = array (
/* simple paths */
array("bar"),
array("\\foo\\bar"),
array("foo\\bar"),
array("\\bar"),
/* simple paths with trailing slashes */
array("bar\\"),
array("\\bar\\"),
array("\\foo\\bar\\"),
array("foo\\bar\\"),
array("\\bar\\"),
/* paths with suffix removal */
array("bar.zip", ".zip"),
array("bar.zip", "bar.zip"),
array("\\foo\\bar.zip", ".zip"),
array("foo\\bar.zip", ".zip"),
array("\\bar.zip", ".zip"),
/* paths with suffix and trailing slashes with suffix removal*/
array("bar.zip\\", ".zip"),
array("\\bar.zip\\", ".zip"),
array("\\foo\\bar.zip\\", ".zip"),
array("foo\\bar.zip\\", ".zip"),
array("\\bar.zip\\", ".zip"),
/* paths with basename only suffix, with suffix removal*/
array("\\.zip", ".zip"),
array(".zip", ".zip"),
array("\\foo\\.zip", ".zip"),
/* paths with basename only suffix & trailing slashes, with suffix removal*/
array(".zip\\", ".zip"),
array("\\foo\\.zip\\", ".zip"),
array("foo\\.zip\\", ".zip"),
);
$file_path_variations = array (
/* paths with shortcut home dir char, with suffix variation */
array("C:\\temp\\bar"),
array("C:\\temp\\bar", ""),
array("C:\\temp\\bar", NULL),
array("C:\\temp\\bar", ' '),
array("C:\\temp\\bar.tar", ".tar"),
array("C:\\temp\\bar.tar", "~"),
array("C:\\temp\\bar.tar\\", "~"),
array("C:\\temp\\bar.tar\\", ""),
array("C:\\temp\\bar.tar", NULL),
array("C:\\temp\\bar.tar", ''),
array("C:\\temp\\bar.tar", " "),
/* paths with numeric strings */
array("10.5"),
array("10.5", ".5"),
array("10.5", "10.5"),
array("10"),
array("105", "5"),
array("/10.5"),
array("10.5\\"),
array("10/10.zip"),
array("0"),
array('0'),
/* paths and suffix given as same */
array("bar.zip", "bar.zip"),
array("\\bar.zip", "\\bar.zip"),
array("\\bar.zip\\", "\\bar.zip\\"),
array(" ", " "),
array(' ', ' '),
array(NULL, NULL),
/* path with spaces */
array(" "),
array(' '),
/* empty paths */
array(""),
array(''),
array(NULL)
);
function check_basename( $path_arrays ) {
$loop_counter = 1;
foreach ($path_arrays as $path) {
echo "\n--Iteration $loop_counter--\n"; $loop_counter++;
if( 1 == count($path) ) { // no suffix provided
var_dump( basename($path[0]) );
} else { // path as well as suffix provided,
var_dump( basename($path[0], $path[1]) );
}
}
}
echo "*** Testing basic operations ***\n";
check_basename( $file_paths );
echo "\n*** Testing possible variations in path and suffix ***\n";
check_basename( $file_path_variations );
echo "\n*** Testing error conditions ***\n";
// zero arguments
var_dump( basename() );
// more than expected no. of arguments
var_dump( basename("\\blah\\tmp\\bar.zip", ".zip", ".zip") );
// passing invalid type arguments
$object = new stdclass;
var_dump( basename( array("string\\bar") ) );
var_dump( basename( array("string\\bar"), "bar" ) );
var_dump( basename( "bar", array("string\\bar") ) );
var_dump( basename( $object, "bar" ) );
var_dump( basename( $object ) );
var_dump( basename( $object, $object ) );
var_dump( basename( "bar", $object ) );
echo "Done\n";
?>
--EXPECTF--
*** Testing basic operations ***
--Iteration 1--
unicode(3) "bar"
--Iteration 2--
unicode(3) "bar"
--Iteration 3--
unicode(3) "bar"
--Iteration 4--
unicode(3) "bar"
--Iteration 5--
unicode(3) "bar"
--Iteration 6--
unicode(3) "bar"
--Iteration 7--
unicode(3) "bar"
--Iteration 8--
unicode(3) "bar"
--Iteration 9--
unicode(3) "bar"
--Iteration 10--
unicode(3) "bar"
--Iteration 11--
unicode(7) "bar.zip"
--Iteration 12--
unicode(3) "bar"
--Iteration 13--
unicode(3) "bar"
--Iteration 14--
unicode(3) "bar"
--Iteration 15--
unicode(3) "bar"
--Iteration 16--
unicode(3) "bar"
--Iteration 17--
unicode(3) "bar"
--Iteration 18--
unicode(3) "bar"
--Iteration 19--
unicode(3) "bar"
--Iteration 20--
unicode(4) ".zip"
--Iteration 21--
unicode(4) ".zip"
--Iteration 22--
unicode(4) ".zip"
--Iteration 23--
unicode(4) ".zip"
--Iteration 24--
unicode(4) ".zip"
--Iteration 25--
unicode(4) ".zip"
*** Testing possible variations in path and suffix ***
--Iteration 1--
unicode(3) "bar"
--Iteration 2--
unicode(3) "bar"
--Iteration 3--
unicode(3) "bar"
--Iteration 4--
unicode(3) "bar"
--Iteration 5--
unicode(3) "bar"
--Iteration 6--
unicode(7) "bar.tar"
--Iteration 7--
unicode(7) "bar.tar"
--Iteration 8--
unicode(7) "bar.tar"
--Iteration 9--
unicode(7) "bar.tar"
--Iteration 10--
unicode(7) "bar.tar"
--Iteration 11--
unicode(7) "bar.tar"
--Iteration 12--
unicode(4) "10.5"
--Iteration 13--
unicode(2) "10"
--Iteration 14--
unicode(4) "10.5"
--Iteration 15--
unicode(2) "10"
--Iteration 16--
unicode(2) "10"
--Iteration 17--
unicode(4) "10.5"
--Iteration 18--
unicode(4) "10.5"
--Iteration 19--
unicode(6) "10.zip"
--Iteration 20--
unicode(1) "0"
--Iteration 21--
unicode(1) "0"
--Iteration 22--
unicode(7) "bar.zip"
--Iteration 23--
unicode(7) "bar.zip"
--Iteration 24--
unicode(7) "bar.zip"
--Iteration 25--
unicode(1) " "
--Iteration 26--
unicode(1) " "
--Iteration 27--
unicode(0) ""
--Iteration 28--
unicode(1) " "
--Iteration 29--
unicode(1) " "
--Iteration 30--
unicode(0) ""
--Iteration 31--
unicode(0) ""
--Iteration 32--
unicode(0) ""
*** Testing error conditions ***
Warning: basename() expects at least 1 parameter, 0 given in %s on line %d
NULL
Warning: basename() expects at most 2 parameters, 3 given in %s on line %d
NULL
Warning: basename() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
Warning: basename() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
Warning: basename() expects parameter 2 to be string (Unicode or binary), array given in %s on line %d
NULL
Warning: basename() expects parameter 1 to be string (Unicode or binary), object given in %s on line %d
NULL
Warning: basename() expects parameter 1 to be string (Unicode or binary), object given in %s on line %d
NULL
Warning: basename() expects parameter 1 to be string (Unicode or binary), object given in %s on line %d
NULL
Warning: basename() expects parameter 2 to be string (Unicode or binary), object given in %s on line %d
NULL
Done

Binary file not shown.

View File

@ -0,0 +1,38 @@
--TEST--
Test basename() function : error conditions
--FILE--
<?php
/* Prototype : string basename(string path [, string suffix])
* Description: Returns the filename component of the path
* Source code: ext/standard/string.c
* Alias to functions:
*/
echo "*** Testing basename() : error conditions ***\n";
// Zero arguments
echo "\n-- Testing basename() function with Zero arguments --\n";
var_dump( basename() );
//Test basename with one more than the expected number of arguments
echo "\n-- Testing basename() function with more than expected no. of arguments --\n";
$path = 'string_val';
$suffix = 'string_val';
$extra_arg = 10;
var_dump( basename($path, $suffix, $extra_arg) );
?>
===DONE===
--EXPECTF--
*** Testing basename() : error conditions ***
-- Testing basename() function with Zero arguments --
Warning: basename() expects at least 1 parameter, 0 given in %s on line %d
NULL
-- Testing basename() function with more than expected no. of arguments --
Warning: basename() expects at most 2 parameters, 3 given in %s on line %d
NULL
===DONE===

View File

@ -1,12 +1,15 @@
--TEST--
Bug #41655 (open_basedir bypass via glob()) 1/2
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--INI--
open_basedir=/tmp
--FILE--
<?php
$a=glob("./*.jpeg");
$a=glob("./*.jpeg");
var_dump($a);
echo "Done\n";
?>
--EXPECT--
Done
bool(false)
Done

View File

@ -0,0 +1,209 @@
--TEST--
Test chmod() function : first parameter variation
--FILE--
<?php
/* Prototype : bool chmod(string filename, int mode)
* Description: Change file mode
* Source code: ext/standard/filestat.c
* Alias to functions:
*/
echo "*** Testing chmod() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$mode = 0777;
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
);
// loop through each element of the array for filename
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
var_dump( chmod($value, $mode) );
};
?>
===DONE===
--EXPECTF--
*** Testing chmod() : usage variation ***
--int 0--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--int 1--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--int 12345--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--int -12345--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--float 10.5--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--float -10.5--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--float 12.3456789000e10--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--float -12.3456789000e10--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--float .5--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--empty array--
Error: 2 - chmod() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
NULL
--int indexed array--
Error: 2 - chmod() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
NULL
--associative array--
Error: 2 - chmod() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
NULL
--nested arrays--
Error: 2 - chmod() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
NULL
--uppercase NULL--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--lowercase null--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--lowercase true--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--lowercase false--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--uppercase TRUE--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--uppercase FALSE--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--empty string DQ--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--empty string SQ--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--instance of classWithToString--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--instance of classWithoutToString--
Error: 2 - chmod() expects parameter 1 to be string (Unicode or binary), object given, %s(%d)
NULL
--undefined var--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
--unset var--
Error: 2 - chmod(): No such file or directory, %s(%d)
bool(false)
===DONE===

View File

@ -0,0 +1,202 @@
--TEST--
Test chmod() function : second parameter variation
--XFAIL--
--FILE--
<?php
/* Prototype : bool chmod(string filename, int mode)
* Description: Change file mode
* Source code: ext/standard/filestat.c
* Alias to functions:
*/
echo "*** Testing chmod() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted
$filename = __FILE__ . ".tmp";
$fd = fopen($filename, "w+");
fclose($fd);
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// string data
'string DQ' => "string",
'string SQ' => 'string',
'mixed case string' => "sTrInG",
'heredoc' => $heredoc,
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
);
// loop through each element of the array for mode
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
var_dump( chmod($filename, $value) );
};
chmod($filename, 0777);
unlink($filename);
?>
===DONE===
--EXPECTF--
*** Testing chmod() : usage variation ***
--float 10.5--
bool(true)
--float -10.5--
bool(true)
--float 12.3456789000e10--
bool(true)
--float -12.3456789000e10--
bool(true)
--float .5--
bool(true)
--empty array--
Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d)
NULL
--associative array--
Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - chmod() expects parameter 2 to be long, array given, %s(%d)
NULL
--uppercase NULL--
bool(true)
--lowercase null--
bool(true)
--lowercase true--
bool(true)
--lowercase false--
bool(true)
--uppercase TRUE--
bool(true)
--uppercase FALSE--
bool(true)
--empty string DQ--
Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d)
NULL
--empty string SQ--
Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d)
NULL
--string DQ--
Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d)
NULL
--string SQ--
Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d)
NULL
--mixed case string--
Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d)
NULL
--heredoc--
Error: 2 - chmod() expects parameter 2 to be long, Unicode string given, %s(%d)
NULL
--instance of classWithToString--
Error: 2 - chmod() expects parameter 2 to be long, object given, %s(%d)
NULL
--instance of classWithoutToString--
Error: 2 - chmod() expects parameter 2 to be long, object given, %s(%d)
NULL
--undefined var--
bool(true)
--unset var--
bool(true)
===DONE===

View File

@ -1,5 +1,5 @@
--TEST--
Test copy() function: usage variations - src as dir and dest as an existing file (Bug #42243)
Test copy() function: usage variations - src as dir and dest as an existing file(Bug #42243)
--FILE--
<?php
/* Prototype: bool copy ( string $source, string $dest );

View File

@ -1,5 +1,7 @@
--TEST--
Test copy() function: usage variations - stat after copy
--XFAIL--
Pending completion of Unicode streams
--FILE--
<?php
/* Prototype: bool copy ( string $source, string $dest );
@ -16,7 +18,7 @@ require($file_path."/file.inc");
echo "*** Test copy() function: stat of file before and after copy ***\n";
$src_file_name = $file_path."/copy_variation18.tmp";
$file_handle = fopen($src_file_name, "w");
fwrite($file_handle, str_repeat(b"Hello2world...\n", 100));
fwrite($file_handle, str_repeat("Hello2world...\n", 100));
fclose($file_handle);
$dest_file_name = $file_path."/copy_copy_variation18.tmp";
@ -32,8 +34,13 @@ var_dump( copy($src_file_name, $dest_file_name) );
$stat_after_copy = stat($src_file_name);
clearstatcache();
// compare all stat fields except access time
$stat_keys_to_compare = array("dev", "ino", "mode", "nlink", "uid", "gid",
"rdev", "size", "mtime", "ctime",
"blksize", "blocks");
echo "Comparing the stats of file before and after copy operation => ";
var_dump( compare_stats($stat_before_copy, $stat_after_copy, $all_stat_keys) );
var_dump( compare_stats($stat_before_copy, $stat_after_copy, $stat_keys_to_compare) );
echo "*** Done ***\n";
?>
@ -43,8 +50,10 @@ echo "*** Done ***\n";
unlink(dirname(__FILE__)."/copy_copy_variation18.tmp");
unlink(dirname(__FILE__)."/copy_variation18.tmp");
?>
--EXPECT--
--EXPECTF--
*** Test copy() function: stat of file before and after copy ***
Copy operation => bool(true)
Comparing the stats of file before and after copy operation => bool(true)
*** Done ***

View File

@ -0,0 +1,93 @@
--TEST--
Test dirname() function : basic functionality
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
die("skip Only valid for Windows");
?>
--FILE--
<?php
/* Prototype : string dirname(string path)
* Description: Returns the directory name component of the path
* Source code: ext/standard/string.c
* Alias to functions:
*/
echo "*** Testing dirname() : basic functionality ***\n";
// Initialise all required variables
$paths = array(
'',
' ',
'c:',
'c:\\',
'c:/',
'afile',
'c:\test\afile',
'c:\\test\\afile',
'c://test//afile',
'c:\test\afile\\',
'/usr/lib/locale/en_US',
'//usr/lib//locale/en_US',
'\\',
'\\\\',
'/',
'//',
'///',
'/usr/lib/locale/en_US/',
'c:\windows/system32\drivers/etc\hosts',
'/usr\lib/locale\en_US',
' c:\test\adir\afile.txt',
'c:\test\adir\afile.txt ',
' c:\test\adir\afile.txt ',
' /usr/lib/locale/en_US',
'/usr/lib/locale/en_US ',
' /usr/lib/locale/en_US ',
' c:',
' c:\test\adir\afile.txt',
'/usr',
'/usr/',
);
foreach ($paths as $path) {
var_dump( dirname($path) );
}
?>
===DONE===
--EXPECTF--
*** Testing dirname() : basic functionality ***
unicode(0) ""
unicode(1) "."
unicode(2) "c:"
unicode(3) "c:\"
unicode(3) "c:\"
unicode(1) "."
unicode(7) "c:\test"
unicode(7) "c:\test"
unicode(8) "c://test"
unicode(7) "c:\test"
unicode(15) "/usr/lib/locale"
unicode(17) "//usr/lib//locale"
unicode(1) "\"
unicode(1) "\"
unicode(1) "\"
unicode(1) "\"
unicode(1) "\"
unicode(15) "/usr/lib/locale"
unicode(31) "c:\windows/system32\drivers/etc"
unicode(15) "/usr\lib/locale"
unicode(15) " c:\test\adir"
unicode(12) "c:\test\adir"
unicode(15) " c:\test\adir"
unicode(18) " /usr/lib/locale"
unicode(15) "/usr/lib/locale"
unicode(18) " /usr/lib/locale"
unicode(1) "."
unicode(14) " c:\test\adir"
unicode(1) "\"
unicode(1) "\"
===DONE===

View File

@ -0,0 +1,94 @@
--TEST--
Test dirname() function : basic functionality
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Not valid for Windows");
?>
--FILE--
<?php
/* Prototype : string dirname(string path)
* Description: Returns the directory name component of the path
* Source code: ext/standard/string.c
* Alias to functions:
*/
echo "*** Testing dirname() : basic functionality ***\n";
// Initialise all required variables
$paths = array(
'',
' ',
'c:',
'c:\\',
'c:/',
'afile',
'c:\test\afile',
'c:\\test\\afile',
'c://test//afile',
'c:\test\afile\\',
'/usr/lib/locale/en_US',
'//usr/lib//locale/en_US',
'\\',
'\\\\',
'/',
'//',
'///',
'/usr/lib/locale/en_US/',
'c:\windows/system32\drivers/etc\hosts',
'/usr\lib/locale\en_US',
' c:\test\adir\afile.txt',
'c:\test\adir\afile.txt ',
' c:\test\adir\afile.txt ',
' /usr/lib/locale/en_US',
'/usr/lib/locale/en_US ',
' /usr/lib/locale/en_US ',
' c:',
' c:\test\adir\afile.txt',
'/usr',
'/usr/'
);
foreach ($paths as $path) {
var_dump( dirname($path) );
}
?>
===DONE===
--EXPECTF--
*** Testing dirname() : basic functionality ***
unicode(0) ""
unicode(1) "."
unicode(1) "."
unicode(1) "."
unicode(1) "."
unicode(1) "."
unicode(1) "."
unicode(1) "."
unicode(8) "c://test"
unicode(1) "."
unicode(15) "/usr/lib/locale"
unicode(17) "//usr/lib//locale"
unicode(1) "."
unicode(1) "."
unicode(1) "/"
unicode(1) "/"
unicode(1) "/"
unicode(15) "/usr/lib/locale"
unicode(27) "c:\windows/system32\drivers"
unicode(8) "/usr\lib"
unicode(1) "."
unicode(1) "."
unicode(1) "."
unicode(18) " /usr/lib/locale"
unicode(15) "/usr/lib/locale"
unicode(18) " /usr/lib/locale"
unicode(1) "."
unicode(1) "."
unicode(1) "/"
unicode(1) "/"
===DONE===

View File

@ -0,0 +1,40 @@
--TEST--
Test dirname() function : error conditions
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : string dirname(string path)
* Description: Returns the directory name component of the path
* Source code: ext/standard/string.c
* Alias to functions:
*/
echo "*** Testing dirname() : error conditions ***\n";
// Zero arguments
echo "\n-- Testing dirname() function with Zero arguments --\n";
var_dump( dirname() );
//Test dirname with one more than the expected number of arguments
echo "\n-- Testing dirname() function with more than expected no. of arguments --\n";
$path = 'string_val';
$extra_arg = 10;
var_dump( dirname($path, $extra_arg) );
?>
===DONE===
--EXPECTF--
*** Testing dirname() : error conditions ***
-- Testing dirname() function with Zero arguments --
Warning: dirname() expects exactly 1 parameter, 0 given in %s on line %d
NULL
-- Testing dirname() function with more than expected no. of arguments --
Warning: dirname() expects exactly 1 parameter, 2 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,190 @@
--TEST--
Test dirname() function : usage variation
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : string dirname(string path)
* Description: Returns the directory name component of the path
* Source code: ext/standard/string.c
* Alias to functions:
*/
echo "*** Testing dirname() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
);
// loop through each element of the array for path
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
var_dump( dirname($value) );
};
?>
===DONE===
--EXPECTF--
*** Testing dirname() : usage variation ***
--int 0--
unicode(1) "."
--int 1--
unicode(1) "."
--int 12345--
unicode(1) "."
--int -12345--
unicode(1) "."
--float 10.5--
unicode(1) "."
--float -10.5--
unicode(1) "."
--float 12.3456789000e10--
unicode(1) "."
--float -12.3456789000e10--
unicode(1) "."
--float .5--
unicode(1) "."
--empty array--
Error: 2 - dirname() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
NULL
--int indexed array--
Error: 2 - dirname() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
NULL
--associative array--
Error: 2 - dirname() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
NULL
--nested arrays--
Error: 2 - dirname() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
NULL
--uppercase NULL--
unicode(0) ""
--lowercase null--
unicode(0) ""
--lowercase true--
unicode(1) "."
--lowercase false--
unicode(0) ""
--uppercase TRUE--
unicode(1) "."
--uppercase FALSE--
unicode(0) ""
--empty string DQ--
unicode(0) ""
--empty string SQ--
unicode(0) ""
--instance of classWithToString--
unicode(1) "."
--instance of classWithoutToString--
Error: 2 - dirname() expects parameter 1 to be string (Unicode or binary), object given, %s(%d)
NULL
--undefined var--
unicode(0) ""
--unset var--
unicode(0) ""
===DONE===

View File

@ -25,7 +25,7 @@ var_dump(disk_total_space("/some/path/here"));
echo "Done\n";
?>
--EXPECTF--
--EXPECTF--
Warning: disk_free_space() expects exactly 1 parameter, 0 given in %s on line %d
NULL
@ -37,8 +37,8 @@ bool(false)
Warning: disk_total_space(): No such file or directory in %s on line %d
bool(false)
float(%d)
float(%d)
float(%f)
float(%f)
Warning: disk_free_space(): No such file or directory in %s on line %d
bool(false)

View File

@ -7,27 +7,26 @@ memory_limit=32M
/*
* Prototype: float disk_free_space( string directory )
* Description: Given a string containing a directory, this function
* will return the number of bytes available on the corresponding
* filesystem or disk partition
* will return the number of bytes available on the corresponding
* filesystem or disk partition
*/
$file_path = dirname(__FILE__);
include($file_path."/file.inc");
echo "*** Testing with existing directory ***\n";
var_dump( disk_free_space($file_path) );
var_dump( diskfreespace($file_path) );
$dir = "/disk_free_space";
echo "*** Testing with newly created directory ***\n";
$dir = "/disk_free_space";
mkdir($file_path.$dir);
echo" \n Free Space before writing to a file\n";
$space1 = disk_free_space($file_path.$dir);
var_dump( $space1 );
var_dump($space1);
$fh = fopen($file_path.$dir."/disk_free_space.tmp", "a");
for( $i=1; $i<=1000; $i++)
fwrite($fh, (binary)"x");
fclose($fh);
fill_buffer($buffer, "text", 3000000);
file_put_contents($file_path.$dir."/disk_free_space.tmp", $buffer);
echo "\n Free Space after writing to a file\n";
$space2 = disk_free_space($file_path.$dir);
@ -38,33 +37,29 @@ if( $space1 > $space2 )
else
echo "\n Free Space Value Is Incorrect\n";
echo "*** Testing with Binary Input ***\n";
var_dump( disk_free_space(b"$file_path") );
echo"\n--- Done ---";
echo"\n-- Done --";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/disk_free_space/disk_free_space.tmp");
rmdir($file_path."/disk_free_space");
$dir = "/disk_free_space";
unlink($file_path.$dir."/disk_free_space.tmp");
rmdir($file_path.$dir);
?>
--EXPECTF--
*** Testing with existing directory ***
float(%d)
float(%d)
float(%f)
float(%f)
*** Testing with newly created directory ***
Free Space before writing to a file
float(%d)
float(%f)
Free Space after writing to a file
float(%d)
float(%f)
Free Space Value Is Correct
*** Testing with Binary Input ***
float(%d)
--- Done ---
-- Done --

View File

@ -1,15 +1,15 @@
--TEST--
Test disk_free_space and its alias diskfreespace() functions : error conditions.
Test disk_free_space and its alias diskfreespace() functions : error conditions
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == 'WIN')
die("skip Not valid on Windows");
if(substr(PHP_OS, 0, 3) == 'WIN' )
die("skip Not Valid for Windows");
?>
--FILE--
<?php
/*
* Prototype: float disk_free_space( string directory )
* Description: Given a string containing a directory, this function will
* Description: Given a string containing a directory, this function will
* return the number of bytes available on the corresponding
* filesystem or disk partition
*/
@ -27,7 +27,7 @@ var_dump( disk_free_space( $file_path."/dir1" )); // Invalid directory
var_dump( diskfreespace( $file_path."/dir1" ));
$fh = fopen( $file_path."/disk_free_space.tmp", "w" );
fwrite( $fh, (binary)" Garbage data for the temporary file" );
fwrite( $fh, " Garbage data for the temporary file" );
var_dump( disk_free_space( $file_path."/disk_free_space.tmp" )); // file input instead of directory
var_dump( diskfreespace( $file_path."/disk_free_space.tmp" ));
fclose($fh);
@ -55,12 +55,12 @@ NULL
Warning: diskfreespace() expects exactly 1 parameter, 2 given in %s on line %d
NULL
Warning: disk_free_space(): No such file or directory in %s on line %d
Warning: disk_free_space(): %s in %s on line %d
bool(false)
Warning: diskfreespace(): No such file or directory in %s on line %d
Warning: diskfreespace(): %s in %s on line %d
bool(false)
float(%d)
float(%d)
float(%f)
float(%f)
-- Done --

View File

@ -1,5 +1,5 @@
--TEST--
Test disk_free_space and its alias diskfreespace() functions : Usage Variations
Test disk_free_space and its alias diskfreespace() functions : usage variations
--FILE--
<?php
/*
@ -11,15 +11,16 @@ Test disk_free_space and its alias diskfreespace() functions : Usage Variations
$file_path = dirname(__FILE__);
echo "*** Testing with a directory ***\n";
echo "*** Testing disk_free_space() function with a directory ***\n";
var_dump( disk_free_space($file_path."/..") );
var_dump( diskfreespace($file_path."/..") );
echo "\nTesting for the return type ***\n";
echo "\n*** Testing for the return type ***\n";
$return_value = disk_free_space($file_path);
var_dump( is_float($return_value) );
echo "\n*** Testing with different directory combinations ***";
echo "\n*** Testing disk_free_space() function with different styles of file and directory ***";
$dir = "/disk_free_space";
mkdir($file_path.$dir);
@ -41,15 +42,15 @@ $dirs_arr = array(
$file_path.$dir.chr(0),
$file_path."/.".$dir.chr(0),
".".chr(0).$file_path.$dir,
".".chr(0).$file_path.$dir.chr(0)
".".chr(0).$file_path.$dir.chr(0)
);
$count = 1;
/* loop through to test each element the above array */
foreach($dirs_arr as $dir1) {
foreach($dirs_arr as $dir) {
echo "\n-- Iteration $count --\n";
var_dump( disk_free_space( $dir1 ) );
var_dump( diskfreespace( $dir1 ) );
var_dump( disk_free_space( $dir ) );
var_dump( diskfreespace( $dir ) );
$count++;
}
@ -58,66 +59,65 @@ echo"\n--- Done ---";
--CLEAN--
<?php
$file_path = dirname(__FILE__);
rmdir($file_path."/disk_free_space");
$file_path = dirname(__FILE__)."/disk_free_space";
rmdir($file_path);
?>
--EXPECTF--
*** Testing with a directory ***
float(%d)
float(%d)
*** Testing disk_free_space() function with a directory ***
float(%f)
float(%f)
Testing for the return type ***
*** Testing for the return type ***
bool(true)
*** Testing with different directory combinations ***
*** Testing disk_free_space() function with different styles of file and directory ***
-- Iteration 1 --
float(%d)
float(%d)
float(%f)
float(%f)
-- Iteration 2 --
float(%d)
float(%d)
float(%f)
float(%f)
-- Iteration 3 --
float(%d)
float(%d)
float(%f)
float(%f)
-- Iteration 4 --
float(%d)
float(%d)
float(%f)
float(%f)
-- Iteration 5 --
float(%d)
float(%d)
float(%f)
float(%f)
-- Iteration 6 --
float(%d)
float(%d)
float(%f)
float(%f)
-- Iteration 7 --
float(%d)
float(%d)
float(%f)
float(%f)
-- Iteration 8 --
float(%d)
float(%d)
float(%f)
float(%f)
-- Iteration 9 --
float(%d)
float(%d)
float(%f)
float(%f)
-- Iteration 10 --
float(%d)
float(%d)
float(%f)
float(%f)
-- Iteration 11 --
float(%d)
float(%d)
float(%f)
float(%f)
-- Iteration 12 --
float(%d)
float(%d)
float(%f)
float(%f)
--- Done ---

View File

@ -1,34 +1,36 @@
--TEST--
Test disk_total_space() function : basic functionality
--XFAIL--
Pending completion of Unicode streams
--FILE--
<?php
/*
* Prototype: float disk_total_space( string $directory );
* Description: given a string containing a directory, this function will
* return the total number of bytes on the corresponding filesyatem
* or disk partition.
* Description: given a string containing a directory, this
* function will return the total number of bytes
* on the corresponding filesyatem or disk partition.
*/
$file_path = dirname(__FILE__);
echo "*** Testing with normal directory ***\n";
echo "*** Testing with existing directory ***\n";
var_dump( disk_total_space($file_path) );
echo "*** Testing with newly created directory ***\n";
$dir = "/disk_total_space";
mkdir($file_path."/disk_total_space");
var_dump( disk_total_space($file_path."/disk_total_space") );
mkdir($file_path.$dir);
var_dump( disk_total_space($file_path.$dir) );
$fh = fopen($file_path.$dir."/disk_total_space.tmp", "w");
fwrite($fh, (binary)"Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data");
$fh = fopen($file_path."/disk_total_space/disk_total_space.tmp", "w");
fwrite($fh, "Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data Garbage Data");
fclose($fh);
echo"\nTotal Space after writing to a file\n";
var_dump( disk_total_space($file_path.$dir) );
echo" \n Total Space after writing to a file\n";
var_dump( disk_total_space($file_path."/disk_total_space") );
echo"\n-- Done --";
echo"\n--- Done ---";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
@ -37,12 +39,12 @@ rmdir($file_path."/disk_total_space");
?>
--EXPECTF--
*** Testing with normal directory ***
float(%d)
*** Testing with existing directory ***
float(%f)
*** Testing with newly created directory ***
float(%d)
float(%f)
Total Space after writing to a file
float(%f)
Total Space after writing to a file
float(%d)
-- Done --
--- Done ---

View File

@ -1,15 +1,17 @@
--TEST--
Test disk_total_space() function : error conditions
--XFAIL--
Pending completion of Unicode streams
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == 'WIN')
die("skip Not valid on Windows");
if(substr(PHP_OS, 0, 3) == 'WIN' )
die("skip Not Valid for Windows");
?>
--FILE--
<?php
/*
* Prototype: float disk_total_space( string $directory );
* Description: given a string containing a directory, this function
* Description: given a string containing a directory, this function
* will return the total number of bytes on the corresponding
* filesystem or disk partition
*/
@ -24,7 +26,7 @@ var_dump( disk_total_space( $file_path, "extra argument") ); // More than valid
var_dump( disk_total_space( $file_path."/dir1" )); // Invalid directory
$fh = fopen( $file_path."/disk_total_space.tmp", "w" );
fwrite( $fh, (binary)" Garbage data for the temporary file" );
fwrite( $fh, " Garbage data for the temporary file" );
var_dump( disk_total_space( $file_path."/disk_total_space.tmp" )); // file input instead of directory
fclose($fh);
@ -46,6 +48,6 @@ NULL
Warning: disk_total_space(): No such file or directory in %s on line %d
bool(false)
float(%d)
float(%f)
--- Done ---

View File

@ -1,5 +1,5 @@
--TEST--
Testing disk_total_space() functions : Usage Variations.
Test disk_total_space() functions : usage variations
--FILE--
<?php
/*
@ -18,9 +18,9 @@ echo "\nTesting for the return type ***\n";
$return_value = disk_total_space($file_path);
var_dump( is_float($return_value) );
echo "\n*** Testing with different directory combinations ***";
$dir = "/disk_total_space";
echo "\n*** Testing disk_total_space() function with different directory combinations ***";
$dir = "/disk_total_space";
mkdir($file_path.$dir);
$dirs_arr = array(
@ -29,7 +29,7 @@ $dirs_arr = array(
$file_path."/.".$dir,
/* Testing a file trailing slash */
$file_path."".$dir."/",
$file_path.$dir."/",
$file_path."/.".$dir."/",
/* Testing file with double trailing slashes */
@ -44,7 +44,6 @@ $dirs_arr = array(
".".chr(0).$file_path.$dir.chr(0)
);
$count = 1;
/* loop through to test each element the above array */
foreach($dirs_arr as $dir1) {
@ -53,63 +52,57 @@ foreach($dirs_arr as $dir1) {
$count++;
}
echo "*** Testing with Binary Input ***\n";
var_dump( disk_total_space(b"$file_path") );
echo"\n--- Done ---";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
rmdir($file_path."/disk_total_space");
$dir = "/disk_total_space";
rmdir($file_path.$dir);
?>
--EXPECTF--
*** Testing with a directory ***
float(%d)
float(%f)
Testing for the return type ***
bool(true)
*** Testing with different directory combinations ***
*** Testing disk_total_space() function with different directory combinations ***
-- Iteration 1 --
float(%d)
float(%f)
-- Iteration 2 --
float(%d)
float(%f)
-- Iteration 3 --
float(%d)
float(%f)
-- Iteration 4 --
float(%d)
float(%f)
-- Iteration 5 --
float(%d)
float(%f)
-- Iteration 6 --
float(%d)
float(%f)
-- Iteration 7 --
float(%d)
float(%f)
-- Iteration 8 --
float(%d)
float(%f)
-- Iteration 9 --
float(%d)
float(%f)
-- Iteration 10 --
float(%d)
float(%f)
-- Iteration 11 --
float(%d)
float(%f)
-- Iteration 12 --
float(%d)
*** Testing with Binary Input ***
float(%d)
float(%f)
--- Done ---

View File

@ -0,0 +1,103 @@
--TEST--
Test feof() function : basic functionality
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : proto bool feof(resource fp)
* Description: Test for end-of-file on a file pointer
* Source code: ext/standard/file.c
* Alias to functions: gzeof
*/
echo "*** Testing feof() : basic functionality ***\n";
$tmpFile1 = __FILE__.".tmp1";
$h = fopen($tmpFile1, 'wb');
$count = 10;
for ($i = 1; $i <= $count; $i++) {
fwrite($h, "some data $i\n");
}
fclose($h);
echo "\n*** testing reading complete file using feof to stop ***\n";
$h = fopen($tmpFile1, 'rb');
//feof is not set to true until you try to read past the end of file.
//so fgets will be called even if we are at the end of the file on
//last time to set the eof flag but it will fail to read.
$lastline = "";
while (!feof($h)) {
$previousLine = $lastline;
$lastline = fgets($h);
}
echo $previousLine;
var_dump($lastline); // this should be false
fclose($h);
$tmpFile2 = __FILE__.".tmp2";
$h = fopen($tmpFile2, 'wb+');
$count = 10;
echo "*** writing $count lines, testing feof ***\n";
for ($i = 1; $i <=$count; $i++) {
fwrite($h, "some data $i\n");
var_dump(feof($h));
}
echo "*** testing feof on unclosed file after a read ***\n";
fread($h, 100);
var_dump(feof($h));
$eofPointer = ftell($h);
echo "*** testing feof after a seek to near the beginning ***\n";
fseek($h, 20, SEEK_SET);
var_dump(feof($h));
echo "*** testing feof after a seek to end ***\n";
fseek($h, $eofPointer, SEEK_SET);
var_dump(feof($h));
echo "*** testing feof after a seek passed the end ***\n";
fseek($h, $eofPointer + 1000, SEEK_SET);
var_dump(feof($h));
echo "*** closing file, testing eof ***\n";
fclose($h);
feof($h);
unlink($tmpFile1);
unlink($tmpFile2);
echo "Done";
?>
--EXPECTF--
*** Testing feof() : basic functionality ***
*** testing reading complete file using feof to stop ***
some data 10
bool(false)
*** writing 10 lines, testing feof ***
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
*** testing feof on unclosed file after a read ***
bool(true)
*** testing feof after a seek to near the beginning ***
bool(false)
*** testing feof after a seek to end ***
bool(false)
*** testing feof after a seek passed the end ***
bool(false)
*** closing file, testing eof ***
Warning: feof(): %d is not a valid stream resource in %s on line %d
Done

View File

@ -24,9 +24,10 @@ if($file_handle == false)
var_dump( fflush($file_handle, $file_handle) );
fclose($file_handle);
fflush($file_handle);
// test invalid arguments : non-resources
echo "-- Testing fflush(): with invalid arguments --\n";
echo "\n-- Testing fflush(): with invalid arguments --\n";
$invalid_args = array (
"string",
10,
@ -41,7 +42,7 @@ for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
echo "-- Iteration $loop_counter --\n";
var_dump( fflush($invalid_args[$loop_counter - 1]) );
}
echo "\n*** Done ***";
echo "Done\n";
?>
--CLEAN--
@ -60,6 +61,9 @@ NULL
Warning: fflush() expects exactly 1 parameter, 2 given in %s on line %d
NULL
Warning: fflush(): 5 is not a valid stream resource in %s on line %d
-- Testing fflush(): with invalid arguments --
-- Iteration 1 --
@ -85,5 +89,5 @@ NULL
Warning: fflush() expects parameter 1 to be resource, object given in %s on line %d
NULL
Done
*** Done ***

View File

@ -1,5 +1,7 @@
--TEST--
Test fgetc() function : basic functionality
--XFAIL--
Pending completion of Unicode streams
--FILE--
<?php
/*
@ -541,3 +543,4 @@ int(6)
bool(false)
resource(%d) of type (stream)
Done

View File

@ -1,5 +1,7 @@
--TEST--
Test fgetc() function : usage variations - closed handle
--XFAIL--
Return values are inconsistent (and have changed from previous versions)
--FILE--
<?php
/*
@ -47,6 +49,6 @@ bool(false)
Notice: Undefined variable: file_handle in %s on line %d
Warning: fgetc(): supplied argument is not a valid stream resource in %s on line %d
Warning: fgetc() expects parameter 1 to be resource, null given in %s on line %d
bool(false)
Done

View File

@ -1,5 +1,7 @@
--TEST--
Test fgets() function : error conditions
--XFAIL--
Return values are inconsistent (and have changed from previous versions)
--FILE--
<?php
/*
@ -60,11 +62,11 @@ echo "Done\n";
-- Testing fgets() with zero argument --
Warning: fgets() expects at least 1 parameter, 0 given in %s on line %d
NULL
bool(false)
-- Testing fgets() with more than expected number of arguments --
Warning: fgets() expects at most 2 parameters, 3 given in %s on line %d
NULL
bool(false)
-- Testing fgets() with invalid length arguments --
Warning: fgets(): Length parameter must be greater than 0 in %s on line %d
@ -77,31 +79,32 @@ bool(false)
-- Iteration 1 --
Warning: fgets() expects parameter 1 to be resource, Unicode string given in %s on line %d
NULL
bool(false)
-- Iteration 2 --
Warning: fgets() expects parameter 1 to be resource, integer given in %s on line %d
NULL
bool(false)
-- Iteration 3 --
Warning: fgets() expects parameter 1 to be resource, double given in %s on line %d
NULL
bool(false)
-- Iteration 4 --
Warning: fgets() expects parameter 1 to be resource, boolean given in %s on line %d
NULL
bool(false)
-- Iteration 5 --
Warning: fgets() expects parameter 1 to be resource, array given in %s on line %d
NULL
bool(false)
-- Iteration 6 --
Warning: fgets() expects parameter 1 to be resource, object given in %s on line %d
NULL
bool(false)
-- Testing fgets() with closed/unset file handle --
Warning: fgets(): 5 is not a valid stream resource in %s on line %d
Warning: fgets(): %d is not a valid stream resource in %s on line %d
bool(false)
Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d
NULL
bool(false)
Done

View File

@ -0,0 +1,58 @@
--TEST--
fgets() with a socket stream
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Setup socket server */
$server = stream_socket_server('tcp://127.0.0.1:31337');
/* Connect to it */
$client = fsockopen('tcp://127.0.0.1:31337');
if (!$client) {
die("Unable to create socket");
}
/* Accept that connection */
$socket = stream_socket_accept($server);
echo "Write some data:\n";
fwrite($socket, "line1\nline2\nline3\n");
echo "\n\nRead a line from the client:\n";
var_dump(fgets($client));
echo "\n\nRead another line from the client:\n";
var_dump(fgets($client));
echo "\n\nClose the server side socket and read the remaining data from the client\n";
fclose($socket);
fclose($server);
while(!feof($client)) {
fread($client, 1);
}
echo "done\n";
?>
--EXPECT--
Write some data:
Read a line from the client:
unicode(6) "line1
"
Read another line from the client:
unicode(6) "line2
"
Close the server side socket and read the remaining data from the client
done

View File

@ -0,0 +1,65 @@
--TEST--
fgets() over a socket with more than a buffer's worth of data
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
// create a file
$filename = __FILE__ . ".tmp";
$fd = fopen($filename, "w+");
// populate the file with lines of data
define("LINE_OF_DATA", "12345678\n");
for ($i = 0; $i < 1000; $i++) {
fwrite($fd, LINE_OF_DATA);
}
fclose($fd);
/* Setup socket server */
$server = stream_socket_server('tcp://127.0.0.1:31337');
/* Connect to it */
$client = fsockopen('tcp://127.0.0.1:31337');
if (!$client) {
die("Unable to create socket");
}
/* Accept that connection */
$socket = stream_socket_accept($server);
echo "Write data from the file:\n";
$data = file_get_contents($filename);
unlink($filename);
var_dump(fwrite($socket, $data));
fclose($socket);
echo "\nRead lines from the client\n";
while ($line = fgets($client,256)) {
if (strcmp($line, LINE_OF_DATA) != 0) {
echo "Error - $line does not match " . LINE_OF_DATA;
break;
}
}
echo "\nClose the server side socket and read the remaining data from the client\n";
fclose($server);
while(!feof($client)) {
fread($client, 1);
}
echo "done\n";
?>
--EXPECT--
Write data from the file:
int(9000)
Read lines from the client
Close the server side socket and read the remaining data from the client
done

View File

@ -1,5 +1,7 @@
--TEST--
Test fgets() function : usage variations - closed handle
--XFAIL--
Return values are inconsistent (and have changed from previous versions)
--FILE--
<?php
/*
@ -43,20 +45,21 @@ echo "Done";
*** Testing fgets() : usage variations ***
-- Testing fgets() with closed handle --
Warning: fgets(): 6 is not a valid stream resource in %s on line %s
Warning: fgets(): %d is not a valid stream resource in %s on line %d
bool(false)
Warning: fgets(): 6 is not a valid stream resource in %s on line %s
Warning: fgets(): %d is not a valid stream resource in %s on line %d
bool(false)
-- Testing fgets() with unset handle --
Notice: Undefined variable: file_handle in %s on line %s
Notice: Undefined variable: file_handle in %s on line %d
Warning: fgets() expects parameter 1 to be resource, null given in %s on line %s
NULL
Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d
bool(false)
Notice: Undefined variable: file_handle in %s on line %s
Notice: Undefined variable: file_handle in %s on line %d
Warning: fgets() expects parameter 1 to be resource, null given in %s on line %s
NULL
Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d
bool(false)
Done

View File

@ -279,7 +279,7 @@ function create_files( $file_path,
if ( $content_type == "empty" ) {
$return_value['filled'] = $count;
} else {
// fill the file with specifiec type of data and size
//fill the file with specifiec type of data and size
$tmp_name_suffix = $name_suffix;
for($loop_counter = 1; $loop_counter <= $count; $loop_counter ++) {
$filename = $file_path."/".$name_prefix.$tmp_name_suffix.$file_extension;
@ -577,7 +577,7 @@ Description:
$stat2 = second stat array
$op = type of the comparision to be perform between elements of stat1 and stat2
"!=" compare for not equal
"==" compare for equality
"==" comprae for equality
">" if each element of stat1 is > than stat2
"<" if each element of stat1 is < than stat2
$fields = contains the key of the elements that needs to be compared.
@ -585,10 +585,7 @@ Description:
$flag = specify true to dump the stat1 and stat2
*/
$all_stat_keys = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
"dev", "ino", "mode", "nlink", "uid", "gid",
"rdev", "size", "atime", "mtime", "ctime",
"blksize", "blocks");
$all_stat_keys = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, "dev", "ino", "mode", "nlink", "uid", "gid", "rdev", "size", "atime", "mtime", "ctime", "blksize", "blocks");
function compare_stats($stat1, $stat2, $fields, $op = "==", $flag = false ) {
// dump the stat if requested
@ -638,8 +635,6 @@ function compare_stats($stat1, $stat2, $fields, $op = "==", $flag = false ) {
// if the result is false(i.e values are not as expected),
// dump the stat array so that easy to figure out the error
if ( $result == false ) {
echo "\n Dumping diff between stat array 1 and 2...\n";
var_dump(array_diff($stat1, $stat2));
echo "\n Dumping stat array 1...\n";
var_dump($stat1);
echo "\n Dumping stat array 2...\n";

View File

@ -0,0 +1,44 @@
--TEST--
Test file_exists() function : error conditions
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : proto bool file_exists(string filename)
* Description: Returns true if filename exists
* Source code: ext/standard/filestat.c
* Alias to functions:
*/
/*
* add a comment here to say what the test is supposed to do
*/
echo "*** Testing file_exists() : error conditions ***\n";
// Zero arguments
echo "\n-- Testing file_exists() function with Zero arguments --\n";
var_dump( file_exists() );
//Test file_exists with one more than the expected number of arguments
echo "\n-- Testing file_exists() function with more than expected no. of arguments --\n";
$filename = 'string_val';
$extra_arg = 10;
var_dump( file_exists($filename, $extra_arg) );
echo "Done";
?>
--EXPECTF--
*** Testing file_exists() : error conditions ***
-- Testing file_exists() function with Zero arguments --
Warning: file_exists() expects exactly 1 parameter, 0 given in %s on line %d
NULL
-- Testing file_exists() function with more than expected no. of arguments --
Warning: file_exists() expects exactly 1 parameter, 2 given in %s on line %d
NULL
Done

View File

@ -0,0 +1,30 @@
--TEST--
Test file_exists() function : usage variations
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : proto bool file_exists(string filename)
* Description: Returns true if filename exists
* Source code: ext/standard/filestat.c
* Alias to functions:
*/
echo "*** Testing file_exists() : usage variations ***\n";
var_dump(file_exists(NULL));
var_dump(file_exists(false));
var_dump(file_exists(''));
var_dump(file_exists(' '));
var_dump(file_exists('|'));
echo "Done";
?>
--EXPECTF--
*** Testing file_exists() : usage variations ***
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
Done

View File

@ -0,0 +1,49 @@
--TEST--
file_get_contents() function : basic functionality
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype: string file_get_contents( string $filename[, bool $use_include_path[,
* resource $context[, int $offset[, int $maxlen]]]] )
* Description: Reads entire file into a string
*/
$file_path = dirname(__FILE__);
include($file_path."/file.inc");
echo "*** Testing the basic functionality of the file_get_contents() function ***\n";
echo "-- Testing with simple valid data file --\n";
create_files($file_path, 1, "text", 0755, 100, "w", "file", 1, "byte");
var_dump( file_get_contents($file_path."/file1.tmp") );
delete_files($file_path, 1);
echo "\n-- Testing with empty file --\n";
create_files($file_path, 1, "empty", 0755, 100, "w", "file", 1, "byte");
var_dump( file_get_contents($file_path."/file1.tmp") );
delete_files($file_path, 1);
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/file_put_contents.tmp");
unlink($file_path."/file_put_contents1.tmp");
?>
--EXPECTF--
*** Testing the basic functionality of the file_get_contents() function ***
-- Testing with simple valid data file --
unicode(100) "text text text text text text text text text text text text text text text text text text text text "
-- Testing with empty file --
unicode(0) ""
*** Done ***

View File

@ -0,0 +1,66 @@
--TEST--
Test file_get_contents() function : error conditions
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype: string file_get_contents( string $filename{, bool $use_include_path[,
* resource $context[, int $offset[, int $maxlen]]]] )
* Description: Reads entire file into a string
*/
echo "*** Testing error conditions ***\n";
$file_path = dirname(__FILE__);
include($file_path."/file.inc");
echo "\n-- Testing with Non-existing file --\n";
print( file_get_contents("/no/such/file/or/dir") );
echo "\n-- Testing No.of arguments less than expected --\n";
print( file_get_contents() );
echo "\n-- Testing No.of arguments greater than expected --\n";
create_files($file_path, 1, "text", 0755, 100, "w", "file", 1, "byte");
$file_handle = fopen($file_path."/file_put_contents_error.tmp", "w");
print( file_get_contents($file_path."/file1.tmp", false, $file_handle, 1, 2, "extra_argument") );
echo "\n-- Testing for invalid negative maxlen values --";
var_dump( file_get_contents($file_path."/file1.tmp", FALSE, $file_handle, 0, -5) );
delete_files($file_path, 1);
fclose($file_handle);
unlink($file_path."/file_put_contents_error.tmp");
echo "\n*** Done ***\n";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/file_put_contents_error.tmp");
unlink($file_path."/file_put_contents1.tmp");
?>
--EXPECTF--
*** Testing error conditions ***
-- Testing with Non-existing file --
Warning: file_get_contents(/no/such/file/or/dir): failed to open stream: No such file or directory in %s on line %d
-- Testing No.of arguments less than expected --
Warning: file_get_contents() expects at least 1 parameter, 0 given in %s on line %d
-- Testing No.of arguments greater than expected --
Warning: file_get_contents() expects at most 5 parameters, 6 given in %s on line %d
-- Testing for invalid negative maxlen values --
Warning: file_get_contents(): length must be greater than or equal to zero in %s on line %d
bool(false)
*** Done ***

View File

@ -0,0 +1,53 @@
--TEST--
Test file_get_contents() function : variation - include path testing
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
* Description: Read the entire file into a string
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_get_contents() : variation ***\n";
require_once('fopen_include_path.inc');
// this doesn't create the include dirs in this directory
// we change to this to ensure we are not part of the
// include paths.
$thisTestDir = "fileGetContentsVar1.dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$filename = "afile.txt";
$secondFile = $dir2."/".$filename;
$newpath = create_include_path();
set_include_path($newpath);
runtest();
teardown_include_path();
restore_include_path();
chdir("..");
rmdir($thisTestDir);
function runtest() {
global $secondFile, $filename;
$h = fopen($secondFile, "w");
fwrite($h, "File in include path");
fclose($h);
$line = file_get_contents($filename, true);
echo "$line\n";
unlink($secondFile);
}
?>
===DONE===
--EXPECT--
*** Testing file_get_contents() : variation ***
File in include path
===DONE===

View File

@ -0,0 +1,54 @@
--TEST--
Test file_get_contents() function : variation - include path testing
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
* Description: Read the entire file into a string
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_get_contents() : variation ***\n";
require_once('fopen_include_path.inc');
// this doesn't create the include dirs in this directory
// we change to this to ensure we are not part of the
// include paths.
$thisTestDir = "FileGetContentsVar2.dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$filename = 'FileGetContentsVar2.tmp';
$scriptLocFile = dirname(__FILE__)."/".$filename;
$newpath = create_include_path();
set_include_path($newpath);
runtest();
teardown_include_path();
restore_include_path();
chdir("..");
rmdir($thisTestDir);
function runtest() {
global $scriptLocFile, $filename;
$h = fopen($scriptLocFile, "w");
fwrite($h, "File in script location");
fclose($h);
$line = file_get_contents($filename, true);
echo "$line\n";
unlink($scriptLocFile);
}
?>
===DONE===
--EXPECT--
*** Testing file_get_contents() : variation ***
File in script location
===DONE===

View File

@ -0,0 +1,220 @@
--TEST--
Test file_get_contents() function : usage variation - different type for use_include_path
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
* Description: Read the entire file into a string
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_get_contents() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$filename = 'FileGetContentsVar3.tmp';
$absFile = dirname(__FILE__).'/'.$filename;
$h = fopen($absFile,"w");
fwrite($h, "contents read");
fclose($h);
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// string data
'string DQ' => "string",
'string SQ' => 'string',
'mixed case string' => "sTrInG",
'heredoc' => $heredoc,
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
);
// loop through each element of the array for use_include_path
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
var_dump( file_get_contents($absFile, $value) );
};
unlink($absFile);
?>
===DONE===
--EXPECTF--
*** Testing file_get_contents() : usage variation ***
--int 0--
unicode(13) "contents read"
--int 1--
unicode(13) "contents read"
--int 12345--
unicode(%d) "contents read"
--int -12345--
unicode(%d) "contents read"
--float 10.5--
unicode(%d) "contents read"
--float -10.5--
unicode(%d) "contents read"
--float 12.3456789000e10--
unicode(%d) "contents read"
--float -12.3456789000e10--
unicode(%d) "contents read"
--float .5--
unicode(%d) "contents read"
--empty array--
Error: 2 - file_get_contents() expects parameter 2 to be boolean, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - file_get_contents() expects parameter 2 to be boolean, array given, %s(%d)
NULL
--associative array--
Error: 2 - file_get_contents() expects parameter 2 to be boolean, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - file_get_contents() expects parameter 2 to be boolean, array given, %s(%d)
NULL
--uppercase NULL--
unicode(%d) "contents read"
--lowercase null--
unicode(%d) "contents read"
--lowercase true--
unicode(%d) "contents read"
--lowercase false--
unicode(%d) "contents read"
--uppercase TRUE--
unicode(%d) "contents read"
--uppercase FALSE--
unicode(%d) "contents read"
--empty string DQ--
unicode(%d) "contents read"
--empty string SQ--
unicode(%d) "contents read"
--string DQ--
unicode(%d) "contents read"
--string SQ--
unicode(%d) "contents read"
--mixed case string--
unicode(%d) "contents read"
--heredoc--
unicode(%d) "contents read"
--instance of classWithToString--
Error: 2 - file_get_contents() expects parameter 2 to be boolean, object given, %s(%d)
NULL
--instance of classWithoutToString--
Error: 2 - file_get_contents() expects parameter 2 to be boolean, object given, %s(%d)
NULL
--undefined var--
unicode(%d) "contents read"
--unset var--
unicode(%d) "contents read"
===DONE===

View File

@ -0,0 +1,253 @@
--TEST--
Test file_get_contents() function : usage variation - different types for context.
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
* Description: Read the entire file into a string
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_get_contents() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$filename = 'FileGetContentsVar4.tmp';
$absFile = dirname(__FILE__).'/'.$filename;
$h = fopen($absFile,"w");
fwrite($h, "contents read");
fclose($h);
$fileRes = fopen(__FILE__,'r');
$strContext = stream_context_create();
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// string data
'string DQ' => "string",
'string SQ' => 'string',
'mixed case string' => "sTrInG",
'heredoc' => $heredoc,
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
//non context resource
'file resource' => $fileRes,
//valid stream context
'stream context' => $strContext,
);
// loop through each element of the array for context
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
var_dump( file_get_contents($absFile, false, $value) );
};
unlink($absFile);
fclose($fileRes);
?>
===DONE===
--EXPECTF--
*** Testing file_get_contents() : usage variation ***
--int 0--
Error: 2 - file_get_contents() expects parameter 3 to be resource, integer given, %s(%d)
NULL
--int 1--
Error: 2 - file_get_contents() expects parameter 3 to be resource, integer given, %s(%d)
NULL
--int 12345--
Error: 2 - file_get_contents() expects parameter 3 to be resource, integer given, %s(%d)
NULL
--int -12345--
Error: 2 - file_get_contents() expects parameter 3 to be resource, integer given, %s(%d)
NULL
--float 10.5--
Error: 2 - file_get_contents() expects parameter 3 to be resource, double given, %s(%d)
NULL
--float -10.5--
Error: 2 - file_get_contents() expects parameter 3 to be resource, double given, %s(%d)
NULL
--float 12.3456789000e10--
Error: 2 - file_get_contents() expects parameter 3 to be resource, double given, %s(%d)
NULL
--float -12.3456789000e10--
Error: 2 - file_get_contents() expects parameter 3 to be resource, double given, %s(%d)
NULL
--float .5--
Error: 2 - file_get_contents() expects parameter 3 to be resource, double given, %s(%d)
NULL
--empty array--
Error: 2 - file_get_contents() expects parameter 3 to be resource, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - file_get_contents() expects parameter 3 to be resource, array given, %s(%d)
NULL
--associative array--
Error: 2 - file_get_contents() expects parameter 3 to be resource, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - file_get_contents() expects parameter 3 to be resource, array given, %s(%d)
NULL
--uppercase NULL--
unicode(%d) "contents read"
--lowercase null--
unicode(%d) "contents read"
--lowercase true--
Error: 2 - file_get_contents() expects parameter 3 to be resource, boolean given, %s(%d)
NULL
--lowercase false--
Error: 2 - file_get_contents() expects parameter 3 to be resource, boolean given, %s(%d)
NULL
--uppercase TRUE--
Error: 2 - file_get_contents() expects parameter 3 to be resource, boolean given, %s(%d)
NULL
--uppercase FALSE--
Error: 2 - file_get_contents() expects parameter 3 to be resource, boolean given, %s(%d)
NULL
--empty string DQ--
Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d)
NULL
--empty string SQ--
Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d)
NULL
--string DQ--
Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d)
NULL
--string SQ--
Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d)
NULL
--mixed case string--
Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d)
NULL
--heredoc--
Error: 2 - file_get_contents() expects parameter 3 to be resource, Unicode string given, %s(%d)
NULL
--instance of classWithToString--
Error: 2 - file_get_contents() expects parameter 3 to be resource, object given, %s(%d)
NULL
--instance of classWithoutToString--
Error: 2 - file_get_contents() expects parameter 3 to be resource, object given, %s(%d)
NULL
--undefined var--
unicode(%d) "contents read"
--unset var--
unicode(%d) "contents read"
--file resource--
Error: 2 - file_get_contents(): supplied resource is not a valid Stream-Context resource, %s(%d)
unicode(%d) "contents read"
--stream context--
unicode(%d) "contents read"
===DONE===

View File

@ -0,0 +1,224 @@
--TEST--
Test file_get_contents() function : usage variation
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
* Description: Read the entire file into a string
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_get_contents() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$filename = 'FileGetContentsVar5.tmp';
$absFile = dirname(__FILE__).'/'.$filename;
$h = fopen($absFile,"w");
fwrite($h, "contents read");
fclose($h);
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// string data
'string DQ' => "string",
'string SQ' => 'string',
'mixed case string' => "sTrInG",
'heredoc' => $heredoc,
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
);
// loop through each element of the array for offset
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
var_dump( file_get_contents($absFile, false, null, $value) );
};
unlink($absFile);
?>
===DONE===
--EXPECTF--
*** Testing file_get_contents() : usage variation ***
--int 0--
unicode(%d) "contents read"
--int 1--
unicode(%d) "ontents read"
--int 12345--
unicode(%d) ""
--int -12345--
unicode(%d) "contents read"
--float 10.5--
unicode(3) "ead"
--float -10.5--
unicode(%d) "contents read"
--float 12.3456789000e10--
unicode(%d) %s
--float -12.3456789000e10--
unicode(%d) %s
--float .5--
unicode(%d) "contents read"
--empty array--
Error: 2 - file_get_contents() expects parameter 4 to be long, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - file_get_contents() expects parameter 4 to be long, array given, %s(%d)
NULL
--associative array--
Error: 2 - file_get_contents() expects parameter 4 to be long, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - file_get_contents() expects parameter 4 to be long, array given, %s(%d)
NULL
--uppercase NULL--
unicode(%d) "contents read"
--lowercase null--
unicode(%d) "contents read"
--lowercase true--
unicode(12) "ontents read"
--lowercase false--
unicode(%d) "contents read"
--uppercase TRUE--
unicode(12) "ontents read"
--uppercase FALSE--
unicode(%d) "contents read"
--empty string DQ--
Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d)
NULL
--empty string SQ--
Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d)
NULL
--string DQ--
Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d)
NULL
--string SQ--
Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d)
NULL
--mixed case string--
Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d)
NULL
--heredoc--
Error: 2 - file_get_contents() expects parameter 4 to be long, Unicode string given, %s(%d)
NULL
--instance of classWithToString--
Error: 2 - file_get_contents() expects parameter 4 to be long, object given, %s(%d)
NULL
--instance of classWithoutToString--
Error: 2 - file_get_contents() expects parameter 4 to be long, object given, %s(%d)
NULL
--undefined var--
unicode(%d) "contents read"
--unset var--
unicode(%d) "contents read"
===DONE===

View File

@ -0,0 +1,217 @@
--TEST--
Test file_get_contents() function : usage variation
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
* Description: Read the entire file into a string
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_get_contents() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$filename = 'FileGetContentsVar5.tmp';
$absFile = dirname(__FILE__).'/'.$filename;
$h = fopen($absFile,"w");
fwrite($h, "contents read");
fclose($h);
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// string data
'string DQ' => "string",
'string SQ' => 'string',
'mixed case string' => "sTrInG",
'heredoc' => $heredoc,
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
);
// loop through each element of the array for maxlen
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
var_dump( file_get_contents($absFile, false, null, 0, $value) );
};
unlink($absFile);
?>
===DONE===
--EXPECTF--
*** Testing file_get_contents() : usage variation ***
--int 0--
unicode(%d) ""
--int 1--
unicode(%d) "c"
--int 12345--
unicode(%d) "contents read"
--int -12345--
Error: 2 - file_get_contents(): length must be greater than or equal to zero, %s(%d)
bool(false)
--float 10.5--
unicode(%d) "contents r"
--float -10.5--
Error: 2 - file_get_contents(): length must be greater than or equal to zero, %s(%d)
bool(false)
--float .5--
unicode(%d) ""
--empty array--
Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d)
NULL
--associative array--
Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - file_get_contents() expects parameter 5 to be long, array given, %s(%d)
NULL
--uppercase NULL--
unicode(%d) ""
--lowercase null--
unicode(%d) ""
--lowercase true--
unicode(%d) "c"
--lowercase false--
unicode(%d) ""
--uppercase TRUE--
unicode(%d) "c"
--uppercase FALSE--
unicode(%d) ""
--empty string DQ--
Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d)
NULL
--empty string SQ--
Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d)
NULL
--string DQ--
Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d)
NULL
--string SQ--
Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d)
NULL
--mixed case string--
Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d)
NULL
--heredoc--
Error: 2 - file_get_contents() expects parameter 5 to be long, Unicode string given, %s(%d)
NULL
--instance of classWithToString--
Error: 2 - file_get_contents() expects parameter 5 to be long, object given, %s(%d)
NULL
--instance of classWithoutToString--
Error: 2 - file_get_contents() expects parameter 5 to be long, object given, %s(%d)
NULL
--undefined var--
unicode(%d) ""
--unset var--
unicode(%d) ""
===DONE===

View File

@ -0,0 +1,117 @@
--TEST--
Test file_get_contents() function : variation - various absolute and relative paths
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
die("skip Only run on Windows");
?>
--FILE--
<?php
/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
* Description: Read the entire file into a string
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_get_contents() : variation ***\n";
$mainDir = "fileGetContentsVar7.dir";
$subDir = "fileGetContentsVar7Sub";
$absMainDir = dirname(__FILE__)."\\".$mainDir;
mkdir($absMainDir);
$absSubDir = $absMainDir."\\".$subDir;
mkdir($absSubDir);
$old_dir_path = getcwd();
chdir(dirname(__FILE__));
$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3);
$allDirs = array(
// absolute paths
"$absSubDir\\",
"$absSubDir\\..\\".$subDir,
"$absSubDir\\\\..\\.\\".$subDir,
"$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir,
"$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir,
"$absSubDir\\BADDIR",
// relative paths
$mainDir."\\".$subDir,
$mainDir."\\\\".$subDir,
$mainDir."\\\\\\".$subDir,
".\\".$mainDir."\\..\\".$mainDir."\\".$subDir,
"BADDIR",
// unixifed path
$unixifiedDir,
);
$filename = 'FileGetContentsVar7.tmp';
$absFile = $absSubDir.'/'.$filename;
$h = fopen($absFile,"w");
fwrite($h, "contents read");
fclose($h);
for($i = 0; $i<count($allDirs); $i++) {
$j = $i+1;
$dir = $allDirs[$i];
echo "\n-- Iteration $j --\n";
var_dump(file_get_contents($dir."\\".$filename));
}
unlink($absFile);
chdir($old_dir_path);
rmdir($absSubDir);
rmdir($absMainDir);
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing file_get_contents() : variation ***
-- Iteration 1 --
unicode(%d) "contents read"
-- Iteration 2 --
unicode(%d) "contents read"
-- Iteration 3 --
unicode(%d) "contents read"
-- Iteration 4 --
unicode(%d) "contents read"
-- Iteration 5 --
Warning: file_get_contents(%sfileGetContentsVar7.dir\fileGetContentsVar7Sub\..\\\fileGetContentsVar7Sub\\..\\..\fileGetContentsVar7Sub\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 6 --
Warning: file_get_contents(%sfileGetContentsVar7.dir\fileGetContentsVar7Sub\BADDIR\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 7 --
unicode(%d) "contents read"
-- Iteration 8 --
unicode(%d) "contents read"
-- Iteration 9 --
unicode(%d) "contents read"
-- Iteration 10 --
unicode(%d) "contents read"
-- Iteration 11 --
Warning: file_get_contents(BADDIR\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 12 --
unicode(%d) "contents read"
*** Done ***

View File

@ -0,0 +1,106 @@
--TEST--
Test file_get_contents() function : variation - various absolute and relative paths
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
* Description: Read the entire file into a string
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_get_contents() : variation ***\n";
$mainDir = "fileGetContentsVar7.dir";
$subDir = "fileGetContentsVar7Sub";
$absMainDir = dirname(__FILE__)."/".$mainDir;
mkdir($absMainDir);
$absSubDir = $absMainDir."/".$subDir;
mkdir($absSubDir);
$old_dir_path = getcwd();
chdir(dirname(__FILE__));
$allDirs = array(
// absolute paths
"$absSubDir/",
"$absSubDir/../".$subDir,
"$absSubDir//.././".$subDir,
"$absSubDir/../../".$mainDir."/./".$subDir,
"$absSubDir/..///".$subDir."//..//../".$subDir,
"$absSubDir/BADDIR",
// relative paths
$mainDir."/".$subDir,
$mainDir."//".$subDir,
$mainDir."///".$subDir,
"./".$mainDir."/../".$mainDir."/".$subDir,
"BADDIR",
);
$filename = 'FileGetContentsVar7.tmp';
$absFile = $absSubDir.'/'.$filename;
$h = fopen($absFile,"w");
fwrite($h, "contents read");
fclose($h);
for($i = 0; $i<count($allDirs); $i++) {
$j = $i+1;
$dir = $allDirs[$i];
echo "\n-- Iteration $j --\n";
var_dump(file_get_contents($dir."/".$filename));
}
unlink($absFile);
chdir($old_dir_path);
rmdir($absSubDir);
rmdir($absMainDir);
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing file_get_contents() : variation ***
-- Iteration 1 --
unicode(%d) "contents read"
-- Iteration 2 --
unicode(%d) "contents read"
-- Iteration 3 --
unicode(%d) "contents read"
-- Iteration 4 --
unicode(%d) "contents read"
-- Iteration 5 --
Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/..///fileGetContentsVar7Sub//..//../fileGetContentsVar7Sub/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 6 --
Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 7 --
unicode(%d) "contents read"
-- Iteration 8 --
unicode(%d) "contents read"
-- Iteration 9 --
unicode(%d) "contents read"
-- Iteration 10 --
unicode(%d) "contents read"
-- Iteration 11 --
Warning: file_get_contents(BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
*** Done ***

View File

@ -0,0 +1,84 @@
--TEST--
Test file_get_contents() function : variation - obscure filenames
--XFAIL--
Return values are inconsistent (and have changed from previous versions)
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
die("skip Only run on Windows");
?>
--FILE--
<?php
/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
* Description: Read the entire file into a string
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_get_contents() : variation ***\n";
/* An array of filenames */
$names_arr = array(
/* Invalid args */
-1,
TRUE,
FALSE,
NULL,
"",
" ",
"\0",
array(),
/* prefix with path separator of a non existing directory*/
"/no/such/file/dir",
"php/php"
);
for( $i=0; $i<count($names_arr); $i++ ) {
echo "-- Iteration $i --\n";
var_dump(file_get_contents($names_arr[$i]));
}
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing file_get_contents() : variation ***
-- Iteration 0 --
Warning: file_get_contents(-1): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 1 --
Warning: file_get_contents(1): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 2 --
bool(false)
-- Iteration 3 --
bool(false)
-- Iteration 4 --
bool(false)
-- Iteration 5 --
Warning: file_get_contents( ): failed to open stream: Permission denied in %s on line %d
bool(false)
-- Iteration 6 --
bool(false)
-- Iteration 7 --
Notice: Array to string conversion in %s on line %d
Warning: file_get_contents(Array): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 8 --
Warning: file_get_contents(/no/such/file/dir): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 9 --
Warning: file_get_contents(php/php): failed to open stream: No such file or directory in %s on line %d
bool(false)
*** Done ***

View File

@ -0,0 +1,82 @@
--TEST--
Test file_get_contents() function : variation - obscure filenames
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Do not run on Windows");
?>
--FILE--
<?php
/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
* Description: Read the entire file into a string
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_get_contents() : variation ***\n";
/* An array of filenames */
$names_arr = array(
/* Invalid args */
-1,
TRUE,
FALSE,
NULL,
"",
" ",
"\0",
array(),
/* prefix with path separator of a non existing directory*/
"/no/such/file/dir",
"php/php"
);
for( $i=0; $i<count($names_arr); $i++ ) {
echo "-- Iteration $i --\n";
var_dump(file_get_contents($names_arr[$i]));
}
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing file_get_contents() : variation ***
-- Iteration 0 --
Warning: file_get_contents(-1): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 1 --
Warning: file_get_contents(1): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 2 --
bool(false)
-- Iteration 3 --
bool(false)
-- Iteration 4 --
bool(false)
-- Iteration 5 --
Warning: file_get_contents( ): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 6 --
bool(false)
-- Iteration 7 --
Notice: Array to string conversion in %s on line %d
Warning: file_get_contents(Array): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 8 --
Warning: file_get_contents(/no/such/file/dir): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 9 --
Warning: file_get_contents(php/php): failed to open stream: No such file or directory in %s on line %d
bool(false)
*** Done ***

View File

@ -0,0 +1,56 @@
--TEST--
Test file_get_contents() function : variation - linked files
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Do not run on Windows");
?>
--FILE--
<?php
/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
* Description: Read the entire file into a string
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_get_contents() : variation ***\n";
$filename = dirname(__FILE__).'/fileGetContentsVar9.tmp';
$softlink = dirname(__FILE__).'/fileGetContentsVar9.SoftLink';
$hardlink = dirname(__FILE__).'/fileGetContentsVar9.HardLink';
$chainlink = dirname(__FILE__).'/fileGetContentsVar9.ChainLink';
// create file
$h = fopen($filename,"w");
//Data should be more than the size of a link.
for ($i = 1; $i <= 10; $i++) {
fwrite($h, "Here is a repeated amount of data");
}
fclose($h);
// link files
link($filename, $hardlink);
symlink($filename, $softlink);
symlink($softlink, $chainlink);
// perform tests
var_dump(file_get_contents($chainlink));
var_dump(file_get_contents($softlink));
var_dump(file_get_contents($hardlink));
unlink($chainlink);
unlink($softlink);
unlink($hardlink);
unlink($filename);
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing file_get_contents() : variation ***
string(330) "Here is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of data"
string(330) "Here is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of data"
string(330) "Here is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of dataHere is a repeated amount of data"
*** Done ***

View File

@ -0,0 +1,45 @@
--TEST--
Test file_put_contents() function : variation - test append flag
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
* Description: Write/Create a file with contents data and return the number of bytes written
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_put_contents() : variation ***\n";
$filename = "FilePutContentsVar1.tmp";
$data = "The first string to write";
$extra = ", followed by this";
var_dump(file_put_contents($filename, $data));
var_dump(file_put_contents($filename, $extra, FILE_APPEND));
echo filesize($filename)."\n";
readfile($filename);
echo "\n";
clearstatcache();
file_put_contents($filename, $data);
echo filesize($filename)."\n";
readfile($filename);
echo "\n";
unlink($filename);
?>
===DONE===
--EXPECTF--
*** Testing file_put_contents() : variation ***
int(25)
int(18)
43
The first string to write, followed by this
25
The first string to write
===DONE===

View File

@ -0,0 +1,170 @@
--TEST--
Test file_put_contents() function : usage variation - different data types to write
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
* Description: Write/Create a file with contents data and return the number of bytes written
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_put_contents() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$filename = 'fwriteVar5.tmp';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
);
// loop through each element of the array for str
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
file_put_contents($filename, $value);
readfile($filename);
};
unlink($filename);
?>
===DONE===
--EXPECTF--
*** Testing file_put_contents() : usage variation ***
--int 0--
0
--int 1--
1
--int 12345--
12345
--int -12345--
-2345
--float 10.5--
10.5
--float -10.5--
-10.5
--float 12.3456789000e10--
123456789000
--float -12.3456789000e10--
-123456789000
--float .5--
0.5
--empty array--
--int indexed array--
123
--associative array--
12
--nested arrays--
Error: 8 - Array to string conversion, %s(%d)
Error: 8 - Array to string conversion, %s(%d)
fooArrayArray
--uppercase NULL--
--lowercase null--
--lowercase true--
1
--lowercase false--
--uppercase TRUE--
1
--uppercase FALSE--
--empty string DQ--
--empty string SQ--
--instance of classWithToString--
Error: 2 - file_put_contents(): 2nd parameter must be non-object (for now), %s(%d)
--instance of classWithoutToString--
Error: 2 - file_put_contents(): 2nd parameter must be non-object (for now), %s(%d)
--undefined var--
--unset var--
===DONE===

View File

@ -0,0 +1,252 @@
--TEST--
Test file_put_contents() function : usage variation - different types for context.
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
* Description: Write/Create a file with contents data and return the number of bytes written
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_put_contents() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$filename = 'FilePutContentsVar4.tmp';
$absFile = dirname(__FILE__).'/'.$filename;
$fileRes = fopen(__FILE__,'r');
$strContext = stream_context_create();
$data = "data to write";
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// string data
'string DQ' => "string",
'string SQ' => 'string',
'mixed case string' => "sTrInG",
'heredoc' => $heredoc,
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
//non context resource
'file resource' => $fileRes,
//valid stream context
'stream context' => $strContext,
);
// loop through each element of the array for context
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
var_dump( file_put_contents($absFile, $data, null, $value) );
};
unlink($absFile);
fclose($fileRes);
?>
===DONE===
--EXPECTF--
*** Testing file_put_contents() : usage variation ***
--int 0--
Error: 2 - file_put_contents() expects parameter 4 to be resource, integer given, %s(%d)
NULL
--int 1--
Error: 2 - file_put_contents() expects parameter 4 to be resource, integer given, %s(%d)
NULL
--int 12345--
Error: 2 - file_put_contents() expects parameter 4 to be resource, integer given, %s(%d)
NULL
--int -12345--
Error: 2 - file_put_contents() expects parameter 4 to be resource, integer given, %s(%d)
NULL
--float 10.5--
Error: 2 - file_put_contents() expects parameter 4 to be resource, double given, %s(%d)
NULL
--float -10.5--
Error: 2 - file_put_contents() expects parameter 4 to be resource, double given, %s(%d)
NULL
--float 12.3456789000e10--
Error: 2 - file_put_contents() expects parameter 4 to be resource, double given, %s(%d)
NULL
--float -12.3456789000e10--
Error: 2 - file_put_contents() expects parameter 4 to be resource, double given, %s(%d)
NULL
--float .5--
Error: 2 - file_put_contents() expects parameter 4 to be resource, double given, %s(%d)
NULL
--empty array--
Error: 2 - file_put_contents() expects parameter 4 to be resource, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - file_put_contents() expects parameter 4 to be resource, array given, %s(%d)
NULL
--associative array--
Error: 2 - file_put_contents() expects parameter 4 to be resource, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - file_put_contents() expects parameter 4 to be resource, array given, %s(%d)
NULL
--uppercase NULL--
int(13)
--lowercase null--
int(13)
--lowercase true--
Error: 2 - file_put_contents() expects parameter 4 to be resource, boolean given, %s(%d)
NULL
--lowercase false--
Error: 2 - file_put_contents() expects parameter 4 to be resource, boolean given, %s(%d)
NULL
--uppercase TRUE--
Error: 2 - file_put_contents() expects parameter 4 to be resource, boolean given, %s(%d)
NULL
--uppercase FALSE--
Error: 2 - file_put_contents() expects parameter 4 to be resource, boolean given, %s(%d)
NULL
--empty string DQ--
Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d)
NULL
--empty string SQ--
Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d)
NULL
--string DQ--
Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d)
NULL
--string SQ--
Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d)
NULL
--mixed case string--
Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d)
NULL
--heredoc--
Error: 2 - file_put_contents() expects parameter 4 to be resource, Unicode string given, %s(%d)
NULL
--instance of classWithToString--
Error: 2 - file_put_contents() expects parameter 4 to be resource, object given, %s(%d)
NULL
--instance of classWithoutToString--
Error: 2 - file_put_contents() expects parameter 4 to be resource, object given, %s(%d)
NULL
--undefined var--
int(13)
--unset var--
int(13)
--file resource--
Error: 2 - file_put_contents(): supplied resource is not a valid Stream-Context resource, %s(%d)
int(13)
--stream context--
int(13)
===DONE===

View File

@ -0,0 +1,55 @@
--TEST--
Test file_put_contents() function : variation - include path testing
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
* Description: Write/Create a file with contents data and return the number of bytes written
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_put_contents() : variation ***\n";
require_once('fopen_include_path.inc');
// this doesn't create the include dirs in this directory
// we change to this to ensure we are not part of the
// include paths.
$thisTestDir = "filePutContentsVar4.dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$filename = "afile.txt";
$firstFile = $dir1."/".$filename;
$newpath = create_include_path();
set_include_path($newpath);
runtest();
$newpath = generate_next_path();
set_include_path($newpath);
runtest();
teardown_include_path();
restore_include_path();
chdir("..");
rmdir($thisTestDir);
function runtest() {
global $firstFile, $filename;
file_put_contents($filename, "File in include path", FILE_USE_INCLUDE_PATH);
$line = file_get_contents($firstFile);
echo "$line\n";
unlink($firstFile);
}
?>
===DONE===
--EXPECT--
*** Testing file_put_contents() : variation ***
File in include path
File in include path
===DONE===

View File

@ -0,0 +1,60 @@
--TEST--
Test file_put_contents() function : variation - include path testing
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
* Description: Write/Create a file with contents data and return the number of bytes written
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_put_contents() : variation ***\n";
require_once('fopen_include_path.inc');
// this doesn't create the include dirs in this directory
// we change to this to ensure we are not part of the
// include paths.
$thisTestDir = "fileGetContentsVar7.dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$filename = "readFileVar7.tmp";
$scriptLocFile = dirname(__FILE__)."/".$filename;
$newpath = "rubbish";
set_include_path($newpath);
runtest();
$newpath = "";
set_include_path($newpath);
runtest();
set_include_path(null);
runtest();
set_include_path(";; ; ;c:\\rubbish");
runtest();
chdir("..");
rmdir($thisTestDir);
function runtest() {
global $scriptLocFile, $filename;
file_put_contents($filename, "File in script location", FILE_USE_INCLUDE_PATH);
$line = file_get_contents($scriptLocFile);
echo "$line\n";
unlink($scriptLocFile);
}
?>
===DONE===
--EXPECT--
*** Testing file_put_contents() : variation ***
File in script location
File in script location
File in script location
File in script location
===DONE===

View File

@ -0,0 +1,56 @@
--TEST--
Test file_put_contents() function : variation - include path testing
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
* Description: Write/Create a file with contents data and return the number of bytes written
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_put_contents() : variation ***\n";
require_once('fopen_include_path.inc');
// this doesn't create the include dirs in this directory
// we change to this to ensure we are not part of the
// include paths.
$thisTestDir = "filePutContentsVar6.dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$filename = "afile.txt";
$firstFile = $dir1."/".$filename;
$newpath = create_include_path();
set_include_path($newpath);
runtest();
$newpath = generate_next_path();
set_include_path($newpath);
runtest();
teardown_include_path();
restore_include_path();
chdir("..");
rmdir($thisTestDir);
function runtest() {
global $firstFile, $filename;
file_put_contents($filename, "File in include path", FILE_USE_INCLUDE_PATH);
file_put_contents($filename, ". This was appended", FILE_USE_INCLUDE_PATH | FILE_APPEND);
$line = file_get_contents($firstFile);
echo "$line\n";
unlink($firstFile);
}
?>
===DONE===
--EXPECT--
*** Testing file_put_contents() : variation ***
File in include path. This was appended
File in include path. This was appended
===DONE===

View File

@ -0,0 +1,130 @@
--TEST--
Test file_put_contents() function : usage variation - various absolute and relative paths
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
die("skip Only run on Windows");
?>
--FILE--
<?php
/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
* Description: Write/Create a file with contents data and return the number of bytes written
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_put_contents() : usage variation ***\n";
$mainDir = "filePutContentsVar7.dir";
$subDir = "filePutContentsVar7Sub";
$absMainDir = dirname(__FILE__)."/".$mainDir;
mkdir($absMainDir);
$absSubDir = $absMainDir."\\".$subDir;
mkdir($absSubDir);
$old_dir_path = getcwd();
chdir(dirname(__FILE__));
$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3);
// Note invalid dirs in p8 result in (The system cannot find the path specified.)
// rather than No Such File or Directory in php.net
$allDirs = array(
// absolute paths
"$absSubDir\\",
"$absSubDir\\..\\".$subDir,
"$absSubDir\\\\..\\.\\".$subDir,
"$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir,
"$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir,
"$absSubDir\\BADDIR",
// relative paths
$mainDir."\\".$subDir,
$mainDir."\\\\".$subDir,
$mainDir."\\\\\\".$subDir,
".\\".$mainDir."\\..\\".$mainDir."\\".$subDir,
"BADDIR",
// unixifed path
$unixifiedDir,
);
$filename = 'FileGetContentsVar7.tmp';
$absFile = $absSubDir.'/'.$filename;
$data = "This was the written data";
for($i = 0; $i<count($allDirs); $i++) {
$j = $i+1;
$dir = $allDirs[$i];
echo "\n-- Iteration $j --\n";
$res = file_put_contents($dir."\\".$filename, ($data + $i));
if ($res !== false) {
$in = file_get_contents($absFile);
if ($in == ($data + $i)) {
echo "Data written correctly\n";
}
else {
echo "Data not written correctly or to correct place\n";
}
unlink($dir."/".$filename);
}
else {
echo "No data written\n";
}
}
chdir($old_dir_path);
rmdir($absSubDir);
rmdir($absMainDir);
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing file_put_contents() : usage variation ***
-- Iteration 1 --
Data written correctly
-- Iteration 2 --
Data written correctly
-- Iteration 3 --
Data written correctly
-- Iteration 4 --
Data written correctly
-- Iteration 5 --
Warning: file_put_contents(%sfilePutContentsVar7.dir\filePutContentsVar7Sub\..\\\filePutContentsVar7Sub\\..\\..\filePutContentsVar7Sub\FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
No data written
-- Iteration 6 --
Warning: file_put_contents(%sfilePutContentsVar7.dir\filePutContentsVar7Sub\BADDIR\FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
No data written
-- Iteration 7 --
Data written correctly
-- Iteration 8 --
Data written correctly
-- Iteration 9 --
Data written correctly
-- Iteration 10 --
Data written correctly
-- Iteration 11 --
Warning: file_put_contents(BADDIR\FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
No data written
-- Iteration 12 --
Data written correctly
*** Done ***

View File

@ -0,0 +1,119 @@
--TEST--
Test file_put_contents() function : usage variation - various absolute and relative paths
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
* Description: Write/Create a file with contents data and return the number of bytes written
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_put_contents() : usage variation ***\n";
$mainDir = "filePutContentsVar7.dir";
$subDir = "filePutContentsVar7Sub";
$absMainDir = dirname(__FILE__)."/".$mainDir;
mkdir($absMainDir);
$absSubDir = $absMainDir."/".$subDir;
mkdir($absSubDir);
$old_dir_path = getcwd();
chdir(dirname(__FILE__));
// Note invalid dirs in p8 result in (The system cannot find the path specified.)
// rather than No Such File or Directory in php.net
$allDirs = array(
// absolute paths
"$absSubDir/",
"$absSubDir/../".$subDir,
"$absSubDir//.././".$subDir,
"$absSubDir/../../".$mainDir."/./".$subDir,
"$absSubDir/..///".$subDir."//..//../".$subDir,
"$absSubDir/BADDIR",
// relative paths
$mainDir."/".$subDir,
$mainDir."//".$subDir,
$mainDir."///".$subDir,
"./".$mainDir."/../".$mainDir."/".$subDir,
"BADDIR",
);
$filename = 'FileGetContentsVar7.tmp';
$absFile = $absSubDir.'/'.$filename;
$data = "This was the written data";
for($i = 0; $i<count($allDirs); $i++) {
$j = $i+1;
$dir = $allDirs[$i];
echo "\n-- Iteration $j --\n";
$res = file_put_contents($dir."/".$filename, ($data + $i));
if ($res !== false) {
$in = file_get_contents($absFile);
if ($in == ($data + $i)) {
echo "Data written correctly\n";
}
else {
echo "Data not written correctly or to correct place\n";
}
unlink($dir."/".$filename);
}
else {
echo "No data written\n";
}
}
chdir($old_dir_path);
rmdir($absSubDir);
rmdir($absMainDir);
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing file_put_contents() : usage variation ***
-- Iteration 1 --
Data written correctly
-- Iteration 2 --
Data written correctly
-- Iteration 3 --
Data written correctly
-- Iteration 4 --
Data written correctly
-- Iteration 5 --
Warning: file_put_contents(%sfilePutContentsVar7.dir/filePutContentsVar7Sub/..///filePutContentsVar7Sub//..//../filePutContentsVar7Sub/FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
No data written
-- Iteration 6 --
Warning: file_put_contents(%sfilePutContentsVar7.dir/filePutContentsVar7Sub/BADDIR/FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
No data written
-- Iteration 7 --
Data written correctly
-- Iteration 8 --
Data written correctly
-- Iteration 9 --
Data written correctly
-- Iteration 10 --
Data written correctly
-- Iteration 11 --
Warning: file_put_contents(BADDIR/FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
No data written
*** Done ***

View File

@ -0,0 +1,73 @@
--TEST--
est file_put_contents() function : usage variation - linked files
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Do not run on Windows");
?>
--FILE--
<?php
/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]])
* Description: Write/Create a file with contents data and return the number of bytes written
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file_put_contents() : usage variation ***\n";
$filename = dirname(__FILE__).'/fileGetContentsVar9.tmp';
$softlink = dirname(__FILE__).'/fileGetContentsVar9.SoftLink';
$hardlink = dirname(__FILE__).'/fileGetContentsVar9.HardLink';
$chainlink = dirname(__FILE__).'/fileGetContentsVar9.ChainLink';
// link files even though it original file doesn't exist yet
symlink($filename, $softlink);
symlink($softlink, $chainlink);
// perform tests
run_test($chainlink);
run_test($softlink);
//can only create a hardlink if the file exists.
file_put_contents($filename,"");
link($filename, $hardlink);
run_test($hardlink);
unlink($chainlink);
unlink($softlink);
unlink($hardlink);
unlink($filename);
function run_test($file) {
$data = "Here is some data";
$extra = ", more data";
var_dump(file_put_contents($file, $data));
var_dump(file_put_contents($file, $extra, FILE_APPEND));
readfile($file);
echo "\n";
}
echo "\n*** Done ***\n";
?>
--EXPECT--
*** Testing file_put_contents() : usage variation ***
int(17)
int(11)
Here is some data, more data
int(17)
int(11)
Here is some data, more data
int(17)
int(11)
Here is some data, more data
*** Done ***

View File

@ -0,0 +1,145 @@
--TEST--
Test file() function : variation - various absolute and relative paths
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
die("skip Only run on Windows");
?>
--FILE--
<?php
/* Prototype : array file(string filename [, int flags[, resource context]])
* Description: Read entire file into an array
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file() : variation ***\n";
$mainDir = "fileVar8.dir";
$subDir = "fileVar8Sub";
$absMainDir = dirname(__FILE__)."\\".$mainDir;
mkdir($absMainDir);
$absSubDir = $absMainDir."\\".$subDir;
mkdir($absSubDir);
$old_dir_path = getcwd();
chdir(dirname(__FILE__));
$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3);
$allDirs = array(
// absolute paths
"$absSubDir\\",
"$absSubDir\\..\\".$subDir,
"$absSubDir\\\\..\\.\\".$subDir,
"$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir,
"$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir,
"$absSubDir\\BADDIR",
// relative paths
$mainDir."\\".$subDir,
$mainDir."\\\\".$subDir,
$mainDir."\\\\\\".$subDir,
".\\".$mainDir."\\..\\".$mainDir."\\".$subDir,
"BADDIR",
// unixifed path
$unixifiedDir,
);
$filename = 'FileGetContentsVar7.tmp';
$absFile = $absSubDir.'/'.$filename;
$h = fopen($absFile,"w");
fwrite($h, "contents read");
fclose($h);
for($i = 0; $i<count($allDirs); $i++) {
$j = $i+1;
$dir = $allDirs[$i];
echo "\n-- Iteration $j --\n";
var_dump(file($dir."\\".$filename));
}
unlink($absFile);
chdir($old_dir_path);
rmdir($absSubDir);
rmdir($absMainDir);
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing file() : variation ***
-- Iteration 1 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 2 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 3 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 4 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 5 --
Warning: file(%s\fileVar8.dir\fileVar8Sub\..\\\fileVar8Sub\\..\\..\fileVar8Sub\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 6 --
Warning: file(%s\fileVar8.dir\fileVar8Sub\BADDIR\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 7 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 8 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 9 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 10 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 11 --
Warning: file(BADDIR\FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 12 --
array(1) {
[0]=>
string(13) "contents read"
}
*** Done ***

View File

@ -0,0 +1,131 @@
--TEST--
Test file function : variation - various absolute and relative paths
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : array file(string filename [, int flags[, resource context]])
* Description: Read entire file into an array
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file() : variation ***\n";
$mainDir = "fileVar8.dir";
$subDir = "fileVar8Sub";
$absMainDir = dirname(__FILE__)."/".$mainDir;
mkdir($absMainDir);
$absSubDir = $absMainDir."/".$subDir;
mkdir($absSubDir);
$old_dir_path = getcwd();
chdir(dirname(__FILE__));
$allDirs = array(
// absolute paths
"$absSubDir/",
"$absSubDir/../".$subDir,
"$absSubDir//.././".$subDir,
"$absSubDir/../../".$mainDir."/./".$subDir,
"$absSubDir/..///".$subDir."//..//../".$subDir,
"$absSubDir/BADDIR",
// relative paths
$mainDir."/".$subDir,
$mainDir."//".$subDir,
$mainDir."///".$subDir,
"./".$mainDir."/../".$mainDir."/".$subDir,
"BADDIR",
);
$filename = 'FileGetContentsVar7.tmp';
$absFile = $absSubDir.'/'.$filename;
$h = fopen($absFile,"w");
fwrite($h, "contents read");
fclose($h);
for($i = 0; $i<count($allDirs); $i++) {
$j = $i+1;
$dir = $allDirs[$i];
echo "\n-- Iteration $j --\n";
var_dump(file($dir."/".$filename));
}
unlink($absFile);
chdir($old_dir_path);
rmdir($absSubDir);
rmdir($absMainDir);
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing file() : variation ***
-- Iteration 1 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 2 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 3 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 4 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 5 --
Warning: file(%s/fileVar8.dir/fileVar8Sub/..///fileVar8Sub//..//../fileVar8Sub/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 6 --
Warning: file(%s/fileVar8.dir/fileVar8Sub/BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
-- Iteration 7 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 8 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 9 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 10 --
array(1) {
[0]=>
string(13) "contents read"
}
-- Iteration 11 --
Warning: file(BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d
bool(false)
*** Done ***

View File

@ -0,0 +1,92 @@
--TEST--
Test file function : variation - test various endings of a file
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : array file(string filename [, int flags[, resource context]])
* Description: Read entire file into an array
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing file() : variation ***\n";
$testfile = dirname(__FILE__)."/fileVar9.txt";
$contents = array(
"File ends on a single character\na",
"File ends on a new line\n",
"File ends on multiple newlines\n\n\n\n",
"File has\n\nmultiple lines and newlines\n\n",
"File has\r\nmultiple crlfs\n\r\n"
);
@unlink($testfile);
foreach ($contents as $content) {
$h = fopen($testfile, "w");
fwrite($h, $content);
fclose($h);
var_dump(file($testfile));
unlink($testfile);
}
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing file() : variation ***
array(2) {
[0]=>
string(32) "File ends on a single character
"
[1]=>
string(1) "a"
}
array(1) {
[0]=>
string(24) "File ends on a new line
"
}
array(4) {
[0]=>
string(31) "File ends on multiple newlines
"
[1]=>
string(1) "
"
[2]=>
string(1) "
"
[3]=>
string(1) "
"
}
array(4) {
[0]=>
string(9) "File has
"
[1]=>
string(1) "
"
[2]=>
string(28) "multiple lines and newlines
"
[3]=>
string(1) "
"
}
array(3) {
[0]=>
string(10) "File has
"
[1]=>
string(15) "multiple crlfs
"
[2]=>
string(2) "
"
}
*** Done ***

View File

@ -0,0 +1,47 @@
--TEST--
Test filegroup() function: usage variations - links
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip Do not run on Windows');
}
--FILE--
<?php
/* Prototype: int filegroup ( string $filename )
* Description: Returns the group ID of the file, or FALSE in case of an error.
*/
/* Creating soft and hard links to a file and applying filegroup() on links */
$file_path = dirname(__FILE__);
fclose( fopen($file_path."/filegroup_variation1.tmp", "w") );
echo "*** Testing filegroup() with links ***\n";
/* With symlink */
symlink($file_path."/filegroup_variation1.tmp", $file_path."/filegroup_variation1_symlink.tmp");
var_dump( filegroup($file_path."/filegroup_variation1_symlink.tmp") ); //expected true
clearstatcache();
/* With hardlink */
link($file_path."/filegroup_variation1.tmp", $file_path."/filegroup_variation1_link.tmp");
var_dump( filegroup($file_path."/filegroup_variation1_link.tmp") ); // expected: true
clearstatcache();
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/filegroup_variation1_symlink.tmp");
unlink($file_path."/filegroup_variation1_link.tmp");
unlink($file_path."/filegroup_variation1.tmp");
?>
--EXPECTF--
*** Testing filegroup() with links ***
int(%d)
int(%d)
*** Done ***

View File

@ -0,0 +1,71 @@
--TEST--
Test filegroup() function: usage variations - invalid filenames
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype: int filegroup ( string $filename )
* Description: Returns the group ID of the file, or FALSE in case of an error.
*/
/* Testing filegroup() with invalid arguments -int, float, bool, NULL, resource */
$file_path = dirname(__FILE__);
$file_handle = fopen($file_path."/filegroup_variation2.tmp", "w");
echo "*** Testing Invalid file types ***\n";
$filenames = array(
/* Invalid filenames */
-2.34555,
" ",
"",
TRUE,
FALSE,
NULL,
$file_handle,
/* scalars */
1234,
0
);
/* loop through to test each element the above array */
foreach( $filenames as $filename ) {
var_dump( filegroup($filename) );
clearstatcache();
}
fclose($file_handle);
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/filegroup_variation2.tmp");
?>
--EXPECTF--
*** Testing Invalid file types ***
Warning: filegroup(): stat failed for -2.34555 in %s on line %d
bool(false)
Warning: filegroup(): stat failed for in %s on line %d
bool(false)
bool(false)
Warning: filegroup(): stat failed for 1 in %s on line %d
bool(false)
bool(false)
bool(false)
Warning: filegroup() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d
NULL
Warning: filegroup(): stat failed for 1234 in %s on line %d
bool(false)
Warning: filegroup(): stat failed for 0 in %s on line %d
bool(false)
*** Done ***

View File

@ -0,0 +1,81 @@
--TEST--
Test filegroup() function: usage variations - diff. path notations
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype: int filegroup ( string $filename )
* Description: Returns the group ID of the file, or FALSE in case of an error.
*/
/* Passing file names with different notations, using slashes, wild-card chars */
$file_path = dirname(__FILE__);
echo "*** Testing filegroup() with different notations of file names ***\n";
$dir_name = $file_path."/filegroup_variation3";
mkdir($dir_name);
$file_handle = fopen($dir_name."/filegroup_variation3.tmp", "w");
fclose($file_handle);
$files_arr = array(
"/filegroup_variation3/filegroup_variation3.tmp",
/* Testing a file trailing slash */
"/filegroup_variation3/filegroup_variation3.tmp/",
/* Testing file with double slashes */
"/filegroup_variation3//filegroup_variation3.tmp",
"//filegroup_variation3//filegroup_variation3.tmp",
"/filegroup_variation3/*.tmp",
"filegroup_variation3/filegroup*.tmp",
/* Testing Binary safe */
"/filegroup_variation3/filegroup_variation3.tmp".chr(0),
"/filegroup_variation3/filegroup_variation3.tmp\0"
);
$count = 1;
/* loop through to test each element in the above array */
foreach($files_arr as $file) {
echo "- Iteration $count -\n";
var_dump( filegroup( $file_path."/".$file ) );
clearstatcache();
$count++;
}
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
$dir_name = $file_path."/filegroup_variation3";
unlink($dir_name."/filegroup_variation3.tmp");
rmdir($dir_name);
?>
--EXPECTF--
*** Testing filegroup() with different notations of file names ***
- Iteration 1 -
int(%d)
- Iteration 2 -
Warning: filegroup(): stat failed for %s//filegroup_variation3/filegroup_variation3.tmp/ in %s on line %d
bool(false)
- Iteration 3 -
int(%d)
- Iteration 4 -
int(%d)
- Iteration 5 -
Warning: filegroup(): stat failed for %s//filegroup_variation3/*.tmp in %s on line %d
bool(false)
- Iteration 6 -
Warning: filegroup(): stat failed for %s/filegroup_variation3/filegroup*.tmp in %s on line %d
bool(false)
- Iteration 7 -
int(%d)
- Iteration 8 -
int(%d)
*** Done ***

View File

@ -0,0 +1,48 @@
--TEST--
Test fileinode() function: usage variations - links
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip Do not run on Windows');
}
--FILE--
<?php
/*
Prototype: int fileinode ( string $filename );
Description: Returns the inode number of the file, or FALSE in case of an error.
*/
/* Creating soft and hard links to a file and applying fileinode() on links */
$file_path = dirname(__FILE__);
fclose( fopen($file_path."/fileinode_variation1.tmp", "w") );
echo "*** Testing fileinode() with links ***\n";
/* With symlink */
symlink($file_path."/fileinode_variation1.tmp", $file_path."/fileinode_variation1_symlink.tmp");
var_dump( fileinode($file_path."/fileinode_variation1_symlink.tmp") ); //expected true
clearstatcache();
/* With hardlink */
link($file_path."/fileinode_variation1.tmp", $file_path."/fileinode_variation1_link.tmp");
var_dump( fileinode($file_path."/fileinode_variation1_link.tmp") ); // expected: true
clearstatcache();
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/fileinode_variation1_symlink.tmp");
unlink($file_path."/fileinode_variation1_link.tmp");
unlink($file_path."/fileinode_variation1.tmp");
?>
--EXPECTF--
*** Testing fileinode() with links ***
int(%d)
int(%d)
*** Done ***

View File

@ -0,0 +1,72 @@
--TEST--
Test fileinode() function: usage variations - invalid filenames
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/*
Prototype: int fileinode ( string $filename );
Description: Returns the inode number of the file, or FALSE in case of an error.
*/
/* Testing fileinode() with invalid arguments -int, float, bool, NULL, resource */
$file_path = dirname(__FILE__);
$file_handle = fopen($file_path."/fileinode_variation2.tmp", "w");
echo "*** Testing Invalid file types ***\n";
$filenames = array(
/* Invalid filenames */
-2.34555,
" ",
"",
TRUE,
FALSE,
NULL,
$file_handle,
/* scalars */
1234,
0
);
/* loop through to test each element the above array */
foreach( $filenames as $filename ) {
var_dump( fileinode($filename) );
clearstatcache();
}
fclose($file_handle);
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/fileinode_variation2.tmp");
?>
--EXPECTF--
*** Testing Invalid file types ***
Warning: fileinode(): stat failed for -2.34555 in %s on line %d
bool(false)
Warning: fileinode(): stat failed for in %s on line %d
bool(false)
bool(false)
Warning: fileinode(): stat failed for 1 in %s on line %d
bool(false)
bool(false)
bool(false)
Warning: fileinode() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d
NULL
Warning: fileinode(): stat failed for 1234 in %s on line %d
bool(false)
Warning: fileinode(): stat failed for 0 in %s on line %d
bool(false)
*** Done ***

View File

@ -0,0 +1,82 @@
--TEST--
Test fileinode() function: usage variations - diff. path notations
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/*
Prototype: int fileinode ( string $filename );
Description: Returns the inode number of the file, or FALSE in case of an error.
*/
/* Passing file names with different notations, using slashes, wild-card chars */
$file_path = dirname(__FILE__);
echo "*** Testing fileinode() with different notations of file names ***\n";
$dir_name = $file_path."/fileinode_variation3";
mkdir($dir_name);
$file_handle = fopen($dir_name."/fileinode_variation3.tmp", "w");
fclose($file_handle);
$files_arr = array(
"/fileinode_variation3/fileinode_variation3.tmp",
/* Testing a file trailing slash */
"/fileinode_variation3/fileinode_variation3.tmp/",
/* Testing file with double slashes */
"/fileinode_variation3//fileinode_variation3.tmp",
"//fileinode_variation3//fileinode_variation3.tmp",
"/fileinode_variation3/*.tmp",
"fileinode_variation3/fileinode*.tmp",
/* Testing Binary safe */
"/fileinode_variation3/fileinode_variation3.tmp".chr(0),
"/fileinode_variation3/fileinode_variation3.tmp\0"
);
$count = 1;
/* loop through to test each element in the above array */
foreach($files_arr as $file) {
echo "- Iteration $count -\n";
var_dump( fileinode( $file_path."/".$file ) );
clearstatcache();
$count++;
}
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
$dir_name = $file_path."/fileinode_variation3";
unlink($dir_name."/fileinode_variation3.tmp");
rmdir($dir_name);
?>
--EXPECTF--
*** Testing fileinode() with different notations of file names ***
- Iteration 1 -
int(%d)
- Iteration 2 -
Warning: fileinode(): stat failed for %s//fileinode_variation3/fileinode_variation3.tmp/ in %s on line %d
bool(false)
- Iteration 3 -
int(%d)
- Iteration 4 -
int(%d)
- Iteration 5 -
Warning: fileinode(): stat failed for %s//fileinode_variation3/*.tmp in %s on line %d
bool(false)
- Iteration 6 -
Warning: fileinode(): stat failed for %s/fileinode_variation3/fileinode*.tmp in %s on line %d
bool(false)
- Iteration 7 -
int(%d)
- Iteration 8 -
int(%d)
*** Done ***

View File

@ -0,0 +1,48 @@
--TEST--
Test fileowner() function: usage variations - links
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip Do not run on Windows');
}
--FILE--
<?php
/* Prototype: int fileowner ( string $filename )
* Description: Returns the user ID of the owner of the file, or
* FALSE in case of an error.
*/
/* Creating soft and hard links to a file and applying fileowner() on links */
$file_path = dirname(__FILE__);
fclose( fopen($file_path."/fileowner_variation1.tmp", "w") );
echo "*** Testing fileowner() with links ***\n";
/* With symlink */
symlink($file_path."/fileowner_variation1.tmp", $file_path."/fileowner_variation1_symlink.tmp");
var_dump( fileowner($file_path."/fileowner_variation1_symlink.tmp") ); //expected true
clearstatcache();
/* With hardlink */
link($file_path."/fileowner_variation1.tmp", $file_path."/fileowner_variation1_link.tmp");
var_dump( fileowner($file_path."/fileowner_variation1_link.tmp") ); // expected: true
clearstatcache();
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/fileowner_variation1_symlink.tmp");
unlink($file_path."/fileowner_variation1_link.tmp");
unlink($file_path."/fileowner_variation1.tmp");
?>
--EXPECTF--
*** Testing fileowner() with links ***
int(%d)
int(%d)
*** Done ***

View File

@ -0,0 +1,72 @@
--TEST--
Test fileowner() function: usage variations - invalid filenames
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype: int fileowner ( string $filename )
* Description: Returns the user ID of the owner of the file, or
* FALSE in case of an error.
*/
/* Testing fileowner() with invalid arguments -int, float, bool, NULL, resource */
$file_path = dirname(__FILE__);
$file_handle = fopen($file_path."/fileowner_variation2.tmp", "w");
echo "*** Testing Invalid file types ***\n";
$filenames = array(
/* Invalid filenames */
-2.34555,
" ",
"",
TRUE,
FALSE,
NULL,
$file_handle,
/* scalars */
1234,
0
);
/* loop through to test each element the above array */
foreach( $filenames as $filename ) {
var_dump( fileowner($filename) );
clearstatcache();
}
fclose($file_handle);
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/fileowner_variation2.tmp");
?>
--EXPECTF--
*** Testing Invalid file types ***
Warning: fileowner(): stat failed for -2.34555 in %s on line %d
bool(false)
Warning: fileowner(): stat failed for in %s on line %d
bool(false)
bool(false)
Warning: fileowner(): stat failed for 1 in %s on line %d
bool(false)
bool(false)
bool(false)
Warning: fileowner() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d
NULL
Warning: fileowner(): stat failed for 1234 in %s on line %d
bool(false)
Warning: fileowner(): stat failed for 0 in %s on line %d
bool(false)
*** Done ***

View File

@ -0,0 +1,82 @@
--TEST--
Test fileowner() function: usage variations - diff. path notations
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype: int fileowner ( string $filename )
* Description: Returns the user ID of the owner of the file, or
* FALSE in case of an error.
*/
/* Passing file names with different notations, using slashes, wild-card chars */
$file_path = dirname(__FILE__);
echo "*** Testing fileowner() with different notations of file names ***\n";
$dir_name = $file_path."/fileowner_variation3";
mkdir($dir_name);
$file_handle = fopen($dir_name."/fileowner_variation3.tmp", "w");
fclose($file_handle);
$files_arr = array(
"/fileowner_variation3/fileowner_variation3.tmp",
/* Testing a file trailing slash */
"/fileowner_variation3/fileowner_variation3.tmp/",
/* Testing file with double slashes */
"/fileowner_variation3//fileowner_variation3.tmp",
"//fileowner_variation3//fileowner_variation3.tmp",
"/fileowner_variation3/*.tmp",
"fileowner_variation3/fileowner*.tmp",
/* Testing Binary safe */
"/fileowner_variation3/fileowner_variation3.tmp".chr(0),
"/fileowner_variation3/fileowner_variation3.tmp\0"
);
$count = 1;
/* loop through to test each element in the above array */
foreach($files_arr as $file) {
echo "- Iteration $count -\n";
var_dump( fileowner( $file_path."/".$file ) );
clearstatcache();
$count++;
}
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
$dir_name = $file_path."/fileowner_variation3";
unlink($dir_name."/fileowner_variation3.tmp");
rmdir($dir_name);
?>
--EXPECTF--
*** Testing fileowner() with different notations of file names ***
- Iteration 1 -
int(%d)
- Iteration 2 -
Warning: fileowner(): stat failed for %s//fileowner_variation3/fileowner_variation3.tmp/ in %s on line %d
bool(false)
- Iteration 3 -
int(%d)
- Iteration 4 -
int(%d)
- Iteration 5 -
Warning: fileowner(): stat failed for %s//fileowner_variation3/*.tmp in %s on line %d
bool(false)
- Iteration 6 -
Warning: fileowner(): stat failed for %s/fileowner_variation3/fileowner*.tmp in %s on line %d
bool(false)
- Iteration 7 -
int(%d)
- Iteration 8 -
int(%d)
*** Done ***

View File

@ -0,0 +1,47 @@
--TEST--
Test fileperms() function: usage variations - links
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip Do not run on Windows');
}
--FILE--
<?php
/* Prototype: int fileperms ( string $filename )
* Description: Returns the group ID of the file, or FALSE in case of an error.
*/
/* Creating soft and hard links to a file and applying fileperms() on links */
$file_path = dirname(__FILE__);
fclose( fopen($file_path."/fileperms_variation1.tmp", "w") );
echo "*** Testing fileperms() with links ***\n";
/* With symlink */
symlink($file_path."/fileperms_variation1.tmp", $file_path."/fileperms_variation1_symlink.tmp");
var_dump( fileperms($file_path."/fileperms_variation1_symlink.tmp") ); //expected true
clearstatcache();
/* With hardlink */
link($file_path."/fileperms_variation1.tmp", $file_path."/fileperms_variation1_link.tmp");
var_dump( fileperms($file_path."/fileperms_variation1_link.tmp") ); // expected: true
clearstatcache();
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/fileperms_variation1_symlink.tmp");
unlink($file_path."/fileperms_variation1_link.tmp");
unlink($file_path."/fileperms_variation1.tmp");
?>
--EXPECTF--
*** Testing fileperms() with links ***
int(%d)
int(%d)
*** Done ***

View File

@ -0,0 +1,71 @@
--TEST--
Test fileperms() function: usage variations - invalid filenames
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype: int fileperms ( string $filename )
* Description: Returns the group ID of the file, or FALSE in case of an error.
*/
/* Testing fileperms() with invalid arguments -int, float, bool, NULL, resource */
$file_path = dirname(__FILE__);
$file_handle = fopen($file_path."/fileperms_variation2.tmp", "w");
echo "*** Testing Invalid file types ***\n";
$filenames = array(
/* Invalid filenames */
-2.34555,
" ",
"",
TRUE,
FALSE,
NULL,
$file_handle,
/* scalars */
1234,
0
);
/* loop through to test each element the above array */
foreach( $filenames as $filename ) {
var_dump( fileperms($filename) );
clearstatcache();
}
fclose($file_handle);
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/fileperms_variation2.tmp");
?>
--EXPECTF--
*** Testing Invalid file types ***
Warning: fileperms(): stat failed for -2.34555 in %s on line %d
bool(false)
Warning: fileperms(): stat failed for in %s on line %d
bool(false)
bool(false)
Warning: fileperms(): stat failed for 1 in %s on line %d
bool(false)
bool(false)
bool(false)
Warning: fileperms() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d
NULL
Warning: fileperms(): stat failed for 1234 in %s on line %d
bool(false)
Warning: fileperms(): stat failed for 0 in %s on line %d
bool(false)
*** Done ***

View File

@ -0,0 +1,81 @@
--TEST--
Test fileperms() function: usage variations - diff. path notations
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype: int fileperms ( string $filename )
* Description: Returns the group ID of the file, or FALSE in case of an error.
*/
/* Passing file names with different notations, using slashes, wild-card chars */
$file_path = dirname(__FILE__);
echo "*** Testing fileperms() with different notations of file names ***\n";
$dir_name = $file_path."/fileperms_variation3";
mkdir($dir_name);
$file_handle = fopen($dir_name."/fileperms_variation3.tmp", "w");
fclose($file_handle);
$files_arr = array(
"/fileperms_variation3/fileperms_variation3.tmp",
/* Testing a file trailing slash */
"/fileperms_variation3/fileperms_variation3.tmp/",
/* Testing file with double slashes */
"/fileperms_variation3//fileperms_variation3.tmp",
"//fileperms_variation3//fileperms_variation3.tmp",
"/fileperms_variation3/*.tmp",
"fileperms_variation3/fileperms*.tmp",
/* Testing Binary safe */
"/fileperms_variation3/fileperms_variation3.tmp".chr(0),
"/fileperms_variation3/fileperms_variation3.tmp\0"
);
$count = 1;
/* loop through to test each element in the above array */
foreach($files_arr as $file) {
echo "- Iteration $count -\n";
var_dump( fileperms( $file_path."/".$file ) );
clearstatcache();
$count++;
}
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
$dir_name = $file_path."/fileperms_variation3";
unlink($dir_name."/fileperms_variation3.tmp");
rmdir($dir_name);
?>
--EXPECTF--
*** Testing fileperms() with different notations of file names ***
- Iteration 1 -
int(%d)
- Iteration 2 -
Warning: fileperms(): stat failed for %s//fileperms_variation3/fileperms_variation3.tmp/ in %s on line %d
bool(false)
- Iteration 3 -
int(%d)
- Iteration 4 -
int(%d)
- Iteration 5 -
Warning: fileperms(): stat failed for %s//fileperms_variation3/*.tmp in %s on line %d
bool(false)
- Iteration 6 -
Warning: fileperms(): stat failed for %s/fileperms_variation3/fileperms*.tmp in %s on line %d
bool(false)
- Iteration 7 -
int(%d)
- Iteration 8 -
int(%d)
*** Done ***

View File

@ -3,7 +3,7 @@ Test filesize() function: usage variations - size of files
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip only valid for Linux');
die('skip Not valid on Windows');
}
--FILE--
<?php
@ -29,17 +29,17 @@ for($size = 1; $size <10000; $size = $size+1000)
echo "Done\n";
--EXPECT--
--EXPECTF--
*** Testing filesize(): usage variations ***
*** Checking filesize() with different size of files ***
int(1024)
int(1025024)
int(2049024)
int(3073024)
int(4097024)
int(5121024)
int(6145024)
int(7169024)
int(8193024)
int(9217024)
int(%d)
int(%d)
int(%d)
int(%d)
int(%d)
int(%d)
int(%d)
int(%d)
int(%d)
int(%d)
Done

View File

@ -0,0 +1,34 @@
--TEST--
Test filesize() function: usage variations - size of files
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/*
* Prototype : int filesize ( string $filename );
* Description : Returns the size of the file in bytes, or FALSE
* (and generates an error of level E_WARNING) in case of an error.
*/
echo "*** Testing filesize(): usage variations ***\n";
/* null, false, "", " " */
var_dump( filesize(NULL) );
var_dump( filesize(false) );
var_dump( filesize('') );
var_dump( filesize(' ') );
var_dump( filesize('|') );
echo "*** Done ***\n";
?>
--EXPECTF--
*** Testing filesize(): usage variations ***
bool(false)
bool(false)
bool(false)
Warning: filesize(): stat failed for in %s on line %d
bool(false)
Warning: filesize(): stat failed for | in %s on line %d
bool(false)
*** Done ***

View File

@ -0,0 +1,36 @@
--TEST--
Test filetype() function: Variations
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip no /dev on Windows');
}
?>
--FILE--
<?php
/*
Prototype: string filetype ( string $filename );
Description: Returns the type of the file. Possible values are fifo, char,
dir, block, link, file, and unknown.
*/
echo "*** Testing filetype() with various types ***\n";
echo "-- Checking for char --\n";
print( filetype("/dev/console") )."\n";
echo "-- Checking for block --\n";
//we have cheated in our mac build by creating a ram0 block device.
print( filetype("/dev/ram0") )."\n";
echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Testing filetype() with various types ***
-- Checking for char --
char
-- Checking for block --
block
*** Done ***

View File

@ -55,7 +55,7 @@ echo "\n*** Done ***\n";
$file = dirname(__FILE__)."/flock.tmp";
unlink($file);
?>
--EXPECTF--
--EXPECTF--
*** Testing error conditions ***
--- Iteration 0 ---
@ -91,8 +91,10 @@ Warning: flock() expects parameter 2 to be long, Unicode string given in %s on l
NULL
--- Iteration 8 ---
Warning: flock() expects parameter 2 to be long, string given in %s on line %d
NULL
Notice: A non well formed numeric value encountered in %s on line %d
Warning: flock(): Illegal operation argument in %s on line %d
bool(false)
Warning: flock(): 6 is not a valid stream resource in %s on line %d
bool(false)
@ -110,3 +112,4 @@ Warning: flock() expects at most 3 parameters, 4 given in %s on line %d
NULL
*** Done ***

View File

@ -1,371 +1,45 @@
--TEST--
Test flock() function: Variations
Test flock() function: usage variations
--FILE--
<?php
/*
Prototype: bool flock(resource $handle, int $operation [, int &$wouldblock]);
Description: PHP supports a portable way of locking complete files
in an advisory way
Description: PHP supports a portable way of locking complete files in an advisory way
*/
echo "*** Testing flock() fun with the various operation and
wouldblock values ***\n";
$file = dirname(__FILE__)."/flock.tmp";
$fp = fopen($file, "w");
echo "*** Test flock() function: with the operations given as numeric values ***\n";
/* array of operatons */
$filename = dirname(__FILE__)."/flock_variation.tmp";
$file_handle = fopen($filename, "w");
/* array of operations */
$operations = array(
LOCK_SH,
LOCK_EX,
LOCK_SH|LOCK_NB,
LOCK_EX|LOCK_NB,
LOCK_SH|LOCK_EX,
LOCK_UN,
1,
2,
2.234,
TRUE
);
/* array of wouldblocks */
$wouldblocks = array(
0,
1,
2,
1.234,
TRUE,
FALSE,
NULL,
array(1,2,3),
array(),
"string",
"",
/* binary input */
b"string",
b"",
"\0"
1, //nothing but LOCK_SH
2, //nothing but LOCK_EX
2.234, //nothing but LOCK_EX
TRUE //nothing but LOCK_SH
);
$i = 0;
foreach($operations as $operation) {
echo "--- Outer iteration $i ---\n";
var_dump(flock($fp, $operation));
$j = 0;
foreach($wouldblocks as $wouldblock) {
echo "-- Inner iteration $j in $i --\n";
var_dump(flock($fp, $operation, $wouldblock));
$j++;
}
var_dump(flock($file_handle, $operation));
var_dump(flock($file_handle, 3)); //nothing but LOCK_UN
$i++;
}
fclose($fp);
@unlink($file);
fclose($file_handle);
unlink($filename);
echo "\n*** Done ***\n";
echo "*** Done ***\n";
?>
--EXPECT--
*** Testing flock() fun with the various operation and
wouldblock values ***
--- Outer iteration 0 ---
--EXPECTF--
*** Test flock() function: with the operations given as numeric values ***
bool(true)
-- Inner iteration 0 in 0 --
bool(true)
-- Inner iteration 1 in 0 --
bool(true)
-- Inner iteration 2 in 0 --
bool(true)
-- Inner iteration 3 in 0 --
bool(true)
-- Inner iteration 4 in 0 --
bool(true)
-- Inner iteration 5 in 0 --
bool(true)
-- Inner iteration 6 in 0 --
bool(true)
-- Inner iteration 7 in 0 --
bool(true)
-- Inner iteration 8 in 0 --
bool(true)
-- Inner iteration 9 in 0 --
bool(true)
-- Inner iteration 10 in 0 --
bool(true)
-- Inner iteration 11 in 0 --
bool(true)
-- Inner iteration 12 in 0 --
bool(true)
-- Inner iteration 13 in 0 --
bool(true)
--- Outer iteration 1 ---
bool(true)
-- Inner iteration 0 in 1 --
bool(true)
-- Inner iteration 1 in 1 --
bool(true)
-- Inner iteration 2 in 1 --
bool(true)
-- Inner iteration 3 in 1 --
bool(true)
-- Inner iteration 4 in 1 --
bool(true)
-- Inner iteration 5 in 1 --
bool(true)
-- Inner iteration 6 in 1 --
bool(true)
-- Inner iteration 7 in 1 --
bool(true)
-- Inner iteration 8 in 1 --
bool(true)
-- Inner iteration 9 in 1 --
bool(true)
-- Inner iteration 10 in 1 --
bool(true)
-- Inner iteration 11 in 1 --
bool(true)
-- Inner iteration 12 in 1 --
bool(true)
-- Inner iteration 13 in 1 --
bool(true)
--- Outer iteration 2 ---
bool(true)
-- Inner iteration 0 in 2 --
bool(true)
-- Inner iteration 1 in 2 --
bool(true)
-- Inner iteration 2 in 2 --
bool(true)
-- Inner iteration 3 in 2 --
bool(true)
-- Inner iteration 4 in 2 --
bool(true)
-- Inner iteration 5 in 2 --
bool(true)
-- Inner iteration 6 in 2 --
bool(true)
-- Inner iteration 7 in 2 --
bool(true)
-- Inner iteration 8 in 2 --
bool(true)
-- Inner iteration 9 in 2 --
bool(true)
-- Inner iteration 10 in 2 --
bool(true)
-- Inner iteration 11 in 2 --
bool(true)
-- Inner iteration 12 in 2 --
bool(true)
-- Inner iteration 13 in 2 --
bool(true)
--- Outer iteration 3 ---
bool(true)
-- Inner iteration 0 in 3 --
bool(true)
-- Inner iteration 1 in 3 --
bool(true)
-- Inner iteration 2 in 3 --
bool(true)
-- Inner iteration 3 in 3 --
bool(true)
-- Inner iteration 4 in 3 --
bool(true)
-- Inner iteration 5 in 3 --
bool(true)
-- Inner iteration 6 in 3 --
bool(true)
-- Inner iteration 7 in 3 --
bool(true)
-- Inner iteration 8 in 3 --
bool(true)
-- Inner iteration 9 in 3 --
bool(true)
-- Inner iteration 10 in 3 --
bool(true)
-- Inner iteration 11 in 3 --
bool(true)
-- Inner iteration 12 in 3 --
bool(true)
-- Inner iteration 13 in 3 --
bool(true)
--- Outer iteration 4 ---
bool(true)
-- Inner iteration 0 in 4 --
bool(true)
-- Inner iteration 1 in 4 --
bool(true)
-- Inner iteration 2 in 4 --
bool(true)
-- Inner iteration 3 in 4 --
bool(true)
-- Inner iteration 4 in 4 --
bool(true)
-- Inner iteration 5 in 4 --
bool(true)
-- Inner iteration 6 in 4 --
bool(true)
-- Inner iteration 7 in 4 --
bool(true)
-- Inner iteration 8 in 4 --
bool(true)
-- Inner iteration 9 in 4 --
bool(true)
-- Inner iteration 10 in 4 --
bool(true)
-- Inner iteration 11 in 4 --
bool(true)
-- Inner iteration 12 in 4 --
bool(true)
-- Inner iteration 13 in 4 --
bool(true)
--- Outer iteration 5 ---
bool(true)
-- Inner iteration 0 in 5 --
bool(true)
-- Inner iteration 1 in 5 --
bool(true)
-- Inner iteration 2 in 5 --
bool(true)
-- Inner iteration 3 in 5 --
bool(true)
-- Inner iteration 4 in 5 --
bool(true)
-- Inner iteration 5 in 5 --
bool(true)
-- Inner iteration 6 in 5 --
bool(true)
-- Inner iteration 7 in 5 --
bool(true)
-- Inner iteration 8 in 5 --
bool(true)
-- Inner iteration 9 in 5 --
bool(true)
-- Inner iteration 10 in 5 --
bool(true)
-- Inner iteration 11 in 5 --
bool(true)
-- Inner iteration 12 in 5 --
bool(true)
-- Inner iteration 13 in 5 --
bool(true)
--- Outer iteration 6 ---
bool(true)
-- Inner iteration 0 in 6 --
bool(true)
-- Inner iteration 1 in 6 --
bool(true)
-- Inner iteration 2 in 6 --
bool(true)
-- Inner iteration 3 in 6 --
bool(true)
-- Inner iteration 4 in 6 --
bool(true)
-- Inner iteration 5 in 6 --
bool(true)
-- Inner iteration 6 in 6 --
bool(true)
-- Inner iteration 7 in 6 --
bool(true)
-- Inner iteration 8 in 6 --
bool(true)
-- Inner iteration 9 in 6 --
bool(true)
-- Inner iteration 10 in 6 --
bool(true)
-- Inner iteration 11 in 6 --
bool(true)
-- Inner iteration 12 in 6 --
bool(true)
-- Inner iteration 13 in 6 --
bool(true)
--- Outer iteration 7 ---
bool(true)
-- Inner iteration 0 in 7 --
bool(true)
-- Inner iteration 1 in 7 --
bool(true)
-- Inner iteration 2 in 7 --
bool(true)
-- Inner iteration 3 in 7 --
bool(true)
-- Inner iteration 4 in 7 --
bool(true)
-- Inner iteration 5 in 7 --
bool(true)
-- Inner iteration 6 in 7 --
bool(true)
-- Inner iteration 7 in 7 --
bool(true)
-- Inner iteration 8 in 7 --
bool(true)
-- Inner iteration 9 in 7 --
bool(true)
-- Inner iteration 10 in 7 --
bool(true)
-- Inner iteration 11 in 7 --
bool(true)
-- Inner iteration 12 in 7 --
bool(true)
-- Inner iteration 13 in 7 --
bool(true)
--- Outer iteration 8 ---
bool(true)
-- Inner iteration 0 in 8 --
bool(true)
-- Inner iteration 1 in 8 --
bool(true)
-- Inner iteration 2 in 8 --
bool(true)
-- Inner iteration 3 in 8 --
bool(true)
-- Inner iteration 4 in 8 --
bool(true)
-- Inner iteration 5 in 8 --
bool(true)
-- Inner iteration 6 in 8 --
bool(true)
-- Inner iteration 7 in 8 --
bool(true)
-- Inner iteration 8 in 8 --
bool(true)
-- Inner iteration 9 in 8 --
bool(true)
-- Inner iteration 10 in 8 --
bool(true)
-- Inner iteration 11 in 8 --
bool(true)
-- Inner iteration 12 in 8 --
bool(true)
-- Inner iteration 13 in 8 --
bool(true)
--- Outer iteration 9 ---
bool(true)
-- Inner iteration 0 in 9 --
bool(true)
-- Inner iteration 1 in 9 --
bool(true)
-- Inner iteration 2 in 9 --
bool(true)
-- Inner iteration 3 in 9 --
bool(true)
-- Inner iteration 4 in 9 --
bool(true)
-- Inner iteration 5 in 9 --
bool(true)
-- Inner iteration 6 in 9 --
bool(true)
-- Inner iteration 7 in 9 --
bool(true)
-- Inner iteration 8 in 9 --
bool(true)
-- Inner iteration 9 in 9 --
bool(true)
-- Inner iteration 10 in 9 --
bool(true)
-- Inner iteration 11 in 9 --
bool(true)
-- Inner iteration 12 in 9 --
bool(true)
-- Inner iteration 13 in 9 --
bool(true)
*** Done ***

View File

@ -0,0 +1,62 @@
--TEST--
Test flock() function: usage variations
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip.. not for Windows');
}
if (function_exists("pcntl_fork") == FALSE) {
die('skip.. no pcntl_fork()');
}
?>
--FILE--
<?php
/*
Prototype: bool flock(resource $handle, int $operation [, int &$wouldblock]);
Description: PHP supports a portable way of locking complete files in an advisory way
*/
echo "*** Test flock() function: with the operations given as numeric values ***\n";
$filename = dirname(__FILE__)."/flock_variation1.tmp";
$file_handle = fopen($filename, "w");
fwrite($file_handle, str_repeat("Hello2World", 10) );
fclose($file_handle);
$file_read = fopen($filename, "r");
$pid = pcntl_fork();
echo "-- child process is created --\n";
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
echo "-- Trying to get the Reader Lock --\n";
if( flock($file_read, LOCK_EX) ) {
echo "-- Got Lock --\n";
sleep(5);
flock($file_read, LOCK_UN);
}
else
echo "-- Couldn't get the Lock --\n";
} else {
echo "-- Trying to get the Writer Lock --\n";
if( flock($file_read, LOCK_EX) ) {
echo "-- Got Lock --\n";
flock($file_read, LOCK_UN);
}
else
echo "-- Couldn't get the Lock --\n";
}
echo "*** Done ***\n";
?>
--CLEAN--
<?php
fclose($file_read);
fclose($file_write);
unlink($filename);
?>
--EXPECTF--

View File

@ -0,0 +1,92 @@
<?php
$pwd = getcwd();
$f = basename(__FILE__);
$dir1 = $pwd."/".$f.".dir1";
$dir2 = $pwd."/".$f.".dir2";
$dir3 = $pwd."/".$f.".dir3";
//invalid directory
$dir4 = $pwd."/".$f.".dir4";
$newdirs = array($dir1, $dir2, $dir3);
$reldirs = array("dir1", "dir2", "dir3");
function generate_next_rel_path() {
global $reldirs;
//create the include directory structure
$pathSep = ":";
$newIncludePath = "";
if(substr(PHP_OS, 0, 3) == 'WIN' ) {
$pathSep = ";";
}
foreach($reldirs as $newdir) {
$newIncludePath .= $newdir.$pathSep;
}
return "dir4".$pathSep . $newIncludePath;
}
function generate_next_path() {
global $newdirs, $dir4;
//create the include directory structure
$pathSep = ":";
$newIncludePath = "";
if(substr(PHP_OS, 0, 3) == 'WIN' ) {
$pathSep = ";";
}
foreach($newdirs as $newdir) {
$newIncludePath .= $newdir.$pathSep;
}
return $dir4.$pathSep . $newIncludePath;
}
function create_include_path() {
global $newdirs;
//create the include directory structure
$pathSep = ":";
$newIncludePath = "";
if(substr(PHP_OS, 0, 3) == 'WIN' ) {
$pathSep = ";";
}
foreach($newdirs as $newdir) {
mkdir($newdir);
$newIncludePath .= $newdir.$pathSep;
}
return $newIncludePath;
}
function relative_include_path() {
global $reldirs;
//create the include directory structure
$pathSep = ":";
$newIncludePath = "";
if(substr(PHP_OS, 0, 3) == 'WIN' ) {
$pathSep = ";";
}
foreach($reldirs as $newdir) {
mkdir($newdir);
$newIncludePath .= $newdir.$pathSep;
}
return $newIncludePath;
}
function teardown_include_path() {
global $newdirs;
// remove the directory structure
foreach($newdirs as $newdir) {
rmdir($newdir);
}
}
function teardown_relative_path() {
global $reldirs;
// remove the directory structure
foreach($reldirs as $newdir) {
rmdir($newdir);
}
}
?>

View File

@ -0,0 +1,150 @@
--TEST--
Test fopen() function : variation: interesting paths, no use include path
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
die("skip Run only on Windows");
?>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : variation ***\n";
// fopen with interesting windows paths.
$testdir = dirname(__FILE__).'/fopen10.tmpDir';
$rootdir = 'fopen10.tmpdirTwo';
mkdir($testdir);
mkdir('c:\\'.$rootdir);
$unixifiedDir = '/'.substr(str_replace('\\','/',$testdir),3);
$paths = array('c:\\',
'c:',
'c',
'\\',
'/',
'c:'.$rootdir,
'c:adir',
'c:\\/',
'c:\\'.$rootdir.'\\/',
'c:\\'.$rootdir.'\\',
'c:\\'.$rootdir.'/',
$unixifiedDir,
'/sortout');
$file = "fopen_variation10.tmp";
$firstfile = 'c:\\'.$rootdir.'\\'.$file;
$secondfile = $testdir.'\\'.$file;
$thirdfile = 'c:\\'.$file;
$h = fopen($firstfile, 'w');
fwrite($h, "file in $rootdir");
fclose($h);
$h = fopen($secondfile, 'w');
fwrite($h, "file in fopen10.tmpDir");
fclose($h);
$h = fopen($thirdfile, 'w');
fwrite($h, "file in root");
fclose($h);
foreach($paths as $path) {
echo "\n--$path--\n";
$toFind = $path.'\\'.$file;
$h = fopen($toFind, 'r');
if ($h === false) {
echo "file not opened for read\n";
}
else {
fpassthru($h);
echo "\n";
}
fclose($h);
};
unlink($firstfile);
unlink($secondfile);
unlink($thirdfile);
rmdir($testdir);
rmdir('c:\\'.$rootdir);
?>
===DONE===
--EXPECTF--
*** Testing fopen() : variation ***
--c:\--
file in root
--c:--
file in root
--c--
Warning: fopen(c\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
--\--
Warning: fopen(\\fopen_variation10.tmp): failed to open stream: Invalid argument in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
--/--
Warning: fopen(/\fopen_variation10.tmp): failed to open stream: Invalid argument in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
--c:fopen10.tmpdirTwo--
Warning: fopen(c:fopen10.tmpdirTwo\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
--c:adir--
Warning: fopen(c:adir\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
--c:\/--
file in root
--c:\fopen10.tmpdirTwo\/--
file in fopen10.tmpdirTwo
--c:\fopen10.tmpdirTwo\--
file in fopen10.tmpdirTwo
--c:\fopen10.tmpdirTwo/--
file in fopen10.tmpdirTwo
--%s/fopen10.tmpDir--
file in fopen10.tmpDir
--/sortout--
Warning: fopen(/sortout\fopen_variation10.tmp): failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
===DONE===

View File

@ -0,0 +1,149 @@
--TEST--
Test fopen() function : variation: interesting paths, use include path = true
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
die("skip Run only on Windows");
?>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : variation ***\n";
// fopen with interesting windows paths.
$testdir = dirname(__FILE__).'/fopen11.tmpDir';
$rootdir = 'fopen11.tmpdirTwo';
mkdir($testdir);
mkdir('c:\\'.$rootdir);
$unixifiedDir = '/'.substr(str_replace('\\','/',$testdir),3);
$paths = array('c:\\',
'c:',
'c',
'\\',
'/',
'c:'.$rootdir,
'c:adir',
'c:\\/',
'c:\\'.$rootdir.'\\/',
'c:\\'.$rootdir.'\\',
'c:\\'.$rootdir.'/',
$unixifiedDir,
'/sortout');
$file = "fopen_variation11.tmp";
$firstfile = 'c:\\'.$rootdir.'\\'.$file;
$secondfile = $testdir.'\\'.$file;
$thirdfile = 'c:\\'.$file;
$h = fopen($firstfile, 'w');
fwrite($h, "file in $rootdir");
fclose($h);
$h = fopen($secondfile, 'w');
fwrite($h, "file in fopen11.tmpDir");
fclose($h);
$h = fopen($thirdfile, 'w');
fwrite($h, "file in root");
fclose($h);
foreach($paths as $path) {
echo "\n--$path--\n";
$toFind = $path.'\\'.$file;
$h = fopen($toFind, 'r', true);
if ($h === false) {
echo "file not opened for read\n";
}
else {
fpassthru($h);
echo "\n";
}
fclose($h);
};
unlink($firstfile);
unlink($secondfile);
unlink($thirdfile);
rmdir($testdir);
rmdir('c:\\'.$rootdir);
?>
===DONE===
--EXPECTF--
*** Testing fopen() : variation ***
--c:\--
file in root
--c:--
file in root
--c--
Warning: fopen(c\fopen_variation11.tmp): failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
--\--
Warning: fopen(\\FOPEN_VARIATION11.TMP): failed to open stream: Invalid argument in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
--/--
Warning: fopen(\\FOPEN_VARIATION11.TMP): failed to open stream: Invalid argument in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
--c:fopen11.tmpdirTwo--
Warning: fopen(c:fopen11.tmpdirTwo\fopen_variation11.tmp): failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
--c:adir--
Warning: fopen(c:adir\fopen_variation11.tmp): failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
--c:\/--
file in root
--c:\fopen11.tmpdirTwo\/--
file in fopen11.tmpdirTwo
--c:\fopen11.tmpdirTwo\--
file in fopen11.tmpdirTwo
--c:\fopen11.tmpdirTwo/--
file in fopen11.tmpdirTwo
--%s/fopen11.tmpDir--
file in fopen11.tmpDir
--/sortout--
Warning: fopen(/sortout\fopen_variation11.tmp): failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
===DONE===

View File

@ -0,0 +1,55 @@
--TEST--
Test fopen() function : variation: use include path (path is bad) create a file (relative)
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : variation ***\n";
set_include_path("rubbish");
testme();
restore_include_path();
function testme() {
$tmpfile = 'fopen_variation12.tmp';
$h = fopen($tmpfile, "w", true);
fwrite($h, "This is the test file");
fclose($h);
$h = @fopen($tmpfile, "r");
if ($h === false) {
echo "Not created in working dir\n";
}
else {
echo "created in working dir\n";
fclose($h);
unlink($tmpfile);
}
$scriptDirFile = dirname(__FILE__).'/'.$tmpfile;
$h = fopen($scriptDirFile, "r");
if ($h === false) {
echo "Not created in script dir\n";
}
else {
echo "created in script dir\n";
fclose($h);
unlink($scriptDirFile);
}
}
?>
===DONE===
--EXPECT--
*** Testing fopen() : variation ***
Not created in working dir
created in script dir
===DONE===

View File

@ -0,0 +1,58 @@
--TEST--
Test fopen() function : variation: use include path create a file (absolute)
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
require_once('fopen_include_path.inc');
echo "*** Testing fopen() : variation ***\n";
$newpath = create_include_path();
set_include_path($newpath);
runtest();
$newpath = generate_next_path();
set_include_path($newpath);
runtest();
teardown_include_path();
restore_include_path();
function runtest() {
$tempDir = 'fopen_variation13.dir.tmp';
$tmpfile = 'fopen_variation13.tmp';
$absFile = getcwd().'/'.$tempDir.'/'.$tmpfile;
mkdir($tempDir);
$h = fopen($absFile, "w", true);
fwrite($h, "This is the test file");
fclose($h);
$h = fopen($absFile, "r");
if ($h === false) {
echo "Not created absolute location\n";
}
else {
echo "Created in correct location\n";
fclose($h);
}
unlink($absFile);
rmdir($tempDir);
}
?>
===DONE===
--EXPECT--
*** Testing fopen() : variation ***
Created in correct location
Created in correct location
===DONE===

View File

@ -0,0 +1,191 @@
--TEST--
Test fopen() function : variation: file uri, no use include path
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
die("skip Run only on Windows");
?>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : variation ***\n";
// fopen with interesting windows paths.
$testDir = 'fopen14.tmpDir';
$absTestDir = getcwd().'/'.$testDir;
$file = "fopen_variation14.tmp";
$unixifiedDir = '/'.substr(str_replace('\\','/',$absTestDir),3);
$absFile = $absTestDir.'/'.$file;
mkdir($testDir);
$files = array("file://$testDir\\$file",
"file://$testDir/$file",
"file://./$testDir/$file",
"file://.\\$testDir\\$file",
"file://$absTestDir/$file",
"file://$absTestDir\\$file",
"file://$unixifiedDir/$file"
);
runtest($files);
chdir($testDir);
$files = array("file://../$testDir/$file",
"file://..\\$testDir\\$file",
"file://$absTestDir/$file",
"file://$absTestDir\\$file",
"file://$unixifiedDir/$file"
);
runtest($files);
chdir("..");
rmdir($testDir);
function runtest($fileURIs) {
global $absFile;
$iteration = 0;
foreach($fileURIs as $fileURI) {
echo "--- READ: $fileURI ---\n";
$readData = "read:$iteration";
$writeData = "write:$iteration";
// create the file and test read
$h = fopen($absFile, 'w');
fwrite($h, $readData);
fclose($h);
$h = fopen($fileURI, 'r');
if ($h !== false) {
if (fread($h, 4096) != $readData) {
echo "contents not correct\n";
}
else {
echo "test passed\n";
}
fclose($h);
}
unlink($absFile);
echo "--- WRITE: $fileURI ---\n";
// create the file to test write
$h = fopen($fileURI, 'w');
if ($h !== false) {
fwrite($h, $writeData);
fclose($h);
$h = fopen($absFile, 'r');
if ($h !== false) {
if (fread($h, 4096) != $writeData) {
echo "contents not correct\n";
}
else {
echo "test passed\n";
}
fclose($h);
}
unlink($absFile);
}
}
}
?>
===DONE===
--EXPECTF--
*** Testing fopen() : variation ***
--- READ: file://fopen14.tmpDir\fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
Warning: fopen(file://fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://fopen14.tmpDir\fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
Warning: fopen(file://fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://./fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://./fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://.\fopen14.tmpDir\fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://.\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
Warning: fopen(file://.\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://.\fopen14.tmpDir\fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://.\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
Warning: fopen(file://.\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
--- WRITE: file://%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
--- READ: file://%s/fopen14.tmpDir\fopen_variation14.tmp ---
test passed
--- WRITE: file://%s/fopen14.tmpDir\fopen_variation14.tmp ---
test passed
--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
--- READ: file://../fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://../fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://..\fopen14.tmpDir\fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://..\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
Warning: fopen(file://..\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://..\fopen14.tmpDir\fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://..\fopen14.tmpDir\fopen_variation14.tmp in %s on line %d
Warning: fopen(file://..\fopen14.tmpDir\fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
--- WRITE: file://%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
--- READ: file://%s/fopen14.tmpDir\fopen_variation14.tmp ---
test passed
--- WRITE: file://%s/fopen14.tmpDir\fopen_variation14.tmp ---
test passed
--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
===DONE===

View File

@ -0,0 +1,136 @@
--TEST--
Test fopen() function : variation: file uri, no use include path
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip not for Windows");
?>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : variation ***\n";
// fopen with interesting windows paths.
$testDir = 'fopen14.tmpDir';
$absTestDir = getcwd().'/'.$testDir;
$file = "fopen_variation14.tmp";
$absFile = $absTestDir.'/'.$file;
mkdir($testDir);
$files = array("file://$testDir/$file",
"file://./$testDir/$file",
"file://$absTestDir/$file"
);
runtest($files);
chdir($testDir);
$files = array("file://../$testDir/$file",
"file://$absTestDir/$file",
);
runtest($files);
chdir("..");
rmdir($testDir);
function runtest($fileURIs) {
global $absFile;
$iteration = 0;
foreach($fileURIs as $fileURI) {
echo "--- READ: $fileURI ---\n";
$readData = "read:$iteration";
$writeData = "write:$iteration";
// create the file and test read
$h = fopen($absFile, 'w');
fwrite($h, $readData);
fclose($h);
$h = fopen($fileURI, 'r');
if ($h !== false) {
if (fread($h, 4096) != $readData) {
echo "contents not correct\n";
}
else {
echo "test passed\n";
}
fclose($h);
}
unlink($absFile);
echo "--- WRITE: $fileURI ---\n";
// create the file to test write
$h = fopen($fileURI, 'w');
if ($h !== false) {
fwrite($h, $writeData);
fclose($h);
$h = fopen($absFile, 'r');
if ($h !== false) {
if (fread($h, 4096) != $writeData) {
echo "contents not correct\n";
}
else {
echo "test passed\n";
}
fclose($h);
}
unlink($absFile);
}
}
}
?>
===DONE===
--EXPECTF--
*** Testing fopen() : variation ***
--- READ: file://fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://./fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://./fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
--- READ: file://../fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://../fopen14.tmpDir/fopen_variation14.tmp ---
Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d
Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp ---
test passed
===DONE===

View File

@ -0,0 +1,195 @@
--TEST--
Test fopen() function : variation: file uri, use include path = true
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
die("skip Run only on Windows");
?>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : variation ***\n";
// fopen with interesting windows paths.
$includePathDir = getcwd().'/fopen15.includeDir';
$testDir = 'fopen15.tmpDir';
$absTestDir = getcwd().'/'.$testDir;
$file = "fopen_variation15.tmp";
$unixifiedDir = '/'.substr(str_replace('\\','/',$absTestDir),3);
$absFile = $absTestDir.'/'.$file;
mkdir($testDir);
mkdir($includePathDir);
set_include_path($includePathDir);
$files = array("file://$testDir\\$file",
"file://$testDir/$file",
"file://./$testDir/$file",
"file://.\\$testDir\\$file",
"file://$absTestDir/$file",
"file://$absTestDir\\$file",
"file://$unixifiedDir/$file"
);
runtest($files);
chdir($testDir);
$files = array("file://../$testDir/$file",
"file://..\\$testDir\\$file",
"file://$absTestDir/$file",
"file://$absTestDir\\$file",
"file://$unixifiedDir/$file"
);
runtest($files);
chdir("..");
rmdir($testDir);
rmdir($includePathDir);
function runtest($fileURIs) {
global $absFile;
$iteration = 0;
foreach($fileURIs as $fileURI) {
echo "--- READ: $fileURI ---\n";
$readData = "read:$iteration";
$writeData = "write:$iteration";
// create the file and test read
$h = fopen($absFile, 'w');
fwrite($h, $readData);
fclose($h);
$h = fopen($fileURI, 'r', true);
if ($h !== false) {
if (fread($h, 4096) != $readData) {
echo "contents not correct\n";
}
else {
echo "test passed\n";
}
fclose($h);
}
unlink($absFile);
echo "--- WRITE: $fileURI ---\n";
// create the file to test write
$h = fopen($fileURI, 'w', true);
if ($h !== false) {
fwrite($h, $writeData);
fclose($h);
$h = fopen($absFile, 'r');
if ($h !== false) {
if (fread($h, 4096) != $writeData) {
echo "contents not correct\n";
}
else {
echo "test passed\n";
}
fclose($h);
}
unlink($absFile);
}
}
}
?>
===DONE===
--EXPECTF--
*** Testing fopen() : variation ***
--- READ: file://fopen15.tmpDir\fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir\fopen_variation15.tmp in %s on line %d
Warning: fopen(file://fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://fopen15.tmpDir\fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir\fopen_variation15.tmp in %s on line %d
Warning: fopen(file://fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://./fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://./fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://.\fopen15.tmpDir\fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://.\fopen15.tmpDir\fopen_variation15.tmp in %s on line %d
Warning: fopen(file://.\fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://.\fopen15.tmpDir\fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://.\fopen15.tmpDir\fopen_variation15.tmp in %s on line %d
Warning: fopen(file://.\fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
--- WRITE: file://%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
--- READ: file://%s/fopen15.tmpDir\fopen_variation15.tmp ---
test passed
--- WRITE: file://%s/fopen15.tmpDir\fopen_variation15.tmp ---
test passed
--- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
--- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
--- READ: file://../fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://../fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://..\fopen15.tmpDir\fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://..\fopen15.tmpDir\fopen_variation15.tmp in %s on line %d
Warning: fopen(file://..\fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://..\fopen15.tmpDir\fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://..\fopen15.tmpDir\fopen_variation15.tmp in %s on line %d
Warning: fopen(file://..\fopen15.tmpDir\fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
--- WRITE: file://%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
--- READ: file://%s/fopen15.tmpDir\fopen_variation15.tmp ---
test passed
--- WRITE: file://%s/fopen15.tmpDir\fopen_variation15.tmp ---
test passed
--- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
--- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
===DONE===

View File

@ -0,0 +1,140 @@
--TEST--
Test fopen() function : variation: file uri, use include path = true
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Not for Windows");
?>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : variation ***\n";
// fopen with interesting windows paths.
$includePathDir = getcwd().'/fopen15.includeDir';
$testDir = 'fopen15.tmpDir';
$absTestDir = getcwd().'/'.$testDir;
$file = "fopen_variation15.tmp";
$absFile = $absTestDir.'/'.$file;
mkdir($testDir);
mkdir($includePathDir);
set_include_path($includePathDir);
$files = array("file://$testDir/$file",
"file://./$testDir/$file",
"file://$absTestDir/$file"
);
runtest($files);
chdir($testDir);
$files = array("file://../$testDir/$file",
"file://$absTestDir/$file"
);
runtest($files);
chdir("..");
rmdir($testDir);
rmdir($includePathDir);
function runtest($fileURIs) {
global $absFile;
$iteration = 0;
foreach($fileURIs as $fileURI) {
echo "--- READ: $fileURI ---\n";
$readData = "read:$iteration";
$writeData = "write:$iteration";
// create the file and test read
$h = fopen($absFile, 'w');
fwrite($h, $readData);
fclose($h);
$h = fopen($fileURI, 'r', true);
if ($h !== false) {
if (fread($h, 4096) != $readData) {
echo "contents not correct\n";
}
else {
echo "test passed\n";
}
fclose($h);
}
unlink($absFile);
echo "--- WRITE: $fileURI ---\n";
// create the file to test write
$h = fopen($fileURI, 'w', true);
if ($h !== false) {
fwrite($h, $writeData);
fclose($h);
$h = fopen($absFile, 'r');
if ($h !== false) {
if (fread($h, 4096) != $writeData) {
echo "contents not correct\n";
}
else {
echo "test passed\n";
}
fclose($h);
}
unlink($absFile);
}
}
}
?>
===DONE===
--EXPECTF--
*** Testing fopen() : variation ***
--- READ: file://fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file://./fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://./fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
--- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
--- READ: file://../fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- WRITE: file://../fopen15.tmpDir/fopen_variation15.tmp ---
Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d
Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d
--- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
--- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp ---
test passed
===DONE===

View File

@ -0,0 +1,74 @@
--TEST--
Test fopen() function : variation: use include path create and read a file (relative)
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--XFAIL--
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
require_once('fopen_include_path.inc');
echo "*** Testing fopen() : variation ***\n";
$thisTestDir = "fopenVariation16.dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$newpath = create_include_path();
set_include_path($newpath);
runtest();
$newpath = generate_next_path();
set_include_path($newpath);
runtest();
teardown_include_path();
restore_include_path();
chdir("..");
rmdir($thisTestDir);
function runtest() {
global $dir1;
$extraDir = "extraDir";
mkdir($dir1.'/'.$extraDir);
$tmpfile = $extraDir.'/fopen_variation16.tmp';
$h = fopen($tmpfile, "w+", true);
fwrite($h, "This is the test file");
fclose($h);
$h = fopen($dir1.'/'.$tmpfile, "r");
if ($h === false) {
echo "Not created in dir1\n";
}
else {
echo "created in dir1\n";
fclose($h);
}
$h = fopen($tmpfile, "r", true);
if ($h === false) {
echo "could not find file for reading\n";
}
else {
echo "found file again in dir1\n";
fclose($h);
}
unlink($dir1.'/'.$tmpfile);
rmdir($dir1.'/'.$extraDir);
}
?>
===DONE===
--EXPECT--
*** Testing fopen() : variation ***
created in dir1
found file again in dir1
created in dir1
found file again in dir1
===DONE===

View File

@ -0,0 +1,74 @@
--TEST--
Test fopen() function : variation: use include path create and read a file (relative)
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--XFAIL--
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
require_once('fopen_include_path.inc');
echo "*** Testing fopen() : variation ***\n";
$thisTestDir = "fopenVariation17.dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$newpath = create_include_path();
set_include_path($newpath);
runtest();
$newpath = generate_next_path();
set_include_path($newpath);
runtest();
teardown_include_path();
restore_include_path();
chdir("..");
rmdir($thisTestDir);
function runtest() {
global $dir1;
$extraDir = "extraDir";
mkdir($dir1.'/'.$extraDir);
$tmpfile = $extraDir.'/fopen_variation17.tmp';
$h = fopen($tmpfile, "w+", true);
fwrite($h, "This is the test file");
fclose($h);
$h = fopen($dir1.'/'.$tmpfile, "r");
if ($h === false) {
echo "Not created in dir1\n";
}
else {
echo "created in dir1\n";
fclose($h);
}
$h = fopen($tmpfile, "r", true);
if ($h === false) {
echo "could not find file for reading\n";
}
else {
echo "found file again in dir1\n";
fclose($h);
}
unlink($dir1.'/'.$tmpfile);
rmdir($dir1.'/'.$extraDir);
}
?>
===DONE===
--EXPECT--
*** Testing fopen() : variation ***
created in dir1
found file again in dir1
created in dir1
found file again in dir1
===DONE===

View File

@ -0,0 +1,112 @@
--TEST--
Test fopen() function : variation: test opening linked files
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Not for Windows");
?>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
$tmpDir = 'fopenVar19.Dir';
$realFilename = __FILE__.'.real';
$sortFilename = __FILE__.'.soft';
$hardFilename = __FILE__.'.hard';
$linkOfLink = __FILE__.'.soft2';
echo "*** Testing fopen() : variation ***\n";
// start the test
mkdir($tmpDir);
chdir($tmpDir);
$h = fopen($realFilename, "w");
fwrite($h, "Hello World");
fclose($h);
symlink($realFilename, $sortFilename);
symlink($sortFilename, $linkOfLink);
link($realFilename, $hardFilename);
echo "*** testing reading of links ***\n";
echo "soft link:";
readFile2($sortFilename);
echo "hard link:";
readFile2($hardFilename);
echo "link of link:";
readFile2($linkOfLink);
echo "*** test appending to links ***\n";
echo "soft link:";
appendFile($sortFilename);
echo "hard link:";
appendFile($hardFilename);
echo "link of link:";
appendFile($linkOfLink);
echo "*** test overwriting links ***\n";
echo "soft link:";
writeFile($sortFilename);
echo "hard link:";
writeFile($hardFilename);
echo "link of link:";
writeFile($linkOfLink);
unlink($linkOfLink);
unlink($sortFilename);
unlink($hardFilename);
unlink($realFilename);
chdir("..");
rmdir($tmpDir);
function readFile2($file) {
$h = fopen($file, 'r');
fpassthru($h);
fclose($h);
echo "\n";
}
function appendFile($file) {
$h = fopen($file, 'a+');
fwrite($h, ' again!');
fseek($h, 0);
fpassthru($h);
fclose($h);
echo "\n";
}
function writeFile($file) {
$h = fopen($file, 'w');
fwrite($h, 'Goodbye World');
fclose($h);
readFile2($file);
}
?>
===DONE===
--EXPECT--
*** Testing fopen() : variation ***
*** testing reading of links ***
soft link:Hello World
hard link:Hello World
link of link:Hello World
*** test appending to links ***
soft link:Hello World again!
hard link:Hello World again! again!
link of link:Hello World again! again! again!
*** test overwriting links ***
soft link:Goodbye World
hard link:Goodbye World
link of link:Goodbye World
===DONE===

View File

@ -0,0 +1,218 @@
--TEST--
Test fopen() function : usage variation different datatypes for use_include_path
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$filename = __FILE__;
$mode = 'r';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// string data
'string DQ' => "string",
'string SQ' => 'string',
'mixed case string' => "sTrInG",
'heredoc' => $heredoc,
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
);
// loop through each element of the array for use_include_path
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
$h = fopen($filename, $mode, $value);
if ($h !== false) {
echo "ok\n";
fclose($h);
}
else {
var_dump($h);
}
};
?>
===DONE===
--EXPECTF--
*** Testing fopen() : usage variation ***
--int 0--
ok
--int 1--
ok
--int 12345--
ok
--int -12345--
ok
--float 10.5--
ok
--float -10.5--
ok
--float 12.3456789000e10--
ok
--float -12.3456789000e10--
ok
--float .5--
ok
--empty array--
Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d)
bool(false)
--int indexed array--
Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d)
bool(false)
--associative array--
Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d)
bool(false)
--nested arrays--
Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d)
bool(false)
--uppercase NULL--
ok
--lowercase null--
ok
--lowercase true--
ok
--lowercase false--
ok
--uppercase TRUE--
ok
--uppercase FALSE--
ok
--empty string DQ--
ok
--empty string SQ--
ok
--string DQ--
ok
--string SQ--
ok
--mixed case string--
ok
--heredoc--
ok
--instance of classWithToString--
Error: 2 - fopen() expects parameter 3 to be boolean, object given, %s(%d)
bool(false)
--instance of classWithoutToString--
Error: 2 - fopen() expects parameter 3 to be boolean, object given, %s(%d)
bool(false)
--undefined var--
ok
--unset var--
ok
===DONE===

View File

@ -0,0 +1,251 @@
--TEST--
Test fopen() function : usage variation different datatypes for stream context
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$filename = __FILE__;
$mode = 'r';
$use_include_path = false;
$fileresource = fopen($filename, $mode);
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// string data
'string DQ' => "string",
'string SQ' => 'string',
'mixed case string' => "sTrInG",
'heredoc' => $heredoc,
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
//file resource
'file resource' => $fileresource
);
// loop through each element of the array for context
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
$h = fopen($filename, $mode, false, $value);
if ($h !== false) {
echo "ok\n";
fclose($h);
}
else {
var_dump($h);
}
};
fclose($fileresource);
?>
===DONE===
--EXPECTF--
*** Testing fopen() : usage variation ***
--int 0--
Error: 2 - fopen() expects parameter 4 to be resource, integer given, %s(%d)
bool(false)
--int 1--
Error: 2 - fopen() expects parameter 4 to be resource, integer given, %s(%d)
bool(false)
--int 12345--
Error: 2 - fopen() expects parameter 4 to be resource, integer given, %s(%d)
bool(false)
--int -12345--
Error: 2 - fopen() expects parameter 4 to be resource, integer given, %s(%d)
bool(false)
--float 10.5--
Error: 2 - fopen() expects parameter 4 to be resource, double given, %s(%d)
bool(false)
--float -10.5--
Error: 2 - fopen() expects parameter 4 to be resource, double given, %s(%d)
bool(false)
--float 12.3456789000e10--
Error: 2 - fopen() expects parameter 4 to be resource, double given, %s(%d)
bool(false)
--float -12.3456789000e10--
Error: 2 - fopen() expects parameter 4 to be resource, double given, %s(%d)
bool(false)
--float .5--
Error: 2 - fopen() expects parameter 4 to be resource, double given, %s(%d)
bool(false)
--empty array--
Error: 2 - fopen() expects parameter 4 to be resource, array given, %s(%d)
bool(false)
--int indexed array--
Error: 2 - fopen() expects parameter 4 to be resource, array given, %s(%d)
bool(false)
--associative array--
Error: 2 - fopen() expects parameter 4 to be resource, array given, %s(%d)
bool(false)
--nested arrays--
Error: 2 - fopen() expects parameter 4 to be resource, array given, %s(%d)
bool(false)
--uppercase NULL--
Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d)
bool(false)
--lowercase null--
Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d)
bool(false)
--lowercase true--
Error: 2 - fopen() expects parameter 4 to be resource, boolean given, %s(%d)
bool(false)
--lowercase false--
Error: 2 - fopen() expects parameter 4 to be resource, boolean given, %s(%d)
bool(false)
--uppercase TRUE--
Error: 2 - fopen() expects parameter 4 to be resource, boolean given, %s(%d)
bool(false)
--uppercase FALSE--
Error: 2 - fopen() expects parameter 4 to be resource, boolean given, %s(%d)
bool(false)
--empty string DQ--
Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d)
bool(false)
--empty string SQ--
Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d)
bool(false)
--string DQ--
Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d)
bool(false)
--string SQ--
Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d)
bool(false)
--mixed case string--
Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d)
bool(false)
--heredoc--
Error: 2 - fopen() expects parameter 4 to be resource, Unicode string given, %s(%d)
bool(false)
--instance of classWithToString--
Error: 2 - fopen() expects parameter 4 to be resource, object given, %s(%d)
bool(false)
--instance of classWithoutToString--
Error: 2 - fopen() expects parameter 4 to be resource, object given, %s(%d)
bool(false)
--undefined var--
Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d)
bool(false)
--unset var--
Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d)
bool(false)
--file resource--
Error: 2 - fopen(): supplied resource is not a valid Stream-Context resource, %s(%d)
ok
===DONE===

View File

@ -0,0 +1,173 @@
--TEST--
Test fopen() function : variation: use include path and stream context (absolute directories in path)
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : variation ***\n";
//create the include directory structure
$thisTestDir = "fopenVariation5.dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$workingDir = "workdir";
$filename = "afile.txt";
$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);
//define the files to go into these directories, create one in dir2
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();
// remove the directory structure
chdir($baseDir);
rmdir($workingDir);
foreach($newdirs as $newdir) {
rmdir($newdir);
}
chdir("..");
rmdir($thisTestDir);
function test_fopen($mode) {
global $scriptFile, $secondFile, $firstFile, $filename;
// create a file in the middle directory
$h = fopen($secondFile, "w");
fwrite($h, "in dir2");
fclose($h);
echo "\n** testing with mode=$mode **\n";
// should read dir2 file
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
//create a file in dir1
$h = fopen($firstFile, "w");
fwrite($h, "in dir1");
fclose($h);
//should now read dir1 file
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
// create a file in working directory
$h = fopen($filename, "w");
fwrite($h, "in working dir");
fclose($h);
//should still read dir1 file
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
unlink($firstFile);
unlink($secondFile);
//should fail to read the file
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
// create a file in the script directory
$h = fopen($scriptFile, "w");
fwrite($h, "in script dir");
fclose($h);
//should read the file in script dir
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
//cleanup
unlink($filename);
unlink($scriptFile);
}
?>
===DONE===
--EXPECTF--
*** Testing fopen() : variation ***
--- testing include path ---
** testing with mode=r **
in dir2
in dir1
in dir1
Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
in script dir
** testing with mode=r+ **
in dir2
in dir1
in dir1
Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
in script dir
** testing with mode=rt **
in dir2
in dir1
in dir1
Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
in script dir
===DONE===

View File

@ -0,0 +1,46 @@
--TEST--
Test fopen() function : variation: use include path and stream context relative/absolute file
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : variation ***\n";
$absfile = __FILE__.'.tmp';
$relfile = "fopen_variation6.tmp";
$h = fopen($absfile, "w");
fwrite($h, "This is an absolute file");
fclose($h);
$h = fopen($relfile, "w");
fwrite($h, "This is a relative file");
fclose($h);
$ctx = stream_context_create();
$h = fopen($absfile, "r", true, $ctx);
fpassthru($h);
fclose($h);
echo "\n";
$h = fopen($relfile, "r", true, $ctx);
fpassthru($h);
fclose($h);
echo "\n";
unlink($absfile);
unlink($relfile);
?>
===DONE===
--EXPECTF--
*** Testing fopen() : variation ***
This is an absolute file
This is a relative file
===DONE===

View File

@ -0,0 +1,70 @@
--TEST--
Test fopen() function : variation: use include path create a file (relative)
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
require_once('fopen_include_path.inc');
echo "*** Testing fopen() : variation ***\n";
$thisTestDir = "fopenVariation7.dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$newpath = create_include_path();
set_include_path($newpath);
runtest();
$newpath = generate_next_path();
set_include_path($newpath);
runtest();
teardown_include_path();
restore_include_path();
chdir("..");
rmdir($thisTestDir);
function runtest() {
global $dir1;
$tmpfile = 'fopen_variation7.tmp';
$h = fopen($tmpfile, "w", true);
fwrite($h, "This is the test file");
fclose($h);
$h = @fopen($tmpfile, "r");
if ($h === false) {
echo "Not created in working dir\n";
}
else {
echo "created in working dir\n";
fclose($h);
unlink($tmpfile);
}
$h = fopen($dir1.'/'.$tmpfile, "r");
if ($h === false) {
echo "Not created in dir1\n";
}
else {
echo "created in dir1\n";
fclose($h);
unlink($dir1.'/'.$tmpfile);
}
}
?>
===DONE===
--EXPECT--
*** Testing fopen() : variation ***
Not created in working dir
created in dir1
Not created in working dir
created in dir1
===DONE===

View File

@ -0,0 +1,172 @@
--TEST--
Test fopen() function : variation: use include path and stream context (relative directories in path)
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
echo "*** Testing fopen() : variation ***\n";
$thisTestDir = "fopenVariation8.dir";
mkdir($thisTestDir);
chdir($thisTestDir);
//create the include directory structure
$workingDir = "workdir";
$filename = "afile.txt";
$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 .= '../'.$newdir.$pathSep;
}
mkdir($workingDir);
chdir($workingDir);
//define the files to go into these directories, create one in dir2
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();
// remove the directory structure
chdir($baseDir);
rmdir($workingDir);
foreach($newdirs as $newdir) {
rmdir($newdir);
}
chdir("..");
rmdir($thisTestDir);
function test_fopen($mode) {
global $scriptFile, $secondFile, $firstFile, $filename;
// create a file in the middle directory
$h = fopen($secondFile, "w");
fwrite($h, "in dir2");
fclose($h);
echo "\n** testing with mode=$mode **\n";
// should read dir2 file
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
//create a file in dir1
$h = fopen($firstFile, "w");
fwrite($h, "in dir1");
fclose($h);
//should now read dir1 file
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
// create a file in working directory
$h = fopen($filename, "w");
fwrite($h, "in working dir");
fclose($h);
//should still read dir1 file
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
unlink($firstFile);
unlink($secondFile);
//should fail to read the file
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
// create a file in the script directory
$h = fopen($scriptFile, "w");
fwrite($h, "in script dir");
fclose($h);
//should read the file in script dir
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
echo "\n";
//cleanup
unlink($filename);
unlink($scriptFile);
}
?>
===DONE===
--EXPECTF--
*** Testing fopen() : variation ***
--- testing include path ---
** testing with mode=r **
in dir2
in dir1
in dir1
Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
in script dir
** testing with mode=r+ **
in dir2
in dir1
in dir1
Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
in script dir
** testing with mode=rt **
in dir2
in dir1
in dir1
Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
in script dir
===DONE===

View File

@ -0,0 +1,69 @@
--TEST--
Test fopen() function : variation: use include path and stream context create a file, relative path
--XFAIL--
Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/
require_once('fopen_include_path.inc');
echo "*** Testing fopen() : variation ***\n";
$thisTestDir = "fopenVariation9.dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$newpath = relative_include_path();
set_include_path($newpath);
runtest();
$newpath = generate_next_rel_path();
set_include_path($newpath);
runtest();
teardown_relative_path();
restore_include_path();
chdir("..");
rmdir($thisTestDir);
function runtest() {
$tmpfile = 'fopen_variation7.tmp';
$h = fopen($tmpfile, "w", true);
fwrite($h, "This is the test file");
fclose($h);
$h = @fopen($tmpfile, "r");
if ($h === false) {
echo "Not created in working dir\n";
}
else {
echo "created in working dir\n";
fclose($h);
unlink($tmpfile);
}
$h = fopen('dir1/'.$tmpfile, "r");
if ($h === false) {
echo "Not created in dir1\n";
}
else {
echo "created in dir1\n";
fclose($h);
unlink('dir1/'.$tmpfile);
}
}
?>
===DONE===
--EXPECT--
*** Testing fopen() : variation ***
Not created in working dir
created in dir1
Not created in working dir
created in dir1
===DONE===

Some files were not shown because too many files have changed in this diff Show More