1--TEST--
2Test fopen and fclose() functions - usage variations - "wt" mode
3--SKIPIF--
4<?php
5if( substr(PHP_OS, 0, 3) != "WIN" )
6  die('skip Run only on Windows');
7?>
8--FILE--
9<?php
10
11/* Test fopen() and fclose(): Opening the file in "wt" 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 "wt" 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, "wt", "007_variation_私はガラスを食べられます", 11, "bytes");
21$file = $file_path."/007_variation_私はガラスを食べられます11.tmp";
22$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
23
24echo "*** Test fopen() & fclose() functions:  with 'wt' mode ***\n";
25$file_handle = fopen($file, "wt");  //opening the file "wt" 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; fails; expected: false
33var_dump( ftell($file_handle) );  //File pointer position after read operation, expected at the beginning 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 "wt" mode again, expected: size of content
38clearstatcache();
39fclose( fopen($file, "wt") );  //Opening the existing data file again in "wt" mode
40var_dump( filesize($file) );  //Check for size of existing data file after opening the file in "wt" mode again, expected: 0 bytes
41clearstatcache();
42
43unlink($file);  //Deleting the file
44fclose( fopen($file, "wt") );  //Opening the non-existing file in "wt" mode, which will be created
45var_dump( file_exists($file) );  //Check for the existence of file
46echo "*** Done ***\n";
47--CLEAN--
48<?php
49$file_path = __DIR__;
50$file = $file_path."/007_variation_私はガラスを食べられます11.tmp";
51unlink($file);
52?>
53--EXPECTF--
54*** Test fopen() & fclose() functions:  with 'wt' mode ***
55resource(%d) of type (stream)
56string(6) "stream"
57int(0)
58int(37)
59int(37)
60
61Notice: fread(): Read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
62bool(false)
63int(0)
64bool(true)
65string(7) "Unknown"
66int(39)
67int(0)
68bool(true)
69*** Done ***
70