diff options
author | Raghubansh Kumar <kraghuba@php.net> | 2007-06-21 21:12:18 +0000 |
---|---|---|
committer | Raghubansh Kumar <kraghuba@php.net> | 2007-06-21 21:12:18 +0000 |
commit | e647140a8267ec5c1daff26d76990d0289bf43b6 (patch) | |
tree | f7a52e7762fa89c3f39affc001bcc79586542118 | |
parent | 993b689a2e53bd360ac9cfeb30a0da0ceabd6b4c (diff) | |
download | php-git-e647140a8267ec5c1daff26d76990d0289bf43b6.tar.gz |
New tests for file system handling functions
-rw-r--r-- | ext/standard/tests/file/filesize_variation-win32.phpt | 223 | ||||
-rw-r--r-- | ext/standard/tests/file/filesize_variation.phpt | 220 | ||||
-rw-r--r-- | ext/standard/tests/file/lstat_stat_basic.phpt | 315 | ||||
-rw-r--r-- | ext/standard/tests/file/lstat_stat_error.phpt | 83 | ||||
-rw-r--r-- | ext/standard/tests/file/rename_variation-win32.phpt | 199 | ||||
-rw-r--r-- | ext/standard/tests/file/rename_variation.phpt | 311 | ||||
-rw-r--r-- | ext/standard/tests/file/stat_basic-win32.phpt | 191 | ||||
-rw-r--r-- | ext/standard/tests/file/stat_error-win32.phpt | 56 |
8 files changed, 1598 insertions, 0 deletions
diff --git a/ext/standard/tests/file/filesize_variation-win32.phpt b/ext/standard/tests/file/filesize_variation-win32.phpt new file mode 100644 index 0000000000..ed215c02cb --- /dev/null +++ b/ext/standard/tests/file/filesize_variation-win32.phpt @@ -0,0 +1,223 @@ +--TEST-- +Test filesize() function: usage variations +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip only valid for Windows'); +} +--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. +*/ + +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +echo "*** Testing filesize(): usage variations ***\n"; + +echo "*** Checking filesize() with different size of files ***\n"; +for($size = 1; $size <10000; $size = $size+1000) +{ + create_files($file_path, 1, "numeric", 0755, $size, "w", "filesize_variation"); + var_dump( filesize( $file_path."/filesize_variation1.tmp") ); + clearstatcache(); + delete_files($file_path, 1, "filesize_variation"); +} + +echo "\n*** Testing size of a dir, sub-dir and file with filesize() ***\n"; +echo "-- Creating a base dir, and checking its size --\n"; +mkdir( $file_path."/filesize_variation"); +var_dump( filesize( $file_path."/filesize_variation")); +clearstatcache(); + +echo "-- Creating a file inside base dir, and checking dir & file size --\n"; +create_files($file_path."/filesize_variation", 1, "numeric", 0755, 1, "w", "filesize_variation"); +var_dump( filesize( $file_path."/filesize_variation")); +clearstatcache(); +var_dump( filesize( $file_path."/filesize_variation/filesize_variation1.tmp")); +clearstatcache(); +delete_files($file_path."/filesize_variation", 1, "filesize_variation"); + +echo "-- Creating an empty sub-dir in base-dir, and checking size of base and sub dir --\n"; +mkdir( $file_path."/filesize_variation/filesize_variation_sub"); +var_dump( filesize( $file_path."/filesize_variation")); // size of base dir +clearstatcache(); +var_dump( filesize( $file_path."/filesize_variation/filesize_variation_sub")); // size of subdir +clearstatcache(); + +echo "-- Creating a file inside sub-dir, and checking size of base, subdir and file created --\n"; +// create only the file, as base and subdir is already created +$filename = $file_path."/filesize_variation/filesize_variation_sub/filesize_variation.tmp"; +$file_handle = fopen($filename, "w"); +fwrite($file_handle, str_repeat("Hello,World ", 1000) ); // create file of size 12000 bytes +fclose($file_handle); +// size of base dir +var_dump( filesize( $file_path."/filesize_variation")); +clearstatcache(); +// size of subdir +var_dump( filesize( $file_path."/filesize_variation/filesize_variation_sub")); +clearstatcache(); +// size of file inside subdir +var_dump( filesize( $file_path."/filesize_variation/filesize_variation_sub/filesize_variation.tmp")); +clearstatcache(); + +echo "-- Testing filesize() after truncating the file to a new length --\n"; +// truncate the file created earlier in subdir, the size of the file is 12000bytes +// truncate the same file, in the loop , each time with the decrement in size by 1200 bytes, +// until -1200bytes size +for($size = filesize($filename); $size>=-1200; $size-=1200) { + $file_handle = fopen($filename, "r+"); + var_dump( ftruncate($file_handle, $size) ); + fclose($file_handle); + var_dump( filesize($filename) ); + clearstatcache(); +} + +echo "-- Testing filesize() with the data of possible chars --\n"; +$filename2 = $file_path."/filesize_variation1.tmp"; +$string = "Test 2 test the filesize() fn, with data containing all the types like !@@##$%^&*():<>?|~+!;',.\][{}(special) chars, 12345(numeric) chars, and \n(newline char), \t(tab), \0, \r and so on........\0"; +echo "-- opening the file in 'w' mode and get the size --\n"; +$file_handle = fopen($filename2, "w"); +var_dump( strlen($string) ); //strlen of the string +fwrite($file_handle, $string); +fclose($file_handle); +var_dump( filesize($filename2) ); //size of the file = strlen of string +clearstatcache(); + +echo "-- opening the file in 'wt' mode and get the size --\n"; +$file_handle = fopen($filename2, "wt"); +var_dump( strlen($string) ); //strlen of the string = 191 bytes +fwrite($file_handle, $string); +fclose($file_handle); +/* '\n' treated as '\r\n' i.e two chars in 'wt' mode */ +var_dump( filesize($filename2) ); //size of the file = 192 bytes != strlen of string +clearstatcache(); + +echo "-- opening the file in 'a' mode, adding data and checking the file --\n"; +$file_handle = fopen($filename2, "a"); +fwrite($file_handle, "Hello, world"); +fclose($file_handle); +/* '\n' treated as '\r\n' i.e two chars in 'wt' mode */ +var_dump( filesize($filename2) ); //204 bytes +clearstatcache(); + +echo "-- opening the file in 'at' mode, adding data and checking the file --\n"; +$file_handle = fopen($filename2, "at"); +fwrite($file_handle, "Hello, world\n"); +fclose($file_handle); +/* '\n' treated as '\r\n' i.e two chars in 'wt' mode */ +var_dump( filesize($filename2) ); //218 bytes +clearstatcache(); + +echo "-- creating a hole and checking the size --\n"; +$file_handle = fopen($filename2, "a"); +var_dump( ftruncate($file_handle, 220) ); //creating 4 bytes of hole +fclose($file_handle); +var_dump( filesize($filename2) ); //220 bytes +clearstatcache(); + +echo "-- writing data after hole and checking the size --\n"; +$file_handle = fopen($filename2, "a"); +fwrite($file_handle, "Hello\0"); //wrting 6 bytes of data +fclose($file_handle); +var_dump( filesize($filename2) ); //226 bytes +clearstatcache(); + +echo "-- opening the existing file in write mode --\n"; +fclose( fopen($filename2, "w") ); +var_dump( filesize($filename2) ); //0 bytes +clearstatcache(); + +echo "-- with empty file --\n"; +$filename3 = dirname(__FILE__)."/filesize_variation_empty.tmp"; +fclose( fopen($filename3, "w") ); +var_dump( filesize($filename3) ); //0 bytes + +echo "*** Done ***\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +rmdir($file_path."/filesize_variation"); +unlink($file_path."/filesize_variation/filesize_variation_sub/filesize_variation.tmp"); +rmdir($file_path."/filesize_variation/filesize_variation_sub"); +rmdir($file_path."/filesize_variation"); +unlink($file_path."/filesize_variation1.tmp"); +unlink($file_path."/filesize_variation_empty.tmp"); +?> +--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) + +*** Testing size of a dir, sub-dir and file with filesize() *** +-- Creating a base dir, and checking its size -- +int(0) +-- Creating a file inside base dir, and checking dir & file size -- +int(0) +int(1024) +-- Creating an empty sub-dir in base-dir, and checking size of base and sub dir -- +int(0) +int(0) +-- Creating a file inside sub-dir, and checking size of base, subdir and file created -- +int(0) +int(0) +int(12000) +-- Testing filesize() after truncating the file to a new length -- +bool(true) +int(12000) +bool(true) +int(10800) +bool(true) +int(9600) +bool(true) +int(8400) +bool(true) +int(7200) +bool(true) +int(6000) +bool(true) +int(4800) +bool(true) +int(3600) +bool(true) +int(2400) +bool(true) +int(1200) +bool(true) +int(0) +bool(false) +int(0) +-- Testing filesize() with the data of possible chars -- +-- opening the file in 'w' mode and get the size -- +int(191) +int(191) +-- opening the file in 'wt' mode and get the size -- +int(191) +int(192) +-- opening the file in 'a' mode, adding data and checking the file -- +int(204) +-- opening the file in 'at' mode, adding data and checking the file -- +int(218) +-- creating a hole and checking the size -- +bool(true) +int(220) +-- writing data after hole and checking the size -- +int(226) +-- opening the existing file in write mode -- +int(0) +-- with empty file -- +int(0) +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/filesize_variation.phpt b/ext/standard/tests/file/filesize_variation.phpt new file mode 100644 index 0000000000..883bb8c8a5 --- /dev/null +++ b/ext/standard/tests/file/filesize_variation.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test filesize() function: usage variations +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip only valid for Linux'); +} +--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. +*/ + +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +echo "*** Testing filesize(): usage variations ***\n"; + +echo "*** Checking filesize() with different size of files ***\n"; +for($size = 1; $size <10000; $size = $size+1000) +{ + create_files($file_path, 1, "numeric", 0755, $size, "w", "filesize_variation"); + var_dump( filesize( $file_path."/filesize_variation1.tmp") ); + clearstatcache(); + delete_files($file_path, 1, "filesize_variation"); +} + +echo "\n*** Testing size of a dir, sub-dir and file with filesize() ***\n"; +echo "-- Creating a base dir, and checking its size --\n"; +mkdir( $file_path."/filesize_variation"); +var_dump( filesize( $file_path."/filesize_variation")); +clearstatcache(); + +echo "-- Creating a file inside base dir, and checking dir & file size --\n"; +create_files($file_path."/filesize_variation", 1, "numeric", 0755, 1, "w", "filesize_variation"); +var_dump( filesize( $file_path."/filesize_variation")); +clearstatcache(); +var_dump( filesize( $file_path."/filesize_variation/filesize_variation1.tmp")); +clearstatcache(); +delete_files($file_path."/filesize_variation", 1, "filesize_variation"); + +echo "-- Creating an empty sub-dir in base-dir, and checking size of base and sub dir --\n"; +mkdir( $file_path."/filesize_variation/filesize_variation_sub"); +var_dump( filesize( $file_path."/filesize_variation")); // size of base dir +clearstatcache(); +var_dump( filesize( $file_path."/filesize_variation/filesize_variation_sub")); // size of subdir +clearstatcache(); + +echo "-- Creating a file inside sub-dir, and checking size of base, subdir and file created --\n"; +// create only the file, as base and subdir is already created +$filename = $file_path."/filesize_variation/filesize_variation_sub/filesize_variation.tmp"; +$file_handle = fopen($filename, "w"); +fwrite($file_handle, str_repeat("Hello,World ", 1000) ); // create file of size 12000 bytes +fclose($file_handle); +// size of base dir +var_dump( filesize( $file_path."/filesize_variation")); +clearstatcache(); +// size of subdir +var_dump( filesize( $file_path."/filesize_variation/filesize_variation_sub")); +clearstatcache(); +// size of file inside subdir +var_dump( filesize( $file_path."/filesize_variation/filesize_variation_sub/filesize_variation.tmp")); +clearstatcache(); + +echo "-- Testing filesize() after truncating the file to a new length --\n"; +// truncate the file created earlier in subdir, the size of the file is 12000bytes +// truncate the same file, in the loop , each time with the decrement in size by 1200 bytes, +// until -1200bytes size +for($size = filesize($filename); $size>=-1200; $size-=1200) { + $file_handle = fopen($filename, "r+"); + var_dump( ftruncate($file_handle, $size) ); + fclose($file_handle); + var_dump( filesize($filename) ); + clearstatcache(); +} + +echo "-- Testing filesize() with the data of possible chars --\n"; +$filename2 = $file_path."/filesize_variation1.tmp"; +$string = "Test 2 test the filesize() fn, with data containing all the types like !@@##$%^&*():<>?|~+!;',.\][{}(special) chars, 12345(numeric) chars, and \n(newline char), \t(tab), \0, \r and so on........\0"; +echo "-- opening the file in 'w' mode and get the size --\n"; +$file_handle = fopen($filename2, "w"); +var_dump( strlen($string) ); //strlen of the string +fwrite($file_handle, $string); +fclose($file_handle); +var_dump( filesize($filename2) ); //size of the file = strlen of string +clearstatcache(); + +echo "-- opening the file in 'wt' mode and get the size --\n"; +$file_handle = fopen($filename2, "wt"); +var_dump( strlen($string) ); //strlen of the string = 191 bytes +fwrite($file_handle, $string); +fclose($file_handle); +var_dump( filesize($filename2) ); //size of the file = strlen of string = 191 bytes +clearstatcache(); + +echo "-- opening the file in 'a' mode, adding data and checking the file --\n"; +$file_handle = fopen($filename2, "a"); +fwrite($file_handle, "Hello, world"); +fclose($file_handle); +var_dump( filesize($filename2) ); //203 bytes +clearstatcache(); + +echo "-- opening the file in 'at' mode, adding data and checking the file --\n"; +$file_handle = fopen($filename2, "at"); +fwrite($file_handle, "Hello, world\n"); +fclose($file_handle); +var_dump( filesize($filename2) ); //216 bytes +clearstatcache(); + +echo "-- creating a hole and checking the size --\n"; +$file_handle = fopen($filename2, "a"); +var_dump( ftruncate($file_handle, 220) ); //creating 4 bytes of hole +fclose($file_handle); +var_dump( filesize($filename2) ); //220 bytes +clearstatcache(); + +echo "-- writing data after hole and checking the size --\n"; +$file_handle = fopen($filename2, "a"); +fwrite($file_handle, "Hello\0"); //wrting 6 bytes of data +fclose($file_handle); +var_dump( filesize($filename2) ); //226 bytes +clearstatcache(); + +echo "-- opening the existing file in write mode --\n"; +fclose( fopen($filename2, "w") ); +var_dump( filesize($filename2) ); //0 bytes +clearstatcache(); + +echo "-- with empty file --\n"; +$filename3 = dirname(__FILE__)."/filesize_variation_empty.tmp"; +fclose( fopen($filename3, "w") ); +var_dump( filesize($filename3) ); //0 bytes + +echo "*** Done ***\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +rmdir($file_path."/filesize_variation"); +unlink($file_path."/filesize_variation/filesize_variation_sub/filesize_variation.tmp"); +rmdir($file_path."/filesize_variation/filesize_variation_sub"); +rmdir($file_path."/filesize_variation"); +unlink($file_path."/filesize_variation1.tmp"); +unlink($file_path."/filesize_variation_empty.tmp"); +?> +--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) + +*** Testing size of a dir, sub-dir and file with filesize() *** +-- Creating a base dir, and checking its size -- +int(4096) +-- Creating a file inside base dir, and checking dir & file size -- +int(4096) +int(1024) +-- Creating an empty sub-dir in base-dir, and checking size of base and sub dir -- +int(4096) +int(4096) +-- Creating a file inside sub-dir, and checking size of base, subdir and file created -- +int(4096) +int(4096) +int(12000) +-- Testing filesize() after truncating the file to a new length -- +bool(true) +int(12000) +bool(true) +int(10800) +bool(true) +int(9600) +bool(true) +int(8400) +bool(true) +int(7200) +bool(true) +int(6000) +bool(true) +int(4800) +bool(true) +int(3600) +bool(true) +int(2400) +bool(true) +int(1200) +bool(true) +int(0) +bool(false) +int(0) +-- Testing filesize() with the data of possible chars -- +-- opening the file in 'w' mode and get the size -- +int(191) +int(191) +-- opening the file in 'wt' mode and get the size -- +int(191) +int(191) +-- opening the file in 'a' mode, adding data and checking the file -- +int(203) +-- opening the file in 'at' mode, adding data and checking the file -- +int(216) +-- creating a hole and checking the size -- +bool(true) +int(220) +-- writing data after hole and checking the size -- +int(226) +-- opening the existing file in write mode -- +int(0) +-- with empty file -- +int(0) +*** Done *** diff --git a/ext/standard/tests/file/lstat_stat_basic.phpt b/ext/standard/tests/file/lstat_stat_basic.phpt new file mode 100644 index 0000000000..aa00cf4c4b --- /dev/null +++ b/ext/standard/tests/file/lstat_stat_basic.phpt @@ -0,0 +1,315 @@ +--TEST-- +Test lstat() & stat() functions: basic functionality +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. lstat() not available on Windows'); +} +?> +--FILE-- +<?php +/* Prototype: array lstat ( string $filename ); + Description: Gives information about a file or symbolic link + + Prototype: array stat ( string $filename ); + Description: Gives information about a file +*/ + +$file_path = dirname(__FILE__); +require("$file_path/file.inc"); + +echo "*** Testing lstat() & stat() : basic functionality ***\n"; + +/* creating temp directory and file */ + +// creating dir +$dirname = "$file_path/lstat_stat_basic"; +mkdir($dirname); +// stat of the dir created +$dir_stat = stat($dirname); +clearstatcache(); +sleep(2); + +// creating file +$filename = "$dirname/lstat_stat_basic.tmp"; +$file_handle = fopen($filename, "w"); +fclose($file_handle); +// stat of the file created +$file_stat = stat($filename); +sleep(2); + +// now new stat of the dir after file is created +$new_dir_stat = stat($dirname); +clearstatcache(); + +// create soft link and record stat +$sym_linkname = "$file_path/lstat_stat_basic_link.tmp"; +symlink($filename, $sym_linkname); +// stat of the link created +$link_stat = lstat($sym_linkname); +sleep(2); +// new stat of the file, after a softlink to this file is created +$new_file_stat = stat($filename); +clearstatcache(); + +// stat contains 13 different values stored twice, can be accessed using +// numeric and named keys, compare them to see they are same +echo "*** Testing stat() and lstat() : validating the values stored in stat ***\n"; +// Initial stat values +var_dump( compare_self_stat($file_stat) ); //expect true +var_dump( compare_self_stat($dir_stat) ); //expect true +var_dump( compare_self_stat($link_stat) ); // expect true + +// New stat values taken after creation of file & link +var_dump( compare_self_stat($new_file_stat) ); //expect true +var_dump( compare_self_stat($new_dir_stat) ); // expect true + +// compare the two stat values, initial stat and stat recorded after +// creating files and link, also dump the value of stats +echo "*** Testing stat() and lstat() : comparing stats (recorded before and after file/link creation) ***\n"; +echo "-- comparing difference in dir stats before and after creating file in it --\n"; +$affected_elements = array( 9, 10, 'mtime', 'ctime' ); +var_dump( compare_stats($dir_stat, $new_dir_stat, $affected_elements, '!=', true) ); // expect true + +echo "-- comparing difference in file stats before and after creating link to it --\n"; +var_dump( compare_stats($file_stat, $new_file_stat, $all_stat_keys, "==", true) ); // expect true + +echo "Done\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink("$file_path/lstat_stat_basic_link.tmp"); +unlink("$file_path/lstat_stat_basic/lstat_stat_basic.tmp"); +rmdir("$file_path/lstat_stat_basic"); +?> +--EXPECTF-- +*** Testing lstat() & stat() : basic functionality *** +*** Testing stat() and lstat() : validating the values stored in stat *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Testing stat() and lstat() : comparing stats (recorded before and after file/link creation) *** +-- comparing difference in dir stats before and after creating file in it -- +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(%d) + [12]=> + int(%d) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(%d) + ["blocks"]=> + int(%d) +} +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(%d) + [12]=> + int(%d) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(%d) + ["blocks"]=> + int(%d) +} +bool(true) +-- comparing difference in file stats before and after creating link to it -- +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(%d) + [12]=> + int(%d) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(%d) + ["blocks"]=> + int(%d) +} +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(%d) + [12]=> + int(%d) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(%d) + ["blocks"]=> + int(%d) +} +bool(true) +Done diff --git a/ext/standard/tests/file/lstat_stat_error.phpt b/ext/standard/tests/file/lstat_stat_error.phpt new file mode 100644 index 0000000000..e5a971461e --- /dev/null +++ b/ext/standard/tests/file/lstat_stat_error.phpt @@ -0,0 +1,83 @@ +--TEST-- +Test lstat() and stat() functions: error conditions +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. lstat() not available on Windows'); +} +?> +--FILE-- +<?php +/* Prototype: array lstat ( string $filename ); + Description: Gives information about a file or symbolic link + + Prototype: array stat ( string $filename ); + Description: Gives information about a file +*/ + +echo "*** Testing lstat() for error conditions ***\n"; +$file_path = dirname(__FILE__); +var_dump( lstat() ); // args < expected +var_dump( lstat(__FILE__, 2) ); // args > expected +var_dump( lstat("$file_path/temp.tmp") ); // non existing file +var_dump( lstat(22) ); // scalar argument +$arr = array(__FILE__); +var_dump( lstat($arr) ); // array argument + +echo "\n*** Testing stat() for error conditions ***\n"; +var_dump( stat() ); // args < expected +var_dump( stat(__FILE__, 2) ); // file, args > expected +var_dump( stat(dirname(__FILE__), 2) ); //dir, args > expected + +var_dump( stat("$file_path/temp.tmp") ); // non existing file +var_dump( stat("$file_path/temp/") ); // non existing dir +var_dump( stat(22) ); // scalar argument +var_dump( stat($arr) ); // array argument + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing lstat() for error conditions *** + +Warning: Wrong parameter count for lstat() in %s on line %d +NULL + +Warning: Wrong parameter count for lstat() in %s on line %d +NULL + +Warning: lstat(): Lstat failed for %s in %s on line %d +bool(false) + +Warning: lstat(): Lstat failed for 22 in %s on line %d +bool(false) + +Notice: Array to string conversion in %s on line %d + +Warning: lstat(): Lstat failed for Array in %s on line %d +bool(false) + +*** Testing stat() for error conditions *** + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: stat(): stat failed for %s in %s on line %d +bool(false) + +Warning: stat(): stat failed for %s in %s on line %d +bool(false) + +Warning: stat(): stat failed for 22 in %s on line %d +bool(false) + +Notice: Array to string conversion in %s on line %d + +Warning: stat(): stat failed for Array in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/file/rename_variation-win32.phpt b/ext/standard/tests/file/rename_variation-win32.phpt new file mode 100644 index 0000000000..3cac5ccadd --- /dev/null +++ b/ext/standard/tests/file/rename_variation-win32.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +require dirname(__FILE__).'/file.inc'; + +/* creating directory */ +$file_path = dirname(__FILE__); +mkdir("$file_path/rename_variation"); + +/* rename files across directories */ +echo "*** Testing rename() : rename files across directories ***\n"; +$src_filenames = array( + "$file_path/rename_variation/rename_variation.tmp", + + /* Testing a file trailing slash */ + "$file_path/rename_variation/rename_variation.tmp/", + + /* Testing file with double slashes */ + "$file_path/rename_variation//rename_variation.tmp", + "$file_path//rename_variation//rename_variation.tmp", +); +$counter = 1; +/* loop through each $file and rename it to rename_variation2.tmp */ +foreach($src_filenames as $src_filename) { + echo "-- Iteration $counter --\n"; + $fp = fopen("$file_path/rename_variation/rename_variation.tmp", "w"); + fclose($fp); + $dest_filename = "$file_path/rename_variation2.tmp"; + var_dump( rename($src_filename, $dest_filename) ); + // ensure that file got renamed to new name + var_dump( file_exists($src_filename) ); // expecting false + var_dump( file_exists($dest_filename) ); // expecting true + $counter++; + + // unlink the file + unlink($dest_filename); +} + +// clean the temp dir and file +rmdir("$file_path/rename_variation"); + +// rename dirs across directories +echo "\n*** Testing rename() : renaming directory across directories ***\n"; +$src_dirs = array ( + /* Testing simple directory tree */ + "$file_path/rename_variation/", + + /* Testing a dir with trailing slash */ + "$file_path/rename_variation/", + + /* Testing dir with double trailing slashes */ + "$file_path//rename_variation//", +); + +$dest_dir = "$file_path/rename_variation_dir"; +// create the $dest_dir +mkdir($dest_dir); + +$counter = 1; +/* loop through each $src_dirs and rename it to $dest_dir */ +foreach($src_dirs as $src_dir) { + echo "-- Iteration $counter --\n"; + + // create the src dir + mkdir("$file_path/rename_variation/"); + // rename the src dir to a new dir in dest dir + var_dump( rename($src_dir, $dest_dir."/new_dir") ); + // ensure that dir was renamed + var_dump( file_exists($src_dir) ); // expecting false + var_dump( file_exists($dest_dir."/new_dir") ); // expecting true + + // remove the new dir + rmdir($dest_dir."/new_dir"); + $counter++; +} + +/* Renaming a file and directory to numeric name */ +echo "\n*** Testing rename() by renaming a file and directory to numeric name ***\n"; +$fp = fopen($file_path."/rename_variation.tmp", "w"); +fclose($fp); +// renaming existing file to numeric name +var_dump( rename($file_path."/rename_variation.tmp", $file_path."/12345") ); +// ensure that rename worked fine +var_dump( file_exists($file_path."/rename_variation.tmp" ) ); // expecting false +var_dump( file_exists($file_path."/12345" ) ); // expecting true +// remove the file +unlink($file_path."/12345"); + +// renaming a directory to numeric name +var_dump( rename($file_path."/rename_variation_dir/", $file_path."/12345") ); +// ensure that rename worked fine +var_dump( file_exists($file_path."/rename_variation_dir" ) ); // expecting false +var_dump( file_exists($file_path."/12345" ) ); // expecting true + +// delete the file and dir +rmdir($file_path."/12345"); + +/* test rename() by trying to rename an existing file/dir to the same name + and one another */ +// create a dir +$file_path = dirname(__FILE__); +$dirname = "$file_path/rename_variation_dir"; +mkdir($dirname); +//create a file +$filename = "$file_path/rename_variation.tmp"; +$fp = fopen($filename, "w"); +fclose($fp); + +echo "\n-- Renaming file to same file name --\n"; +var_dump( rename($filename, $filename) ); + +echo "\n-- Renaming directory to same directory name --\n"; +var_dump( rename($dirname, $dirname) ); + +echo "\n-- Renaming existing file to existing directory name --\n"; +var_dump( rename($filename, $dirname) ); + +echo "\n-- Renaming existing directory to existing file name --\n"; +$fp = fopen($filename, "w"); +fclose($fp); +var_dump( rename($dirname, $filename) ); + +echo "Done\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/rename_variation_link.tmp"); +unlink($file_path."/rename_variation.tmp"); +rmdir($file_path."/rename_variation_dir"); +?> +--EXPECTF-- +*** Testing rename() : rename files across directories *** +-- Iteration 1 -- +bool(true) +bool(false) +bool(true) +-- Iteration 2 -- +bool(true) +bool(false) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) +-- Iteration 4 -- +bool(true) +bool(false) +bool(true) + +*** Testing rename() : renaming directory across directories *** +-- Iteration 1 -- +bool(true) +bool(false) +bool(true) +-- Iteration 2 -- +bool(true) +bool(false) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) + +*** Testing rename() by renaming a file and directory to numeric name *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) + +-- Renaming file to same file name -- +bool(true) + +-- Renaming directory to same directory name -- +bool(true) + +-- Renaming existing file to existing directory name -- + +Warning: rename(%s,%s): File exists in %s on line %d +bool(false) + +-- Renaming existing directory to existing file name -- + +Warning: rename(%s,%s): File exists in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/rename_variation.phpt b/ext/standard/tests/file/rename_variation.phpt new file mode 100644 index 0000000000..cf1c0ff8f7 --- /dev/null +++ b/ext/standard/tests/file/rename_variation.phpt @@ -0,0 +1,311 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. only for Linux'); +} +?> +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +require dirname(__FILE__).'/file.inc'; + +/* creating directory */ +$file_path = dirname(__FILE__); +mkdir("$file_path/rename_variation"); + +/* rename files across directories */ +echo "*** Testing rename() : rename files across directories ***\n"; +$src_filenames = array( + "$file_path/rename_variation/rename_variation.tmp", + + /* Testing a file trailing slash */ + "$file_path/rename_variation/rename_variation.tmp/", + + /* Testing file with double slashes */ + "$file_path/rename_variation//rename_variation.tmp", + "$file_path//rename_variation//rename_variation.tmp", +); +$counter = 1; +/* loop through each $file and rename it to rename_variation2.tmp */ +foreach($src_filenames as $src_filename) { + echo "-- Iteration $counter --\n"; + $fp = fopen("$file_path/rename_variation/rename_variation.tmp", "w"); + fclose($fp); + $dest_filename = "$file_path/rename_variation2.tmp"; + var_dump( rename($src_filename, $dest_filename) ); + // ensure that file got renamed to new name + var_dump( file_exists($src_filename) ); // expecting false + var_dump( file_exists($dest_filename) ); // expecting true + $counter++; + + // unlink the file + unlink($dest_filename); +} + +// clean the temp dir and file +rmdir("$file_path/rename_variation"); + +// rename dirs across directories +echo "\n*** Testing rename() : renaming directory across directories ***\n"; +$src_dirs = array ( + /* Testing simple directory tree */ + "$file_path/rename_variation/", + + /* Testing a dir with trailing slash */ + "$file_path/rename_variation/", + + /* Testing dir with double trailing slashes */ + "$file_path//rename_variation//", +); + +$dest_dir = "$file_path/rename_variation_dir"; +// create the $dest_dir +mkdir($dest_dir); + +$counter = 1; +/* loop through each $src_dirs and rename it to $dest_dir */ +foreach($src_dirs as $src_dir) { + echo "-- Iteration $counter --\n"; + + // create the src dir + mkdir("$file_path/rename_variation/"); + // rename the src dir to a new dir in dest dir + var_dump( rename($src_dir, $dest_dir."/new_dir") ); + // ensure that dir was renamed + var_dump( file_exists($src_dir) ); // expecting false + var_dump( file_exists($dest_dir."/new_dir") ); // expecting true + + // remove the new dir + rmdir($dest_dir."/new_dir"); + $counter++; +} + +/* Testing rename() on soft and hard links with different permissions */ +echo "\n*** Testing rename() on soft links ***\n"; +// create the file +$file_prefix = "rename_variation"; +create_files(dirname(__FILE__), 1, "numeric", 0755, 1, "w", $file_prefix); + +// create the soft links to the file +$filename = $file_prefix."1.tmp"; +create_links(dirname(__FILE__), $filename, 1, "soft", 1024, "rename_variation_soft_link"); + +//rename the link to a new name in the same dir +$src_linkname = "$file_path/rename_variation_soft_link1.tmp"; +$dest_linkname = "$file_path/rename_variation_soft_link2.tmp"; +var_dump( rename( $src_linkname, $dest_linkname) ); +//ensure that link was renamed +var_dump( file_exists($src_linkname) ); // expecting false +var_dump( file_exists($dest_linkname) ); // expecting true + +// rename a link across dir +var_dump( rename($dest_linkname, $dest_dir."/rename_variation_soft_link2.tmp")); +//ensure that link got renamed +var_dump( file_exists($dest_linkname) ); // expecting false +var_dump( file_exists($dest_dir."/rename_variation_soft_link2.tmp") ); // expecting true + +// delete the link file now +unlink($dest_dir."/rename_variation_soft_link2.tmp"); + +echo "\n*** Testing rename() on hard links ***\n"; +create_links(dirname(__FILE__), $filename, 1, "hard", 1024, "rename_variation_hard_link"); + +//rename the link to a new name in the same dir +$src_linkname = "$file_path/rename_variation_hard_link1.tmp"; +$dest_linkname = "$file_path/rename_variation_hard_link2.tmp"; +var_dump( rename( $src_linkname, $dest_linkname) ); +//ensure that link was renamed +var_dump( file_exists($src_linkname) ); // expecting false +var_dump( file_exists($dest_linkname) ); // expecting true + +// rename a hard link across dir +var_dump( rename($dest_linkname, $dest_dir."/rename_variation_hard_link2.tmp") ); +//ensure that link got renamed +var_dump( file_exists($dest_linkname) ); // expecting false +var_dump( file_exists($dest_dir."/rename_variation_hard_link2.tmp") ); // expecting true + +// delete the link file now +unlink($dest_dir."/rename_variation_hard_link2.tmp"); +// delete the file +delete_files(dirname(__FILE__), 1, $file_prefix); + +/* Renaming a file, link and directory to numeric name */ +echo "\n*** Testing rename() by renaming a file, link and directory to numeric name ***\n"; +$fp = fopen($file_path."/rename_variation.tmp", "w"); +fclose($fp); +// renaming existing file to numeric name +var_dump( rename($file_path."/rename_variation.tmp", $file_path."/12345") ); +// ensure that rename worked fine +var_dump( file_exists($file_path."/rename_variation.tmp" ) ); // expecting false +var_dump( file_exists($file_path."/12345" ) ); // expecting true +// remove the file +unlink($file_path."/12345"); + +// renaming a directory to numeric name +var_dump( rename($file_path."/rename_variation_dir/", $file_path."/12345") ); +// ensure that rename worked fine +var_dump( file_exists($file_path."/rename_variation_dir" ) ); // expecting false +var_dump( file_exists($file_path."/12345" ) ); // expecting true + +// renaming existing link to numeric name +create_file( $file_path."/rename_variation.tmp"); +/* +symlink($file_path."/rename_variation.tmp", $file_path."/rename_variation_link.tmp"); +var_dump( rename($file_path."/rename_variation_link.tmp", $file_path."/1234") ); +// ensure that rename worked fine +var_dump( file_exists($file_path."/rename_variation_link.tmp" ) ); // expecting false +var_dump( file_exists($file_path."/1234" ) ); // expecting true +*/ +// delete the file and dir +rmdir($file_path."/12345"); + +/* test rename() by trying to rename an existing file/dir/link to the same name + and one another */ +// create a dir +$file_path = dirname(__FILE__); +$dirname = "$file_path/rename_variation_dir"; +mkdir($dirname); +//create a file +$filename = "$file_path/rename_variation.tmp"; +$fp = fopen($filename, "w"); +fclose($fp); +// create a link +$linkname = "$file_path/rename_variation_link.tmp"; +symlink($filename, $linkname); + +echo "\n-- Renaming link to same link name --\n"; +var_dump( rename($linkname, $linkname) ); + +echo "\n-- Renaming file to same file name --\n"; +var_dump( rename($filename, $filename) ); + +echo "\n-- Renaming directory to same directory name --\n"; +var_dump( rename($dirname, $dirname) ); + +echo "\n-- Renaming existing link to existing directory name --\n"; +var_dump( rename($linkname, $dirname) ); +echo "\n-- Renaming existing link to existing file name --\n"; +var_dump( rename($linkname, $filename) ); + +echo "\n-- Renaming existing file to existing directory name --\n"; +var_dump( rename($filename, $dirname) ); +echo "\n-- Renaming existing file to existing link name --\n"; +var_dump( rename($filename, $linkname) ); + +echo "\n-- Renaming existing directory to existing file name --\n"; +$fp = fopen($filename, "w"); +fclose($fp); +var_dump( rename($dirname, $filename) ); +echo "\n-- Renaming existing directory to existing link name --\n"; +var_dump( rename($dirname, $linkname) ); + +echo "Done\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/rename_variation_link.tmp"); +unlink($file_path."/rename_variation.tmp"); +rmdir($file_path."/rename_variation_dir"); +?> +--EXPECTF-- +*** Testing rename() : rename files across directories *** +-- Iteration 1 -- +bool(true) +bool(false) +bool(true) +-- Iteration 2 -- + +Warning: rename(%s,%s): Not a directory in %s on line %d +bool(false) +bool(false) +bool(false) + +Warning: unlink(%s): No such file or directory in %s on line %d +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) +-- Iteration 4 -- +bool(true) +bool(false) +bool(true) + +*** Testing rename() : renaming directory across directories *** +-- Iteration 1 -- +bool(true) +bool(false) +bool(true) +-- Iteration 2 -- +bool(true) +bool(false) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) + +*** Testing rename() on soft links *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) + +*** Testing rename() on hard links *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) + +*** Testing rename() by renaming a file, link and directory to numeric name *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) + +-- Renaming link to same link name -- +bool(true) + +-- Renaming file to same file name -- +bool(true) + +-- Renaming directory to same directory name -- +bool(true) + +-- Renaming existing link to existing directory name -- + +Warning: rename(%s,%s): Is a directory in %s on line %d +bool(false) + +-- Renaming existing link to existing file name -- +bool(true) + +-- Renaming existing file to existing directory name -- + +Warning: rename(%s,%s): Is a directory in %s on line %d +bool(false) + +-- Renaming existing file to existing link name -- +bool(true) + +-- Renaming existing directory to existing file name -- + +Warning: rename(%s,%s): Not a directory in %s on line %d +bool(false) + +-- Renaming existing directory to existing link name -- + +Warning: rename(%s,%s): Not a directory in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/file/stat_basic-win32.phpt b/ext/standard/tests/file/stat_basic-win32.phpt new file mode 100644 index 0000000000..9f2e5cc256 --- /dev/null +++ b/ext/standard/tests/file/stat_basic-win32.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test stat() function: basic functionality +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. stat() only for windows'); +} +?> +--FILE-- +<?php +/* + Prototype: array stat ( string $filename ); + Description: Gives information about a file +*/ + +$file_path = dirname(__FILE__); +require("$file_path/file.inc"); + +echo "*** Testing stat() : basic functionality ***\n"; + +/* creating temp directory and file */ + +// creating dir +$dirname = "$file_path/stat_basic"; +mkdir($dirname); +// stat of the dir created +$dir_stat = stat($dirname); +clearstatcache(); +sleep(2); + +// creating file +$filename = "$dirname/stat_basic.tmp"; +$file_handle = fopen($filename, "w"); +fclose($file_handle); +// stat of the file created +$file_stat = stat($filename); +sleep(2); + +// now new stat of the dir after file is created +$new_dir_stat = stat($dirname); +clearstatcache(); + +// stat contains 13 different values stored twice, can be accessed using +// numeric and named keys, compare them to see they are same +echo "*** Testing stat(): validating the values stored in stat ***\n"; +// Initial stat values +var_dump( compare_self_stat($file_stat) ); //expect true +var_dump( compare_self_stat($dir_stat) ); //expect true + +// New stat values taken after creation of file +var_dump( compare_self_stat($new_dir_stat) ); // expect true + +// compare the two stat values, initial stat and stat recorded after +// creating file, also dump the value of stats +echo "*** Testing stat(): comparing stats (recorded before and after file creation) ***\n"; +echo "-- comparing difference in dir stats before and after creating file in it --\n"; +$affected_elements = array( 9, 'mtime' ); +var_dump( compare_stats($dir_stat, $new_dir_stat, $affected_elements, '!=', true) ); // expect true + +echo "*** Testing stat(): for the return value ***\n"; +var_dump( is_array( stat($filename) ) ); + +echo "\n---Done---"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink("$file_path/stat_basic/stat_basic.tmp"); +rmdir("$file_path/stat_basic"); +?> +--EXPECTF-- +*** Testing stat() : basic functionality *** +*** Testing stat(): validating the values stored in stat *** +bool(true) +bool(true) +bool(true) +*** Testing stat(): comparing stats (recorded before and after file creation) *** +-- comparing difference in dir stats before and after creating file in it -- +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(-1) + [12]=> + int(-1) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(-1) + ["blocks"]=> + int(-1) +} +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(-1) + [12]=> + int(-1) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(-1) + ["blocks"]=> + int(-1) +} +bool(true) +*** Testing stat(): for the return value *** +bool(true) + +---Done--- diff --git a/ext/standard/tests/file/stat_error-win32.phpt b/ext/standard/tests/file/stat_error-win32.phpt new file mode 100644 index 0000000000..fcbac5ff0b --- /dev/null +++ b/ext/standard/tests/file/stat_error-win32.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test stat() function: error conditions +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: array stat ( string $filename ); + Description: Gives information about a file +*/ + +$file_path = dirname(__FILE__); +$arr = array(__FILE__); + +echo "\n*** Testing stat() for error conditions ***\n"; +var_dump( stat() ); // args < expected +var_dump( stat(__FILE__, 2) ); // file, args > expected +var_dump( stat(dirname(__FILE__), 2) ); //dir, args > expected + +var_dump( stat("$file_path/temp.tmp") ); // non existing file +var_dump( stat("$file_path/temp/") ); // non existing dir +var_dump( stat(22) ); // scalar argument +var_dump( stat($arr) ); // array argument + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing stat() for error conditions *** + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: stat(): stat failed for %s in %s on line %d +bool(false) + +Warning: stat(): stat failed for %s in %s on line %d +bool(false) + +Warning: stat(): stat failed for 22 in %s on line %d +bool(false) + +Notice: Array to string conversion in %s on line %d + +Warning: stat(): stat failed for Array in %s on line %d +bool(false) +Done |