]> granicus.if.org Git - php/commitdiff
Break up complicated rename tests into some smaller more consumable chunks
authorAnt Phillips <ant@php.net>
Wed, 30 Apr 2008 13:53:52 +0000 (13:53 +0000)
committerAnt Phillips <ant@php.net>
Wed, 30 Apr 2008 13:53:52 +0000 (13:53 +0000)
ext/standard/tests/file/rename_basic.phpt
ext/standard/tests/file/rename_variation-win32.phpt
ext/standard/tests/file/rename_variation1-win32.phpt [new file with mode: 0644]
ext/standard/tests/file/rename_variation2-win32.phpt [new file with mode: 0644]
ext/standard/tests/file/rename_variation3-win32.phpt [new file with mode: 0644]
ext/standard/tests/file/rename_variation8.phpt [new file with mode: 0644]
ext/standard/tests/file/rename_variation9.phpt [new file with mode: 0644]

index 8a255ca6efeee642c589f01b958ba7e7370e6d5a..28d3b19889bd09db32a1a8a416c72b5e07289d10 100755 (executable)
@@ -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
+
index 7f1484dcec262525f644e7d966cac9367d11fb0b..eae6812b7c1fc590516145d4eef1507d42e40dfa 100644 (file)
@@ -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--
 <?php
-unlink(dirname(__FILE__)."/12345.tmp");
-unlink(dirname(__FILE__)."/rename_variation.tmp");
-rmdir(dirname(__FILE__)."/rename_variation.tmp/");
-rmdir(dirname(__FILE__)."/rename_variation/");
-rmdir(dirname(__FILE__)."/12345/");
+$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 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 (file)
index 0000000..0955096
--- /dev/null
@@ -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 (file)
index 0000000..87f4e7d
--- /dev/null
@@ -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 (file)
index 0000000..b251fc4
--- /dev/null
@@ -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__);
+$dirname = "$file_path/rename_variation3_dir"; 
+mkdir($dirname);
+
+/* test rename() by trying to rename an existing file/dir to the same name
+  and one another */
+
+$filename = "$file_path/rename_variation3.tmp"; 
+$fp = fopen($filename, "w");
+fclose($fp);
+
+echo "\n-- Renaming file to same file name --\n";
+var_dump( rename($filename, $filename) );
+var_dump( file_exists($filename) );
+
+echo "\n-- Renaming directory to same directory name --\n";
+var_dump( rename($dirname, $dirname) );
+var_dump( file_exists($dirname) );
+
+echo "\n-- Renaming existing file to existing directory name --\n";
+var_dump( rename($filename, $dirname) );
+var_dump( file_exists($filename) );
+var_dump( file_exists($dirname) );
+
+echo "\n-- Renaming existing directory to existing file name --\n";
+$fp = fopen($filename, "w");
+fclose($fp);
+
+var_dump( rename($dirname, $filename) );
+var_dump( file_exists($filename) );
+var_dump( file_exists($dirname) );
+
+echo "Done\n";
+?>
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink($file_path."/rename_variation3_link.tmp");
+unlink($file_path."/rename_variation3.tmp");
+rmdir($file_path."/rename_variation3_dir");
+rmdir($file_path."/rename_variation3.tmp");
+?>
+--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 (file)
index 0000000..650b6c9
--- /dev/null
@@ -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 (file)
index 0000000..d923e4a
--- /dev/null
@@ -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
+