rename_variation8.phpt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. --TEST--
  2. Test rename() function: variation
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) == 'WIN') die('skip.. not for Windows');
  6. ?>
  7. --FILE--
  8. <?php
  9. echo "\n*** Testing rename() on non-existing file ***\n";
  10. $file_path = __DIR__;
  11. // try renaming a non existing file
  12. $src_name = $file_path."/non_existent_file.tmp";
  13. $dest_name = $file_path."/rename_variation8_new.tmp";
  14. var_dump( rename($src_name, $dest_name) );
  15. // ensure that $dest_name didn't get created
  16. var_dump( file_exists($src_name) ); // expecting false
  17. var_dump( file_exists($dest_name) ); // expecting false
  18. // rename a existing dir to new name
  19. echo "\n*** Testing rename() on existing directory ***\n";
  20. $dir_name = $file_path."/rename_basic_dir";
  21. mkdir($dir_name);
  22. $new_dir_name = $file_path."/rename_basic_dir1";
  23. var_dump( rename($dir_name, $new_dir_name) );
  24. //ensure that $new_dir_name got created
  25. var_dump( file_exists($dir_name) ); // expecting false
  26. var_dump( file_exists($new_dir_name) ); // expecting true
  27. // try to rename an non_existing dir
  28. echo "\n*** Testing rename() on non-existing directory ***\n";
  29. $non_existent_dir_name = $file_path."/non_existent_dir";
  30. $new_dir_name = "$file_path/rename_basic_dir2";
  31. var_dump( rename($non_existent_dir_name, $new_dir_name) );
  32. // ensure that $new_dir_name didn't get created
  33. var_dump( file_exists($non_existent_dir_name) ); // expecting flase
  34. var_dump( file_exists($new_dir_name) ); // expecting false
  35. echo "Done\n";
  36. ?>
  37. --CLEAN--
  38. <?php
  39. unlink(__DIR__."/rename_basic_new2.tmp");
  40. rmdir(__DIR__."/rename_basic_dir1");
  41. ?>
  42. --EXPECTF--
  43. *** Testing rename() on non-existing file ***
  44. Warning: rename(%s/non_existent_file.tmp,%s/rename_variation8_new.tmp): No such file or directory in %s on line %d
  45. bool(false)
  46. bool(false)
  47. bool(false)
  48. *** Testing rename() on existing directory ***
  49. bool(true)
  50. bool(false)
  51. bool(true)
  52. *** Testing rename() on non-existing directory ***
  53. Warning: rename(%s/non_existent_dir,%s/rename_basic_dir2): No such file or directory in %s on line %d
  54. bool(false)
  55. bool(false)
  56. bool(false)
  57. Done