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 fopen() function:
12 Prototype: resource fopen(string $filename, string $mode
13                            [, bool $use_include_path [, resource $context]] );
14 Description: Opens file or URL.
15*/
16/*
17 fclose() function:
18 Prototype: bool fclose ( resource $handle );
19 Description: Closes an open file pointer
20*/
21
22/* Test fopen() and fclose(): Opening the file in "wt" mode,
23   checking for the file creation, write & read operations,
24   checking for the file pointer position,
25   checking for the file truncation when trying to open an existing file in "wt" mode,
26   and fclose function
27*/
28$file_path = dirname(__FILE__);
29require($file_path."/file.inc");
30
31create_files($file_path, 1, "text_with_new_line", 0755, 20, "wt", "007_variation_私はガラスを食べられます", 11, "bytes");
32$file = $file_path."/007_variation_私はガラスを食べられます11.tmp";
33$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789";
34
35echo "*** Test fopen() & fclose() functions:  with 'wt' mode ***\n";
36$file_handle = fopen($file, "wt");  //opening the file "wt" mode
37var_dump($file_handle);  //Check for the content of handle
38var_dump( get_resource_type($file_handle) );  //Check for the type of resource
39var_dump( ftell($file_handle) );  //Initial file pointer position, expected at the beginning of the file
40var_dump( fwrite($file_handle, $string) );  //Check for write operation; passes; expected:size of the $string
41var_dump( ftell($file_handle) );  //File pointer position after write operation, expected at the end of the file
42rewind($file_handle);
43var_dump( fread($file_handle, 100) );  //Check for read operation; fails; expected: empty string
44var_dump( ftell($file_handle) );  //File pointer position after read operation, expected at the beginning of the file
45var_dump( fclose($file_handle) );  //Check for close operation on the file handle
46var_dump( get_resource_type($file_handle) );  //Check whether resource is lost after close operation
47
48var_dump( filesize($file) );  //Check for size of existing data file before opening the file in "wt" mode again, expected: size of content
49clearstatcache();
50fclose( fopen($file, "wt") );  //Opening the existing data file again in "wt" mode
51var_dump( filesize($file) );  //Check for size of existing data file after opening the file in "wt" mode again, expected: 0 bytes
52clearstatcache();
53
54unlink($file);  //Deleting the file
55fclose( fopen($file, "wt") );  //Opening the non-existing file in "wt" mode, which will be created
56var_dump( file_exists($file) );  //Check for the existence of file
57echo "*** Done ***\n";
58--CLEAN--
59<?php
60$file_path = dirname(__FILE__);
61$file = $file_path."/007_variation_私はガラスを食べられます11.tmp";
62unlink($file);
63?>
64--EXPECTF--
65*** Test fopen() & fclose() functions:  with 'wt' mode ***
66resource(%d) of type (stream)
67string(6) "stream"
68int(0)
69int(37)
70int(37)
71string(0) ""
72int(0)
73bool(true)
74string(7) "Unknown"
75int(39)
76int(0)
77bool(true)
78*** Done ***
79