1--TEST--
2Test fopen and fclose() functions - usage variations - "r+b" mode
3--FILE--
4<?php
5
6/* Test fopen() and fclose(): Opening the file in "r+b" mode,
7   checking for the file creation, write & read operations,
8   checking for the file pointer position,
9   and fclose function
10*/
11$file_path = __DIR__;
12require($file_path."/file.inc");
13
14create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 18, "bytes");
15$file = $file_path."/007_variation18.tmp";
16$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
17
18echo "*** Test fopen() & fclose() functions:  with 'r+b' mode ***\n";
19$file_handle = fopen($file, "r+b");  //opening the file in "r+b" mode
20var_dump($file_handle);  //Check for the content of handle
21var_dump( get_resource_type($file_handle) );  //Check for the type of resource
22var_dump( ftell($file_handle) );  //Initial file pointer position, expected at the beginning of the file
23var_dump( fread($file_handle, 100) );  //Check for read operation
24var_dump( ftell($file_handle) );  //File pointer position after read operation, expected at the end of the file
25var_dump( fwrite($file_handle, $string) );  //Check for write operation; passes; expected:size of the $string
26var_dump( ftell($file_handle) );  //File pointer position after write operation, expected at the end of the file
27var_dump( fclose($file_handle) );  //Check for close operation on the file handle
28var_dump( get_resource_type($file_handle) );  //Check whether resource is lost after close operation
29echo "*** Done ***\n";
30?>
31--CLEAN--
32<?php
33unlink(__DIR__."/007_variation18.tmp");
34?>
35--EXPECTF--
36*** Test fopen() & fclose() functions:  with 'r+b' mode ***
37resource(%d) of type (stream)
38string(6) "stream"
39int(0)
40string(20) "line
41line of text
42li"
43int(20)
44int(37)
45int(57)
46bool(true)
47string(7) "Unknown"
48*** Done ***
49