New tests for file system handling functions

This commit is contained in:
Raghubansh Kumar 2007-06-18 19:45:53 +00:00
parent 4c61a3f27e
commit 210f091022
8 changed files with 1002 additions and 0 deletions

View File

@ -0,0 +1,38 @@
--TEST--
Test filesize() function: basic functionaity
--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 size of files and directories with filesize() ***\n";
$file_path = dirname(__FILE__);
var_dump( filesize(__FILE__) );
var_dump( filesize(".") );
/* Empty file */
$file_name = $file_path."/filesize_basic.tmp";
$file_handle = fopen($file_name, "w");
fclose($file_handle);
var_dump( filesize($file_name) );
echo "*** Done ***\n";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
$file_name = $file_path."/filesize_basic.tmp";
unlink($file_name);
?>
--EXPECTF--
*** Testing size of files and directories with filesize() ***
int(%d)
int(%d)
int(0)
*** Done ***

View File

@ -0,0 +1,40 @@
--TEST--
Test filesize() function: error conditions
--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(): error conditions ***";
/* Non-existing file or dir */
var_dump( filesize("/no/such/file") );
var_dump( filesize("/no/such/dir") );
/* No.of arguments less than expected */
var_dump( filesize() );
/* No.of arguments greater than expected */
var_dump( filesize(__FILE__, 2000) );
echo "\n";
echo "*** Done ***\n";
?>
--EXPECTF--
*** Testing filesize(): error conditions ***
Warning: filesize(): stat failed for /no/such/file in %s on line %d
bool(false)
Warning: filesize(): stat failed for /no/such/dir in %s on line %d
bool(false)
Warning: Wrong parameter count for filesize() in %s on line %d
NULL
Warning: Wrong parameter count for filesize() in %s on line %d
NULL
*** Done ***

View File

