unlink_variation3.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. Test unlink() function : usage variations - unlink links
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) == 'WIN') {
  6. die('skip only on Linux');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /* Delete link files - soft and hard links */
  12. $file_path = __DIR__;
  13. // temp file used
  14. $filename = "$file_path/unlink_variation3.tmp";
  15. echo "*** Testing unlink() on soft and hard links ***\n";
  16. // create temp file
  17. $fp = fopen($filename, "w");
  18. fclose($fp);
  19. // link name used here
  20. $linkname = "$file_path/unlink_variation3_link.tmp";
  21. echo "-- Testing unlink() on soft link --\n";
  22. // create soft link
  23. var_dump( symlink($filename, $linkname) ); // expected: true
  24. // unlink soft link
  25. var_dump( unlink($linkname) ); // expected: true
  26. var_dump( file_exists($linkname) ); // confirm link is deleted
  27. echo "-- Testing unlink() on hard link --\n";
  28. // create hard link
  29. var_dump( link($filename, $linkname) ); // expected: true
  30. // delete hard link
  31. var_dump( unlink($linkname) ); // expected: true
  32. var_dump( file_exists($linkname) ); // confirm link is deleted
  33. // delete temp file
  34. var_dump( unlink($filename) );
  35. var_dump( file_exists($filename) ); // confirm file is deleted
  36. echo "Done\n";
  37. ?>
  38. --EXPECT--
  39. *** Testing unlink() on soft and hard links ***
  40. -- Testing unlink() on soft link --
  41. bool(true)
  42. bool(true)
  43. bool(false)
  44. -- Testing unlink() on hard link --
  45. bool(true)
  46. bool(true)
  47. bool(false)
  48. bool(true)
  49. bool(false)
  50. Done