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