fileinode_variation.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. --TEST--
  2. Test fileinode() function: Variations
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) == 'WIN') {
  6. die('skip no link()/symlink() on Windows');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /*
  12. Prototype: int fileinode ( string $filename );
  13. Description: Returns the inode number of the file, or FALSE in case of an error.
  14. */
  15. echo "*** Testing fileinode() with files, links and directories ***\n";
  16. $file_path = dirname(__FILE__);
  17. $file1 = $file_path."/fileinode1_variation.tmp";
  18. $file2 = $file_path."/fileinode2_variation.tmp";
  19. $link1 = $file_path."/fileinode1_variation_link.tmp";
  20. $link2 = $file_path."/fileinode2_variation_link.tmp";
  21. echo "-- Testing with files --\n";
  22. //creating the files
  23. fclose( fopen( $file1, "w" ) );
  24. fclose( fopen( $file2, "w" ) );
  25. print( fileinode( $file1) )."\n";
  26. print( fileinode( $file2) )."\n";
  27. clearstatcache();
  28. echo "-- Testing with links: hard link --\n";
  29. link( $file1, $link1); // Creating an hard link
  30. print( fileinode( $file1) )."\n";
  31. clearstatcache();
  32. print( fileinode( $link1) )."\n";
  33. clearstatcache();
  34. echo "-- Testing with links: soft link --\n";
  35. symlink( $file2, $link2); // Creating a soft link
  36. print( fileinode( $file2) )."\n";
  37. clearstatcache();
  38. print( fileinode( $link2) )."\n";
  39. unlink( $link1 );
  40. unlink( $link2 );
  41. echo "-- Testing after copying a file --\n";
  42. copy( $file1, $file_path."/fileinode1_variation_new.tmp");
  43. print( fileinode( $file1) )."\n";
  44. clearstatcache();
  45. print( fileinode( $file_path."/fileinode1_variation_new.tmp") )."\n";
  46. unlink( $file_path."/fileinode1_variation_new.tmp");
  47. unlink( $file1);
  48. unlink( $file2);
  49. echo "-- Testing after renaming the file --\n";
  50. fclose( fopen("$file_path/old.txt", "w") );
  51. print( fileinode("$file_path/old.txt") )."\n";
  52. clearstatcache();
  53. rename("$file_path/old.txt", "$file_path/new.txt");
  54. print( fileinode("$file_path/new.txt") )."\n";
  55. unlink("$file_path/new.txt");
  56. echo "-- Testing with directories --\n";
  57. mkdir("$file_path/dir");
  58. print( fileinode("$file_path/dir") )."\n";
  59. clearstatcache();
  60. mkdir("$file_path/dir/subdir");
  61. print( fileinode("$file_path/dir/subdir") )."\n";
  62. clearstatcache();
  63. echo "-- Testing with binary input --\n";
  64. print( fileinode(b"$file_path/dir") )."\n";
  65. clearstatcache();
  66. print( fileinode(b"$file_path/dir/subdir") );
  67. rmdir("$file_path/dir/subdir");
  68. rmdir("$file_path/dir");
  69. echo "\n*** Done ***";
  70. --EXPECTF--
  71. *** Testing fileinode() with files, links and directories ***
  72. -- Testing with files --
  73. %d
  74. %d
  75. -- Testing with links: hard link --
  76. %d
  77. %d
  78. -- Testing with links: soft link --
  79. %d
  80. %d
  81. -- Testing after copying a file --
  82. %d
  83. %d
  84. -- Testing after renaming the file --
  85. %d
  86. %d
  87. -- Testing with directories --
  88. %d
  89. %d
  90. -- Testing with binary input --
  91. %d
  92. %d
  93. *** Done ***