rename_variation5.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. --TEST--
  2. Test rename() function: usage variations-6
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) == 'WIN') {
  6. die('skip.. only for Linux');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /* test rename() by trying to rename an existing file/dir/link to the same name
  12. and one another */
  13. // create a dir
  14. $file_path = __DIR__;
  15. $dirname = "$file_path/rename_variation5_dir";
  16. mkdir($dirname);
  17. //create a file
  18. $filename = "$file_path/rename_variation5.tmp";
  19. $fp = fopen($filename, "w");
  20. fclose($fp);
  21. // create a link
  22. $linkname = "$file_path/rename_variation5_link.tmp";
  23. symlink($filename, $linkname);
  24. echo "\n-- Renaming link to same link name --\n";
  25. var_dump( rename($linkname, $linkname) );
  26. echo "\n-- Renaming file to same file name --\n";
  27. var_dump( rename($filename, $filename) );
  28. echo "\n-- Renaming directory to same directory name --\n";
  29. var_dump( rename($dirname, $dirname) );
  30. echo "\n-- Renaming existing link to existing directory name --\n";
  31. var_dump( rename($linkname, $dirname) );
  32. echo "\n-- Renaming existing link to existing file name --\n";
  33. var_dump( rename($linkname, $filename) );
  34. echo "\n-- Renaming existing file to existing directory name --\n";
  35. var_dump( rename($filename, $dirname) );
  36. echo "\n-- Renaming existing file to existing link name --\n";
  37. var_dump( rename($filename, $linkname) );
  38. echo "\n-- Renaming existing directory to existing file name --\n";
  39. $fp = fopen($filename, "w");
  40. fclose($fp);
  41. var_dump( rename($dirname, $filename) );
  42. echo "\n-- Renaming existing directory to existing link name --\n";
  43. var_dump( rename($dirname, $linkname) );
  44. echo "Done\n";
  45. ?>
  46. --CLEAN--
  47. <?php
  48. $file_path = __DIR__;
  49. unlink($file_path."/rename_variation5_link.tmp");
  50. unlink($file_path."/rename_variation5.tmp");
  51. rmdir($file_path."/rename_variation5_dir");
  52. ?>
  53. --EXPECTF--
  54. -- Renaming link to same link name --
  55. bool(true)
  56. -- Renaming file to same file name --
  57. bool(true)
  58. -- Renaming directory to same directory name --
  59. bool(true)
  60. -- Renaming existing link to existing directory name --
  61. Warning: rename(%s,%s): Is a directory in %s on line %d
  62. bool(false)
  63. -- Renaming existing link to existing file name --
  64. bool(true)
  65. -- Renaming existing file to existing directory name --
  66. Warning: rename(%s,%s): Is a directory in %s on line %d
  67. bool(false)
  68. -- Renaming existing file to existing link name --
  69. bool(true)
  70. -- Renaming existing directory to existing file name --
  71. Warning: rename(%s,%s): Not a directory in %s on line %d
  72. bool(false)
  73. -- Renaming existing directory to existing link name --
  74. Warning: rename(%s,%s): Not a directory in %s on line %d
  75. bool(false)
  76. Done