unlink_variation3.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. /* Prototype : bool unlink ( string $filename [, resource $context] );
  12. Description : Deletes filename
  13. */
  14. /* Delete link files - soft and hard links */
  15. $file_path = dirname(__FILE__);
  16. // temp file used
  17. $filename = "$file_path/unlink_variation3.tmp";
  18. echo "*** Testing unlink() on soft and hard links ***\n";
  19. // create temp file
  20. $fp = fopen($filename, "w");
  21. fclose($fp);
  22. // link name used here
  23. $linkname = "$file_path/unlink_variation3_link.tmp";
  24. echo "-- Testing unlink() on soft link --\n";
  25. // create soft link
  26. var_dump( symlink($filename, $linkname) ); // expected: true
  27. // unlink soft link
  28. var_dump( unlink($linkname) ); // expected: true
  29. var_dump( file_exists($linkname) ); // confirm link is deleted
  30. echo "-- Testing unlink() on hard link --\n";
  31. // create hard link
  32. var_dump( link($filename, $linkname) ); // expected: true
  33. // delete hard link
  34. var_dump( unlink($linkname) ); // expected: true
  35. var_dump( file_exists($linkname) ); // confirm link is deleted
  36. // delete temp file
  37. var_dump( unlink($filename) );
  38. var_dump( file_exists($filename) ); // confirm file is deleted
  39. echo "Done\n";
  40. ?>
  41. --EXPECTF--
  42. *** Testing unlink() on soft and hard links ***
  43. -- Testing unlink() on soft link --
  44. bool(true)
  45. bool(true)
  46. bool(false)
  47. -- Testing unlink() on hard link --
  48. bool(true)
  49. bool(true)
  50. bool(false)
  51. bool(true)
  52. bool(false)
  53. Done