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