@ -0,0 +1,640 @@
--TEST--
Test fread() function : basic functionality
--FILE--
<?php
/*
Prototype: string fread ( resource $handle [, int $length] );
Description: reads up to length bytes from the file pointer referenced by handle.
Reading stops when up to length bytes have been read, EOF (end of file) is
reached, (for network streams) when a packet becomes available, or (after
opening userspace stream) when 8192 bytes have been read whichever comes first.
*/
// include the file.inc for common functions for test
include ("file.inc");
/* Function : function check_size(string $data, int $expect_size)
Description : Check the length of the data, and compare the size with $expect_size
$data : Text data.
$expect_size : Expected data length
*/
function check_size($data, $expect_size) {
$size=strlen($data);
if ( $size == $expect_size)
echo "OK\n";
else
echo "Error: Expected: $expect_size, Actual: $size";
}
echo "*** Testing fread() basic operations ***\n";
/*
test fread with file opened in "r" and "rb" mode only
Content with numeric and strings with it
*/
$file_modes = array( "r", "rb", "rt", "r+", "r+b", "r+t");
$file_content_types = array("numeric","text","text_with_new_line","alphanumeric");
foreach($file_content_types as $file_content_type) {
echo "\n-- Testing fread) with file having data of type ". $file_content_type ." --\n";
/* create files with $file_content_type */
create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "fread_basic");
$filename = dirname(__FILE__)."/fread_basic1.tmp"; // this is name of the file created by create_files()
/* open the file using $files_modes and perform fread() on it */
for($inner_loop_counter = 0;
$inner_loop_counter < count($file_modes);
$inner_loop_counter++) {
echo "-- File opened in mode ".$file_modes[$inner_loop_counter]." --\n";
$file_handle = fopen($filename, $file_modes[$inner_loop_counter]);
if (!$file_handle) {
echo "Error: failed to fopen() file: $filename!";
exit();
}
/* read file by giving the acutal length, check the length and content by calculating the
hash using md5() function
*/
/* Reading 1024 bytes from file, expecting 1024 bytes */ ;
var_dump(ftell($file_handle));
var_dump( feof($file_handle) );
echo "Reading 1024 bytes from file, expecting 1024 bytes ... ";
$data_from_file=fread($file_handle, 1024);
check_size($data_from_file,1024);
var_dump(ftell($file_handle));
var_dump( feof($file_handle) );
var_dump( md5($data_from_file) ); // calculate the hash and dump it
/* read file by giving size more than its size */
var_dump(rewind($file_handle));
var_dump(ftell($file_handle));
var_dump( feof($file_handle) );
/*reading 1030 bytes from file, expecting 1024 bytes */ ;
echo "Reading 1030 bytes from file, expecting 1024 bytes ... ";
$data_from_file=fread($file_handle, 1030);// request for 6 bytes more than its size
check_size($data_from_file,1024);
var_dump(ftell($file_handle));
var_dump( feof($file_handle) );
var_dump( md5($data_from_file) ); // calculate the hash and dump it
// reading 1000 bytes within the file max size
var_dump(rewind($file_handle));
var_dump(ftell($file_handle));
var_dump( feof($file_handle) );
/*reading 1000 bytes from file, expecting 1000 bytes */ ;
echo "Reading 1000 bytes from file, expecting 1000 bytes ... ";
$data_from_file=fread($file_handle, 1000);// request for 24 bytes less than its size
check_size($data_from_file,1000);
var_dump(ftell($file_handle));
var_dump( feof($file_handle) );
var_dump( md5($data_from_file) ); // calculate the hash and dump it
var_dump(fclose($file_handle)); // now close the file
} // end of inner for loop
// delete the file created
delete_file($filename); // delete file with name
} // end of outer foreach loop
echo "Done\n";
?>
--EXPECTF--
*** Testing fread() basic operations ***
-- Testing fread) with file having data of type numeric --
-- File opened in mode r --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "4501f99f2b79d0345f26f1394aca58a3"
bool(true)
-- File opened in mode rb --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "4501f99f2b79d0345f26f1394aca58a3"
bool(true)
-- File opened in mode rt --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "4501f99f2b79d0345f26f1394aca58a3"
bool(true)
-- File opened in mode r+ --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "4501f99f2b79d0345f26f1394aca58a3"
bool(true)
-- File opened in mode r+b --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "4501f99f2b79d0345f26f1394aca58a3"
bool(true)
-- File opened in mode r+t --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "950b7457d1deb6332f2fc5d42f3129d6"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "4501f99f2b79d0345f26f1394aca58a3"
bool(true)
-- Testing fread) with file having data of type text --
-- File opened in mode r --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "2ec76a59f8c44b8f8a0f5139f61bb1bd"
bool(true)
-- File opened in mode rb --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "2ec76a59f8c44b8f8a0f5139f61bb1bd"
bool(true)
-- File opened in mode rt --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "2ec76a59f8c44b8f8a0f5139f61bb1bd"
bool(true)
-- File opened in mode r+ --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "2ec76a59f8c44b8f8a0f5139f61bb1bd"
bool(true)
-- File opened in mode r+b --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "2ec76a59f8c44b8f8a0f5139f61bb1bd"
bool(true)
-- File opened in mode r+t --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "e486000c4c8452774f746a27658d87fa"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "2ec76a59f8c44b8f8a0f5139f61bb1bd"
bool(true)
-- Testing fread) with file having data of type text_with_new_line --
-- File opened in mode r --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a148fa8110bbac875d84fc9d7056c0a1"
bool(true)
-- File opened in mode rb --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a148fa8110bbac875d84fc9d7056c0a1"
bool(true)
-- File opened in mode rt --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a148fa8110bbac875d84fc9d7056c0a1"
bool(true)
-- File opened in mode r+ --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a148fa8110bbac875d84fc9d7056c0a1"
bool(true)
-- File opened in mode r+b --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a148fa8110bbac875d84fc9d7056c0a1"
bool(true)
-- File opened in mode r+t --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "b09c8026a64a88d36d4c2f17983964bb"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a148fa8110bbac875d84fc9d7056c0a1"
bool(true)
-- Testing fread) with file having data of type alphanumeric --
-- File opened in mode r --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a49d752f980184c7f44568e930f89c72"
bool(true)
-- File opened in mode rb --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a49d752f980184c7f44568e930f89c72"
bool(true)
-- File opened in mode rt --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a49d752f980184c7f44568e930f89c72"
bool(true)
-- File opened in mode r+ --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a49d752f980184c7f44568e930f89c72"
bool(true)
-- File opened in mode r+b --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a49d752f980184c7f44568e930f89c72"
bool(true)
-- File opened in mode r+t --
int(0)
bool(false)
Reading 1024 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(false)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1030 bytes from file, expecting 1024 bytes ... OK
int(1024)
bool(true)
string(32) "3fabd48d8eaa65c14e0d93d6880c560c"
bool(true)
int(0)
bool(false)
Reading 1000 bytes from file, expecting 1000 bytes ... OK
int(1000)
bool(false)
string(32) "a49d752f980184c7f44568e930f89c72"
bool(true)
Done

