rename_variation9.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --TEST--
  2. Test rename() function: basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype: bool rename ( string $oldname, string $newname [, resource $context] );
  6. Description: Renames a file or directory
  7. */
  8. echo "\n*** Testing rename() by giving stream context as third argument ***\n";
  9. $file_path = dirname(__FILE__);
  10. $context = stream_context_create();
  11. // on directory
  12. $dir_name = "$file_path/rename_variation_dir9";
  13. $new_dir_name = "$file_path/rename_variation_dir9_new";
  14. mkdir($dir_name);
  15. var_dump( rename($dir_name, $new_dir_name, $context) );
  16. var_dump( file_exists($dir_name) ); // expecting flase
  17. var_dump( file_exists($new_dir_name) ); // expecting true
  18. //on file
  19. $src_name = "$file_path/rename_variation9.tmp";
  20. $dest_name = "$file_path/rename_variation9_new.tmp";
  21. // create the file
  22. $fp = fopen($src_name, "w");
  23. $s1 = stat($src_name);
  24. fclose($fp);
  25. var_dump( rename($src_name, $dest_name, $context) );
  26. var_dump( file_exists($src_name) ); // expecting false
  27. var_dump( file_exists($dest_name) ); // expecting true
  28. echo "Done\n";
  29. ?>
  30. --CLEAN--
  31. <?php
  32. unlink(dirname(__FILE__)."/rename_variation9_new.tmp");
  33. rmdir(dirname(__FILE__)."/rename_variation_dir9_new");
  34. ?>
  35. --EXPECT--
  36. *** Testing rename() by giving stream context as third argument ***
  37. bool(true)
  38. bool(false)
  39. bool(true)
  40. bool(true)
  41. bool(false)
  42. bool(true)
  43. Done