summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnt Phillips <ant@php.net>2008-04-30 13:53:49 +0000
committerAnt Phillips <ant@php.net>2008-04-30 13:53:49 +0000
commit3946b4727b1215a661522323f58fb163c630153b (patch)
treeadca345aab3d9f31b9ed33534db8e2d7f99da340
parent3a30d703c0295d761ceb88b0673f60405a57b41c (diff)
downloadphp-git-3946b4727b1215a661522323f58fb163c630153b.tar.gz
Break up complicated rename tests into some smaller more consumable chunks
-rwxr-xr-xext/standard/tests/file/rename_basic.phpt89
-rw-r--r--ext/standard/tests/file/rename_variation-win32.phpt130
-rw-r--r--ext/standard/tests/file/rename_variation1-win32.phpt81
-rw-r--r--ext/standard/tests/file/rename_variation2-win32.phpt61
-rw-r--r--ext/standard/tests/file/rename_variation3-win32.phpt69
-rw-r--r--ext/standard/tests/file/rename_variation8.phpt67
-rw-r--r--ext/standard/tests/file/rename_variation9.phpt53
7 files changed, 348 insertions, 202 deletions
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--
<?php
-unlink(dirname(__FILE__)."/rename_basic_new2.tmp");
-rmdir(dirname(__FILE__)."/rename_basic_dir3");
+unlink(dirname(__FILE__)."/rename_basic.tmp");
+unlink(dirname(__FILE__)."/rename_basic_new.tmp");
?>
--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 3cac5ccadd..ae95557603 100644
--- a/ext/standard/tests/file/rename_variation-win32.phpt
+++ b/ext/standard/tests/file/rename_variation-win32.phpt
@@ -14,7 +14,7 @@ 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");
@@ -30,7 +30,9 @@ $src_filenames = array(
"$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";
@@ -38,6 +40,7 @@ foreach($src_filenames as $src_filename) {
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
@@ -47,90 +50,8 @@ foreach($src_filenames as $src_filename) {
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--
@@ -147,53 +68,20 @@ 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)
+Warning: rename(%s/rename_variation/rename_variation.tmp/,%s/rename_variation2.tmp): Invalid argument in %s on line %d
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 ***
+Warning: unlink(%s/rename_variation2.tmp): 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)
+Done
--- 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_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--
+<?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__);
+
+// 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++;
+}
+
+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() : 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--
+<?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';
+
+$file_path = dirname(__FILE__);
+mkdir("$file_path/rename_variation_dir");
+
+/* 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
+
+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
+
+rmdir($file_path."/12345");
+
+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() 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..7ad17093db
--- /dev/null
+++ b/ext/standard/tests/file/rename_variation3-win32.phpt
@@ -0,0 +1,69 @@
+--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__);
+$dirname = "$file_path/rename_variation_dir";
+mkdir($dirname);
+
+/* test rename() by trying to rename an existing file/dir to the same name
+ and one another */
+
+$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--
+-- 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/rename_variation.tmp,%s/rename_variation_dir): File exists in %s on line %d
+bool(false)
+
+-- Renaming existing directory to existing file name --
+
+Warning: rename(%s/rename_variation_dir,%s/rename_variation.tmp): File exists in %s on line %d
+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--
+<?php
+/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] );
+ Description: Renames a file or directory
+*/
+
+echo "\n*** Testing rename() on non-existing file ***\n";
+$file_path = dirname(__FILE__);
+
+// try renaming a non existing file
+$src_name = $file_path."/non_existent_file.tmp";
+$dest_name = $file_path."/rename_variation8_new.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 "Done\n";
+?>
+--CLEAN--
+<?php
+unlink(dirname(__FILE__)."/rename_basic_new2.tmp");
+rmdir(dirname(__FILE__)."/rename_basic_dir1");
+?>
+--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--
+<?php
+/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] );
+ Description: Renames a file or directory
+*/
+
+echo "\n*** Testing rename() by giving stream context as third argument ***\n";
+$file_path = dirname(__FILE__);
+
+$context = stream_context_create();
+
+// on directory
+$dir_name = "$file_path/rename_variation_dir9";
+$new_dir_name = "$file_path/rename_variation_dir9_new";
+
+mkdir($dir_name);
+
+var_dump( rename($dir_name, $new_dir_name, $context) );
+var_dump( file_exists($dir_name) ); // expecting flase
+var_dump( file_exists($new_dir_name) ); // expecting true
+
+//on file
+$src_name = "$file_path/rename_variation9.tmp";
+$dest_name = "$file_path/rename_variation9_new.tmp";
+
+// create the file
+$fp = fopen($src_name, "w");
+$s1 = stat($src_name);
+fclose($fp);
+
+var_dump( rename($src_name, $dest_name, $context) );
+var_dump( file_exists($src_name) ); // expecting false
+var_dump( file_exists($dest_name) ); // expecting true
+
+echo "Done\n";
+?>
+--CLEAN--
+<?php
+unlink(dirname(__FILE__)."/rename_variation9_new.tmp");
+rmdir(dirname(__FILE__)."/rename_variation_dir9_new");
+?>
+--EXPECTF--
+*** Testing rename() by giving stream context as third argument ***
+bool(true)
+bool(false)
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+Done
+