rename_basic.phpt 1.3 KB

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