007_variation13-win32.phpt 2.3 KB

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