From 90c2cd0c37135b018fd74a75b940590607574929 Mon Sep 17 00:00:00 2001 From: Ant Phillips Date: Wed, 30 Apr 2008 13:53:52 +0000 Subject: [PATCH] Break up complicated rename tests into some smaller more consumable chunks --- ext/standard/tests/file/rename_basic.phpt | 89 +------- .../tests/file/rename_variation-win32.phpt | 198 ++++-------------- .../tests/file/rename_variation1-win32.phpt | 81 +++++++ .../tests/file/rename_variation2-win32.phpt | 61 ++++++ .../tests/file/rename_variation3-win32.phpt | 81 +++++++ .../tests/file/rename_variation8.phpt | 67 ++++++ .../tests/file/rename_variation9.phpt | 53 +++++ 7 files changed, 386 insertions(+), 244 deletions(-) create mode 100644 ext/standard/tests/file/rename_variation1-win32.phpt create mode 100644 ext/standard/tests/file/rename_variation2-win32.phpt create mode 100644 ext/standard/tests/file/rename_variation3-win32.phpt create mode 100644 ext/standard/tests/file/rename_variation8.phpt create mode 100644 ext/standard/tests/file/rename_variation9.phpt diff --git a/ext/standard/tests/file/rename_basic.phpt b/ext/standard/tests/file/rename_basic.phpt index 8a255ca6ef..28d3b19889 100755 --- a/ext/standard/tests/file/rename_basic.phpt +++ b/ext/standard/tests/file/rename_basic.phpt @@ -6,7 +6,7 @@ Test rename() function: basic functionality Description: Renames a file or directory */ -echo "*** Testing rename() for basic functions on existing file ***\n"; +echo "*** Testing rename() on non-existing file ***\n"; $file_path = dirname(__FILE__); $src_name = "$file_path/rename_basic.tmp"; $dest_name = "$file_path/rename_basic_new.tmp"; @@ -16,103 +16,30 @@ $fp = fopen($src_name, "w"); $s1 = stat($src_name); fclose($fp); -var_dump( rename($src_name, $dest_name) ); -// ensure that $dest_name didn't get created -var_dump( file_exists($src_name) ); // expecting false +var_dump( rename($src_name, $dest_name) ); // expecting true +var_dump( file_exists($src_name) ); // expecting false var_dump( file_exists($dest_name) ); // expecting true $s2 = stat("$file_path/rename_basic_new.tmp"); -// checking statistics of old and renamed file -// both should be same + +// checking statistics of old and renamed file - both should be same for ($i = 0; $i <= 12; $i++) { if ($s1[$i] != $s2[$i]) { echo "rename_basic.tmp and rename_basic_new.tmp stat differ at element $i\n"; } } -echo "\n*** Testing rename() on non-existing file ***\n"; -// try renaming a non existing file -$src_name = $file_path."/non_existent_file.tmp"; -$dest_name = $file_path."/rename_basic_new1.tmp"; -var_dump( rename($src_name, $dest_name) ); -// ensure that $dest_name didn't get created -var_dump( file_exists($src_name) ); // expecting false -var_dump( file_exists($dest_name) ); // expecting false - -// rename a existing dir to new name -echo "\n*** Testing rename() on existing directory ***\n"; -$dir_name = $file_path."/rename_basic_dir"; -mkdir($dir_name); -$new_dir_name = $file_path."/rename_basic_dir1"; -var_dump( rename($dir_name, $new_dir_name) ); -//ensure that $new_dir_name got created -var_dump( file_exists($dir_name) ); // expecting false -var_dump( file_exists($new_dir_name) ); // expecting true - -// try to rename an non_existing dir -echo "\n*** Testing rename() on non-existing directory ***\n"; -$non_existent_dir_name = $file_path."/non_existent_dir"; -$new_dir_name = "$file_path/rename_basic_dir2"; -var_dump( rename($non_existent_dir_name, $new_dir_name) ); -// ensure that $new_dir_name didn't get created -var_dump( file_exists($non_existent_dir_name) ); // expecting flase -var_dump( file_exists($new_dir_name) ); // expecting false - -echo "\n*** Testing rename() by giving stream context as third argument ***\n"; -$context = stream_context_create(); -// on directory -$dir_name = "$file_path/rename_basic_dir1"; -$new_dir_name = "$file_path/rename_basic_dir3"; -var_dump( rename($dir_name, $new_dir_name, $context) ); -// ensure that $new_dir_name got created -var_dump( file_exists($dir_name) ); // expecting flase -var_dump( file_exists($new_dir_name) ); // expecting true - -//on file -$src_name = "$file_path/rename_basic_new.tmp"; -$dest_name = "$file_path/rename_basic_new2.tmp"; -var_dump( rename($src_name, $dest_name, $context) ); -// ensure that $dest_name got created -var_dump( file_exists($src_name) ); // expecting false -var_dump( file_exists($dest_name) ); // expecting true - echo "Done\n"; ?> --CLEAN-- --EXPECTF-- -*** Testing rename() for basic functions on existing file *** -bool(true) -bool(false) -bool(true) - *** Testing rename() on non-existing file *** - -Warning: rename(%s/non_existent_file.tmp,%s/rename_basic_new1.tmp): No such file or directory in %s on line %d -bool(false) -bool(false) -bool(false) - -*** Testing rename() on existing directory *** -bool(true) -bool(false) -bool(true) - -*** Testing rename() on non-existing directory *** - -Warning: rename(%s/non_existent_dir,%s/rename_basic_dir2): No such file or directory in %s on line %d -bool(false) -bool(false) -bool(false) - -*** Testing rename() by giving stream context as third argument *** -bool(true) -bool(false) -bool(true) bool(true) bool(false) bool(true) Done + diff --git a/ext/standard/tests/file/rename_variation-win32.phpt b/ext/standard/tests/file/rename_variation-win32.phpt index 7f1484dcec..eae6812b7c 100644 --- a/ext/standard/tests/file/rename_variation-win32.phpt +++ b/ext/standard/tests/file/rename_variation-win32.phpt @@ -14,202 +14,74 @@ if (substr(PHP_OS, 0, 3) != 'WIN') { require dirname(__FILE__).'/file.inc'; -/* creating directory */ +/* create directory */ $file_path = dirname(__FILE__); -mkdir("$file_path/rename_variation/"); +mkdir("$file_path/rename_variation"); -/* Testing rename() function on files */ -echo "*** Testing variations of rename() on files ***\n"; -$files_arr = array( +/* 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/r*.tmp", - - /* Testing Binary safe */ - "$file_path/rename_variation/rename_variationx000.tmp" + "$file_path//rename_variation//rename_variation.tmp", ); + $counter = 1; + /* loop through each $file and rename it to rename_variation2.tmp */ -foreach($files_arr as $file) { +foreach($src_filenames as $src_filename) { + echo "-- Iteration $counter --\n"; $fp = fopen("$file_path/rename_variation/rename_variation.tmp", "w"); fclose($fp); - echo "-- Iteration $counter --\n"; - var_dump( rename($file, "$file_path/rename_variation2.tmp") ); - $counter++; - unlink("$file_path/rename_variation2.tmp"); -} -unlink("$file_path/rename_variation/rename_variation.tmp"); -rmdir("$file_path/rename_variation/"); // deleting temp directory - -/* Testing rename() function on directories */ -echo "\n*** Testing variations of rename() on directories ***\n"; -$directories = array ( - /* Testing simple directory tree */ - "$file_path/rename_variation/", + $dest_filename = "$file_path/rename_variation2.tmp"; + var_dump( rename($src_filename, $dest_filename) ); - /* Testing a dir with trailing slash */ - "$file_path/rename_variation/", - - /* Testing dir with double trailing slashes */ - "$file_path/rename_variation//", - - /* Testing Binary safe */ - "$file_path/rename_variationx000/", - - /* Testing current directory */ - ".", - - /* Dir name as empty string */ - "", - '', - - /* Dir name as string with a space */ - " ", - ' ' -); -$counter = 1; -/* loop through each $dir and rename it to rename_variation1 */ -foreach($directories as $dir) { - mkdir("$file_path/rename_variation/"); - echo "-- Iteration $counter --\n"; - var_dump( rename($dir, "$file_path/rename_variation1/") ); + // 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++; - rmdir("$file_path/rename_variation1/"); + + // unlink the file + unlink($dest_filename); } -/* Testing rename() on non-existing file and directory as first argument */ -echo "\n*** Testing rename() with non-existing file and directory ***\n"; -// renaming a non-existing file to existing file -var_dump( rename(dirname(__FILE__)."/rename_variation123.tmp", __FILE__) ); -// renaming a non-existing directory to existing directory -var_dump( rename(dirname(__FILE__)."/rename_variation123/", dirname(__FILE__)) ); - -/* Renaming a file and directory to numeric name */ -echo "\n*** Testing rename() by renaming a file and directory to numeric name ***\n"; -$fp = fopen(dirname(__FILE__)."/rename_variation.tmp", "w"); -fclose($fp); -// renaming existing file to numeric name -var_dump( rename(dirname(__FILE__)."/rename_variation.tmp", dirname(__FILE__)."/12345.tmp") ); -unlink(dirname(__FILE__)."/12345.tmp"); -// renaming existing directory to numeric name -var_dump( rename(dirname(__FILE__)."/rename_variation/", dirname(__FILE__)."/12345/") ); - -echo "\n*** Testing rename() with miscelleneous input ***\n"; -$file_path = dirname(__FILE__); -mkdir("$file_path/rename_variation"); -$fp = fopen("$file_path/rename_variation.tmp", "w"); -fclose($fp); - -echo "\n-- Renaming file to same file name --\n"; -var_dump( rename("$file_path/rename_variation.tmp", "$file_path/rename_variation.tmp") ); - -echo "\n-- Renaming directory to same directory name --\n"; -var_dump( rename("$file_path/rename_variation/", "$file_path/rename_variation/") ); - -echo "\n-- Renaming existing file to directory name --\n"; -var_dump( rename("$file_path/rename_variation.tmp", "$file_path/rename_variation/") ); - -echo "\n-- Renaming existing directory to file name --\n"; -var_dump( rename("$file_path/rename_variation", "$file_path/rename_variation.tmp") ); +rmdir("$file_path/rename_variation"); echo "Done\n"; ?> --CLEAN-- --EXPECTF-- -*** Testing variations of rename() on files *** +*** Testing rename() : rename files across directories *** -- Iteration 1 -- bool(true) --- Iteration 2 -- -bool(true) --- Iteration 3 -- -bool(true) --- Iteration 4 -- - -Warning: rename(%s,%s): No such file or directory in %s on line %d bool(false) - -Warning: unlink(%s): No such file or directory in %s on line %d - -*** Testing variations of rename() on directories *** --- Iteration 1 -- bool(true) -- Iteration 2 -- -bool(true) --- Iteration 3 -- -bool(true) --- Iteration 4 -- - -Warning: rename(%s,%s): No such file or directory in %s on line %d -bool(false) - -Warning: rmdir(%s): No such file or directory in %s on line %d --- Iteration 5 -- -Warning: rename(.,%s): Permission denied in %s on line %d +Warning: rename(%s/rename_variation/rename_variation.tmp/,%s/rename_variation2.tmp): No such file or directory in %s on line %d bool(false) - -Warning: rmdir(%s): No such file or directory in %s on line %d --- Iteration 6 -- - -Warning: rename(,%s): Permission denied in %s on line %d -bool(false) - -Warning: rmdir(%s): No such file or directory in %s on line %d --- Iteration 7 -- - -Warning: rename(,%s): Permission denied in %s on line %d -bool(false) - -Warning: rmdir(%s): No such file or directory in %s on line %d --- Iteration 8 -- - -Warning: rename( ,%s): File exists in %s on line %d -bool(false) - -Warning: rmdir(%s): No such file or directory in %s on line %d --- Iteration 9 -- - -Warning: rename( ,%s): File exists in %s on line %d -bool(false) - -Warning: rmdir(%s): No such file or directory in %s on line %d - -*** Testing rename() with non-existing file and directory *** - -Warning: rename(%s,%s): No such file or directory in %s on line %d -bool(false) - -Warning: rename(%s,%s): No such file or directory in %s on line %d +bool(true) bool(false) -*** Testing rename() by renaming a file and directory to numeric name *** -bool(true) +Warning: unlink(%s/rename_variation2.tmp): No such file or directory in %s on line %d +-- Iteration 3 -- bool(true) - -*** Testing rename() with miscelleneous input *** - --- Renaming file to same file name -- +bool(false) bool(true) - --- Renaming directory to same directory name -- +-- Iteration 4 -- bool(true) - --- Renaming existing file to directory name -- - -Warning: rename(%s,%s): File exists in %s on line %d -bool(false) - --- Renaming existing directory to file name -- - -Warning: rename(%s,%s): File exists in %s on line %d bool(false) +bool(true) Done + diff --git a/ext/standard/tests/file/rename_variation1-win32.phpt b/ext/standard/tests/file/rename_variation1-win32.phpt new file mode 100644 index 0000000000..0955096d76 --- /dev/null +++ b/ext/standard/tests/file/rename_variation1-win32.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +*** 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) +Done + diff --git a/ext/standard/tests/file/rename_variation2-win32.phpt b/ext/standard/tests/file/rename_variation2-win32.phpt new file mode 100644 index 0000000000..87f4e7ddb1 --- /dev/null +++ b/ext/standard/tests/file/rename_variation2-win32.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +*** Testing rename() by renaming a file and directory to numeric name *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) +Done + diff --git a/ext/standard/tests/file/rename_variation3-win32.phpt b/ext/standard/tests/file/rename_variation3-win32.phpt new file mode 100644 index 0000000000..b251fc448d --- /dev/null +++ b/ext/standard/tests/file/rename_variation3-win32.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +-- Renaming file to same file name -- +bool(true) +bool(true) + +-- Renaming directory to same directory name -- +bool(true) +bool(true) + +-- Renaming existing file to existing directory name -- + +Warning: rename(%s/rename_variation3.tmp,%s/rename_variation3_dir): No such file or directory in %s on line %d +bool(false) +bool(true) +bool(true) + +-- Renaming existing directory to existing file name -- +bool(true) +bool(true) +bool(false) +Done + diff --git a/ext/standard/tests/file/rename_variation8.phpt b/ext/standard/tests/file/rename_variation8.phpt new file mode 100644 index 0000000000..650b6c990b --- /dev/null +++ b/ext/standard/tests/file/rename_variation8.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test rename() function: variation +--FILE-- + +--CLEAN-- + +--EXPECTF-- +*** Testing rename() on non-existing file *** + +Warning: rename(%s/non_existent_file.tmp,%s/rename_variation8_new.tmp): No such file or directory in %s on line %d +bool(false) +bool(false) +bool(false) + +*** Testing rename() on existing directory *** +bool(true) +bool(false) +bool(true) + +*** Testing rename() on non-existing directory *** + +Warning: rename(%s/non_existent_dir,%s/rename_basic_dir2): No such file or directory in %s on line %d +bool(false) +bool(false) +bool(false) +Done + diff --git a/ext/standard/tests/file/rename_variation9.phpt b/ext/standard/tests/file/rename_variation9.phpt new file mode 100644 index 0000000000..d923e4a3d4 --- /dev/null +++ b/ext/standard/tests/file/rename_variation9.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test rename() function: basic functionality +--FILE-- + +--CLEAN-- + +--EXPECTF-- +*** Testing rename() by giving stream context as third argument *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) +Done + -- 2.40.0