rename_basic.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. --TEST--
  2. Test rename() function: basic functionality
  3. --FILE--
  4. <?php
  5. echo "*** Testing rename() on non-existing file ***\n";
  6. $file_path = __DIR__;
  7. require "$file_path/file.inc";
  8. $src_name = "$file_path/rename_basic.tmp";
  9. $dest_name = "$file_path/rename_basic_new.tmp";
  10. // create the file
  11. $fp = fopen($src_name, "w");
  12. $old_stat = stat($src_name);
  13. fclose($fp);
  14. var_dump( rename($src_name, $dest_name) ); // expecting true
  15. var_dump( file_exists($src_name) ); // expecting false
  16. var_dump( file_exists($dest_name) ); // expecting true
  17. $new_stat = stat("$file_path/rename_basic_new.tmp");
  18. // checking statistics of old and renamed file - both should be same except ctime
  19. $keys_to_compare = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12,
  20. "dev", "ino", "mode", "nlink", "uid", "gid",
  21. "rdev", "size", "atime", "mtime", "blksize", "blocks");
  22. var_dump( compare_stats($old_stat, $new_stat, $keys_to_compare) );
  23. ?>
  24. --CLEAN--
  25. <?php
  26. unlink(__DIR__."/rename_basic_new.tmp");
  27. ?>
  28. --EXPECT--
  29. *** Testing rename() on non-existing file ***
  30. bool(true)
  31. bool(false)
  32. bool(true)
  33. bool(true)