007_variation6.phpt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --TEST--
  2. Test fopen and fclose() functions - usage variations - "a+" mode
  3. --FILE--
  4. <?php
  5. /* Test fopen() and fclose(): Opening the file in "a+" 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", 6, "bytes");
  13. $file = $file_path."/007_variation6.tmp";
  14. $string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
  15. echo "*** Test fopen() & fclose() functions: with 'a+' mode ***\n";
  16. $file_handle = fopen($file, "a+"); //opening the file "a+" 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( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string
  20. rewind($file_handle);
  21. var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of file
  22. var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file
  23. var_dump( fclose($file_handle) ); //Check for close operation on the file handle
  24. var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation
  25. unlink($file); //Deleting the file
  26. fclose( fopen($file, "a+") ); //Opening the non-existing file in "a+" mode, which will be created
  27. var_dump( file_exists($file) ); //Check for the existence of file
  28. echo "*** Done ***\n";
  29. --CLEAN--
  30. <?php
  31. unlink(__DIR__."/007_variation6.tmp");
  32. ?>
  33. --EXPECTF--
  34. *** Test fopen() & fclose() functions: with 'a+' mode ***
  35. resource(%d) of type (stream)
  36. string(6) "stream"
  37. int(37)
  38. string(57) "line
  39. line of text
  40. liabcdefghij
  41. mnopqrst uvwxyz
  42. 0123456789"
  43. int(57)
  44. bool(true)
  45. string(7) "Unknown"
  46. bool(true)
  47. *** Done ***