007_variation11-win32-mb.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --TEST--
  2. Test fopen and fclose() functions - usage variations - "wt" mode
  3. --SKIPIF--
  4. <?php
  5. if( substr(PHP_OS, 0, 3) != "WIN" )
  6. die('skip Run only on Windows');
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Test fopen() and fclose(): Opening the file in "wt" mode,
  11. checking for the file creation, write & read operations,
  12. checking for the file pointer position,
  13. checking for the file truncation when trying to open an existing file in "wt" mode,
  14. and fclose function
  15. */
  16. $file_path = __DIR__;
  17. require($file_path."/file.inc");
  18. create_files($file_path, 1, "text_with_new_line", 0755, 20, "wt", "007_variation_私はガラスを食べられます", 11, "bytes");
  19. $file = $file_path."/007_variation_私はガラスを食べられます11.tmp";
  20. $string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
  21. echo "*** Test fopen() & fclose() functions: with 'wt' mode ***\n";
  22. $file_handle = fopen($file, "wt"); //opening the file "wt" mode
  23. var_dump($file_handle); //Check for the content of handle
  24. var_dump( get_resource_type($file_handle) ); //Check for the type of resource
  25. var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the beginning of the file
  26. var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string
  27. var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file
  28. rewind($file_handle);
  29. var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: false
  30. var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the beginning of the file
  31. var_dump( fclose($file_handle) ); //Check for close operation on the file handle
  32. var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation
  33. var_dump( filesize($file) ); //Check for size of existing data file before opening the file in "wt" mode again, expected: size of content
  34. clearstatcache();
  35. fclose( fopen($file, "wt") ); //Opening the existing data file again in "wt" mode
  36. var_dump( filesize($file) ); //Check for size of existing data file after opening the file in "wt" mode again, expected: 0 bytes
  37. clearstatcache();
  38. unlink($file); //Deleting the file
  39. fclose( fopen($file, "wt") ); //Opening the non-existing file in "wt" mode, which will be created
  40. var_dump( file_exists($file) ); //Check for the existence of file
  41. echo "*** Done ***\n";
  42. --CLEAN--
  43. <?php
  44. $file_path = __DIR__;
  45. $file = $file_path."/007_variation_私はガラスを食べられます11.tmp";
  46. unlink($file);
  47. ?>
  48. --EXPECTF--
  49. *** Test fopen() & fclose() functions: with 'wt' mode ***
  50. resource(%d) of type (stream)
  51. string(6) "stream"
  52. int(0)
  53. int(37)
  54. int(37)
  55. Notice: fread(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  56. bool(false)
  57. int(0)
  58. bool(true)
  59. string(7) "Unknown"
  60. int(39)
  61. int(0)
  62. bool(true)
  63. *** Done ***