007_variation12-win32.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --TEST--
  2. Test fopen and fclose() functions - usage variations - "w+t" 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. /*
  11. fopen() function:
  12. Prototype: resource fopen(string $filename, string $mode
  13. [, bool $use_include_path [, resource $context]] );
  14. Description: Opens file or URL.
  15. */
  16. /*
  17. fclose() function:
  18. Prototype: bool fclose ( resource $handle );
  19. Description: Closes an open file pointer
  20. */
  21. /* Test fopen() and fclose(): Opening the file in "w+t" mode,
  22. checking for the file creation, write & read operations,
  23. checking for the file pointer position,
  24. checking for the file truncation when trying to open an existing file in "w+t" mode,
  25. and fclose function
  26. */
  27. $file_path = dirname(__FILE__);
  28. require($file_path."/file.inc");
  29. create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 12, "bytes");
  30. $file = $file_path."/007_variation12.tmp";
  31. $string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
  32. echo "*** Test fopen() & fclose() functions: with 'w+t' mode ***\n";
  33. $file_handle = fopen($file, "w+t"); //opening the file "w+t" mode
  34. var_dump($file_handle); //Check for the content of handle
  35. var_dump( get_resource_type($file_handle) ); //Check for the type of resource
  36. var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the beginning of the file
  37. var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string
  38. var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file
  39. rewind($file_handle);
  40. var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of file
  41. var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file
  42. var_dump( fclose($file_handle) ); //Check for close operation on the file handle
  43. var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation
  44. var_dump( filesize($file) ); //Check for size of existing data file before opening the file in "w+t" mode again, expected: size of content
  45. clearstatcache();
  46. fclose( fopen($file, "w+t") ); //Opening the existing data file again in "w+t" mode
  47. var_dump( filesize($file) ); //Check for size of existing data file after opening the file in "w+t" mode again, expected: 0 bytes
  48. clearstatcache();
  49. unlink($file); //Deleting the file
  50. fclose( fopen($file, "w+t") ); //Opening the non-existing file in "w+t" mode, which will be created
  51. var_dump( file_exists($file) ); //Check for the existence of file
  52. echo "*** Done ***\n";
  53. --CLEAN--
  54. <?php
  55. unlink(dirname(__FILE__)."/007_variation12.tmp");
  56. ?>
  57. --EXPECTF--
  58. *** Test fopen() & fclose() functions: with 'w+t' mode ***
  59. resource(%d) of type (stream)
  60. string(6) "stream"
  61. int(0)
  62. int(37)
  63. int(37)
  64. string(37) "abcdefghij
  65. mnopqrst uvwxyz
  66. 0123456789"
  67. int(37)
  68. bool(true)
  69. string(7) "Unknown"
  70. int(39)
  71. int(0)
  72. bool(true)
  73. *** Done ***