View File

@ -0,0 +1,114 @@
--TEST--
Test fread() function : error conditions
--FILE--
<?php
/*
Prototype: string fread ( resource $handle [, int $length] );
Description: reads up to length bytes from the file pointer referenced by handle.
Reading stops when up to length bytes have been read, EOF (end of file) is
reached, (for network streams) when a packet becomes available, or (after
opening userspace stream) when 8192 bytes have been read whichever comes first.
*/
echo "*** Testing error conditions ***\n";
$filename = __FILE__;
$file_handle = fopen($filename, "r");
// zero argument
echo "-- Testing fread() with zero argument --\n";
var_dump( fread() );
// more than expected no. of args
echo "-- Testing fread() with more than expected number of arguments --\n";
var_dump( fread($file_handle, 10, $file_handle) );
// invalid length argument
echo "-- Testing fread() with invalid length arguments --\n";
$len = 0;
var_dump( fread($file_handle, $len) );
$len = -10;
var_dump( fread($file_handle, $len) );
// test invalid arguments : non-resources
echo "-- Testing fread() with invalid arguments --\n";
$invalid_args = array (
"string",
10,
10.5,
true,
array(1,2,3),
new stdclass,
);
/* loop to test fread() with different invalid type of args */
for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
echo "-- Iteration $loop_counter --\n";
var_dump( fread($invalid_args[$loop_counter - 1], 10) );
}
// fwrite() on a file handle which is already closed
echo "-- Testing fwrite() with closed/unset file handle --\n";
fclose($file_handle);
var_dump( fread($file_handle,$file_content_type) );
// fwrite on a file handle which is unset
$fp = fopen($filename, "r");
unset($fp); //unset file handle
var_dump( fread(@$fp,10) );
var_dump( fclose(@$fp) );
echo "Done\n";
--EXPECTF--
*** Testing error conditions ***
-- Testing fread() with zero argument --
Warning: Wrong parameter count for fread() in %s on line %d
NULL
-- Testing fread() with more than expected number of arguments --
Warning: Wrong parameter count for fread() in %s on line %d
NULL
-- Testing fread() with invalid length arguments --
Warning: fread(): Length parameter must be greater than 0 in %s on line %d
bool(false)
Warning: fread(): Length parameter must be greater than 0 in %s on line %d
bool(false)
-- Testing fread() with invalid arguments --
-- Iteration 1 --
Warning: fread(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Iteration 2 --
Warning: fread(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Iteration 3 --
Warning: fread(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Iteration 4 --
Warning: fread(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Iteration 5 --
Warning: fread(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Iteration 6 --
Warning: fread(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
-- Testing fwrite() with closed/unset file handle --
Notice: Undefined variable: file_content_type in %s on line %d
Warning: fread(): 5 is not a valid stream resource in %s on line %d
bool(false)
Warning: fread(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
Done

View File

@ -0,0 +1,43 @@
--TEST--
Test is_dir() function: basic functionality
--FILE--
<?php
/* Prototype: bool is_dir ( string $filename );
Description: Tells whether the filename is a regular file
Returns TRUE if the filename exists and is a regular file
*/
echo "*** Testing is_dir(): basic functionality ***\n";
$file_path = dirname(__FILE__);
var_dump( is_dir($file_path) );
clearstatcache();
var_dump( is_dir(".") );
var_dump( is_dir(__FILE__) ); // expected: bool(false)
$dir_name = $file_path."/is_dir_basic";
mkdir($dir_name);
var_dump( is_dir($dir_name) );
echo "*** Testing is_dir() for its return value type ***\n";
var_dump( is_bool( is_dir($file_path) ) );
var_dump( is_bool( is_dir("/no/such/dir") ) );
echo "*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
$dir_name = $file_path."/is_dir_basic";
rmdir($dir_name);
?>
--EXPECTF--
*** Testing is_dir(): basic functionality ***
bool(true)
bool(true)
bool(false)
bool(true)
*** Testing is_dir() for its return value type ***
bool(true)
bool(true)
*** Done ***

View File

@ -0,0 +1,35 @@
--TEST--
Test is_dir() function: error conditions
--FILE--
<?php
/* Prototype: bool is_dir ( string $filename );
* Description: Tells whether the filename is a regular file
* Returns TRUE if the filename exists and is a regular file
*/
echo "\n*** Testing is_dir() error conditions ***";
var_dump( is_dir() ); // Zero No. of args
$dir_name = dirname(__FILE__)."/is_dir_error";
mkdir($dir_name);
var_dump( is_dir($dir_name, "is_dir_error1") ); // args > expected no.of args
/* Non-existing dir */
var_dump( is_dir("/no/such/dir") );
echo "*** Done ***";
?>
--CLEAN--
<?php
rmdir(dirname(__FILE__)."/is_dir_error");
?>
--EXPECTF--
*** Testing is_dir() error conditions ***
Warning: Wrong parameter count for is_dir() in %s on line %d
NULL
Warning: Wrong parameter count for is_dir() in %s on line %d
NULL
bool(false)
*** Done ***

View File

@ -0,0 +1,48 @@
--TEST--
Test is_file() function: basic functionality
--FILE--
<?php
/* Prototype: bool is_file ( string $filename );
Description: Tells whether the filename is a regular file
Returns TRUE if the filename exists and is a regular file
*/
echo "*** Testing is_file(): basic functionality ***\n";
/* Checking with current file */
var_dump( is_file(__FILE__) );
/* Checking with (current) dir */
var_dump( is_file(dirname(__FILE__)) );
$file_path = dirname(__FILE__);
$file_name = $file_path."/is_file_basic.tmp";
/* With non-existing file */
var_dump( is_file($file_name) );
/* With existing file */
fclose( fopen($file_name, "w") );
var_dump( is_file($file_name) );
echo "*** Testing is_file() for its return value type ***\n";
var_dump( is_bool( is_file(__FILE__) ) );
var_dump( is_bool( is_file("/no/such/file") ) );
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
$file_name = $file_path."/is_file_basic.tmp";
unlink($file_name);
?>
--EXPECTF--
*** Testing is_file(): basic functionality ***
bool(true)
bool(false)
bool(false)
bool(true)
*** Testing is_file() for its return value type ***
bool(true)
bool(true)
*** Done ***

View File

@ -0,0 +1,44 @@
--TEST--
Test is_file() function: error conditions
--FILE--
<?php
/* Prototype: bool is_file ( string $filename );
Description: Tells whether the filename is a regular file
Returns TRUE if the filename exists and is a regular file
*/
echo "\n*** Testing is_file() error conditions ***";
$file_path = dirname(__FILE__);
var_dump( is_file() ); // Zero No. of args
/* no.of args > expected no.of args */
$file_handle = fopen($file_path."/is_file_error.tmp", "w");
var_dump( is_file( $file_path."/is_file_error.tmp", $file_path."/is_file_error1.tmp") );
/* Non-existing file */
var_dump( is_file($file_path."/is_file_error1.tmp") );
/* Passing resource as an argument */
var_dump( is_file($file_handle) );
fclose($file_handle);
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
unlink($file_path."/is_file_error.tmp");
?>
--EXPECTF--
*** Testing is_file() error conditions ***
Warning: Wrong parameter count for is_file() in %s on line %d
NULL
Warning: Wrong parameter count for is_file() in %s on line %d
NULL
bool(false)
bool(false)
*** Done ***