007_variation10.phpt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --TEST--
  2. Test fopen and fclose() functions - usage variations - "r+t" mode
  3. --FILE--
  4. <?php
  5. /* Test fopen() and fclose(): Opening the file in "r+t" mode,
  6. checking for the file creation, write & read operations,
  7. checking for the file pointer position,
  8. and fclose function
  9. */
  10. $file_path = __DIR__;
  11. require($file_path."/file.inc");
  12. create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 10, "bytes");
  13. $file = $file_path."/007_variation10.tmp";
  14. $string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
  15. echo "*** Test fopen() & fclose() functions: with 'r+t' mode ***\n";
  16. $file_handle = fopen($file, "r+t"); //opening the file in "r+t" mode
  17. var_dump($file_handle); //Check for the content of handle
  18. var_dump( get_resource_type($file_handle) ); //Check for the type of resource
  19. var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the beginning of the file
  20. var_dump( fread($file_handle, 100) ); //Check for read operation
  21. var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file
  22. var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string
  23. var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file
  24. var_dump( fclose($file_handle) ); //Check for close operation on the file handle
  25. var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation
  26. echo "*** Done ***\n";
  27. --CLEAN--
  28. <?php
  29. unlink(__DIR__."/007_variation10.tmp");
  30. ?>
  31. --EXPECTF--
  32. *** Test fopen() & fclose() functions: with 'r+t' mode ***
  33. resource(%d) of type (stream)
  34. string(6) "stream"
  35. int(0)
  36. string(20) "line
  37. line of text
  38. li"
  39. int(20)
  40. int(37)
  41. int(57)
  42. bool(true)
  43. string(7) "Unknown"
  44. *** Done ***