1--TEST--
2Test fopen and fclose() functions - usage variations - "w+t" mode
3--SKIPIF--
4<?php
5if( substr(PHP_OS, 0, 3) == "WIN" )
6  die('skip Do not run on Windows');
7?>
8--FILE--
9<?php
10
11/* Test fopen() and fclose(): Opening the file in "w+t" mode,
12   checking for the file creation, write & read operations,
13   checking for the file pointer position,
14   checking for the file truncation when trying to open an existing file in "w+t" mode,
15   and fclose function
16*/
17$file_path = __DIR__;
18require($file_path."/file.inc");
19
20create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 12, "bytes");
21$file = $file_path."/007_variation12.tmp";
22$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
23
24echo "*** Test fopen() & fclose() functions:  with 'w+t' mode ***\n";
25$file_handle = fopen($file, "w+t");  //opening the file "w+t" mode
26var_dump($file_handle);  //Check for the content of handle
27var_dump( get_resource_type($file_handle) );  //Check for the type of resource
28var_dump( ftell($file_handle) );  //Initial file pointer position, expected at the beginning of the file
29var_dump( fwrite($file_handle, $string) );  //Check for write operation; passes; expected:size of the $string
30var_dump( ftell($file_handle) );  //File pointer position after write operation, expected at the end of the file
31rewind($file_handle);
32var_dump( fread($file_handle, 100) );  //Check for read operation; passes; expected: content of file
33var_dump( ftell($file_handle) );  //File pointer position after read operation, expected at the end of the file
34var_dump( fclose($file_handle) );  //Check for close operation on the file handle
35var_dump( get_resource_type($file_handle) );  //Check whether resource is lost after close operation
36
37var_dump( filesize($file) );  //Check for size of existing data file before opening the file in "w+t" mode again, expected: size of content
38clearstatcache();
39fclose( fopen($file, "w+t") );  //Opening the existing data file again in "w+t" mode
40var_dump( filesize($file) );  //Check for size of existing data file after opening the file in "w+t" mode again, expected: 0 bytes
41clearstatcache();
42
43unlink($file);  //Deleting the file
44fclose( fopen($file, "w+t") );  //Opening the non-existing file in "w+t" mode, which will be created
45var_dump( file_exists($file) );  //Check for the existence of file
46echo "*** Done ***\n";
47--CLEAN--
48<?php
49unlink(__DIR__."/007_variation12.tmp");
50?>
51--EXPECTF--
52*** Test fopen() & fclose() functions:  with 'w+t' mode ***
53resource(%d) of type (stream)
54string(6) "stream"
55int(0)
56int(37)
57int(37)
58string(37) "abcdefghij
59mnopqrst	uvwxyz
600123456789"
61int(37)
62bool(true)
63string(7) "Unknown"
64int(37)
65int(0)
66bool(true)
67*** Done ***
68