007_variation13-win32.phpt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. Test fopen and fclose() functions - usage variations - "at" 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 "at" mode,
  11. checking for the file creation, write & read operations,
  12. checking for the file pointer position,
  13. and fclose function
  14. */
  15. $file_path = __DIR__;
  16. require($file_path."/file.inc");
  17. create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 13, "bytes");
  18. $file = $file_path."/007_variation13.tmp";
  19. $string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
  20. echo "*** Test fopen() & fclose() functions: with 'at' mode ***\n";
  21. $file_handle = fopen($file, "at"); //opening the file "at" mode
  22. var_dump($file_handle); //Check for the content of handle
  23. var_dump( get_resource_type($file_handle) ); //Check for the type of resource
  24. var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string
  25. rewind($file_handle);
  26. var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: false
  27. var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file
  28. var_dump( fclose($file_handle) ); //Check for close operation on the file handle
  29. var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation
  30. var_dump( filesize($file) ); //Check that data hasn't over written; Expected: Size of (initial data + newly added data)
  31. unlink($file); //Deleting the file
  32. fclose( fopen($file, "at") ); //Opening the non-existing file in "at" mode, which will be created
  33. var_dump( file_exists($file) ); //Check for the existence of file
  34. echo "*** Done ***\n";
  35. --CLEAN--
  36. <?php
  37. unlink(__DIR__."/007_variation13.tmp");
  38. ?>
  39. --EXPECTF--
  40. *** Test fopen() & fclose() functions: with 'at' mode ***
  41. resource(%d) of type (stream)
  42. string(6) "stream"
  43. int(37)
  44. Notice: fread(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
  45. bool(false)
  46. int(0)
  47. bool(true)
  48. string(7) "Unknown"
  49. int(59)
  50. bool(true)
  51. *** Done ***