007_variation5.phpt 2.0 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", 5, "bytes");
  13. $file = $file_path."/007_variation5.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; fails; expected: false
  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. var_dump( filesize($file) ); //Check that data hasn't over written; Expected: Size of (initial data + newly added data)
  26. unlink($file); //Deleting the file
  27. fclose( fopen($file, "a") ); //Opening the non-existing file in "a" mode, which will be created
  28. var_dump( file_exists($file) ); //Check for the existence of file
  29. echo "*** Done ***\n";
  30. --CLEAN--
  31. <?php
  32. unlink(__DIR__."/007_variation5.tmp");
  33. ?>
  34. --EXPECTF--
  35. *** Test fopen() & fclose() functions: with 'a' mode ***
  36. resource(%d) of type (stream)
  37. string(6) "stream"
  38. int(37)
  39. Notice: fread(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  40. bool(false)
  41. int(0)
  42. bool(true)
  43. string(7) "Unknown"
  44. int(57)
  45. bool(true)
  46. *** Done ***