Annotation of embedaddon/php/ext/standard/tests/file/007_variation4.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test fopen and fclose() functions - usage variations - "w+" mode
! 3: --FILE--
! 4: <?php
! 5: /*
! 6: fopen() function:
! 7: Prototype: resource fopen(string $filename, string $mode
! 8: [, bool $use_include_path [, resource $context]] );
! 9: Description: Opens file or URL.
! 10: */
! 11: /*
! 12: fclose() function:
! 13: Prototype: bool fclose ( resource $handle );
! 14: Description: Closes an open file pointer
! 15: */
! 16:
! 17: /* Test fopen() and fclose(): Opening the file in "w+" mode,
! 18: checking for the file creation, write & read operations,
! 19: checking for the file pointer position,
! 20: checking for the file truncation when trying to open an existing file in "w+" mode,
! 21: and fclose function
! 22: */
! 23: $file_path = dirname(__FILE__);
! 24: require($file_path."/file.inc");
! 25:
! 26: create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 4, "bytes");
! 27: $file = $file_path."/007_variation4.tmp";
! 28: $string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
! 29:
! 30: echo "*** Test fopen() & fclose() functions: with 'w+' mode ***\n";
! 31: $file_handle = fopen($file, "w+"); //opening the file "w+" mode
! 32: var_dump($file_handle); //Check for the content of handle
! 33: var_dump( get_resource_type($file_handle) ); //Check for the type of resource
! 34: var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file
! 35: var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string
! 36: var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file
! 37: rewind($file_handle);
! 38: var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of file
! 39: var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file
! 40: var_dump( fclose($file_handle) ); //Check for close operation on the file handle
! 41: var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation
! 42:
! 43: var_dump( filesize($file) ); //Check for size of existing data file before opening the file in "w+" mode again, expected: size of content
! 44: clearstatcache();
! 45: fclose( fopen($file, "w+") ); //Opening the existing data file again in "w+" mode
! 46: var_dump( filesize($file) ); //Check for size of existing data file after opening the file in "w+" mode again, expected: 0 bytes
! 47: clearstatcache();
! 48:
! 49: unlink($file); //Deleting the file
! 50: fclose( fopen($file, "w+") ); //Opening the non-existing file in "w+" mode, which will be created
! 51: var_dump( file_exists($file) ); //Check for the existance of file
! 52: echo "*** Done ***\n";
! 53: --CLEAN--
! 54: <?php
! 55: unlink(dirname(__FILE__)."/007_variation4.tmp");
! 56: ?>
! 57: --EXPECTF--
! 58: *** Test fopen() & fclose() functions: with 'w+' mode ***
! 59: resource(%d) of type (stream)
! 60: string(6) "stream"
! 61: int(0)
! 62: int(37)
! 63: int(37)
! 64: string(37) "abcdefghij
! 65: mnopqrst uvwxyz
! 66: 0123456789"
! 67: int(37)
! 68: bool(true)
! 69: string(7) "Unknown"
! 70: int(37)
! 71: int(0)
! 72: bool(true)
! 73: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>