1--TEST--
2Test fgetcsv() : usage variations - with default enclosure, line without any csv fields
3--FILE--
4<?php
5/*
6  Testing fgetcsv() to read a line without any csv fields from a file
7  when provided with default enclosure value
8*/
9
10echo "*** Testing fgetcsv() : with default enclosure, line without any csv fields ***\n";
11
12$filename = __DIR__ . '/fgetcsv_variation20.tmp';
13@unlink($filename);
14
15$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t",
16                     "a+", "a+b", "a+t",
17                     "w+", "w+b", "w+t",
18                     "x+", "x+b", "x+t");
19
20$loop_counter = 1;
21  for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
22    // create the file and add the content with has csv fields
23    if ( strstr($file_modes[$mode_counter], "r") ) {
24      $file_handle = fopen($filename, "w");
25    } else {
26      $file_handle = fopen($filename, $file_modes[$mode_counter] );
27    }
28    if ( !$file_handle ) {
29      echo "Error: failed to create file $filename!\n";
30      exit();
31    }
32    // write line of text
33    fwrite($file_handle, "This is line of text without csv fields\n");
34
35    // close the file if the mode to be used is read mode  and re-open using read mode
36    // else rewind the file pointer to beginning of the file
37    if ( strstr($file_modes[$mode_counter], "r" ) ) {
38      fclose($file_handle);
39      $file_handle = fopen($filename, $file_modes[$mode_counter]);
40    } else {
41      // rewind the file pointer to bof
42      rewind($file_handle);
43    }
44
45    echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n";
46
47    // call fgetcsv() to parse csv fields
48
49    // read the line which is without csv fields, provide delimiter and see the working of fgetcsv
50    $fp_pos = ftell($file_handle);
51    var_dump( fgetcsv($file_handle, 1024) );
52    // check the file pointer position and if eof
53    var_dump( ftell($file_handle) );
54    var_dump( feof($file_handle) );
55
56    // close the file
57    fclose($file_handle);
58    //delete file
59    unlink($filename);
60  } //end of mode loop
61
62echo "Done\n";
63?>
64--EXPECT--
65*** Testing fgetcsv() : with default enclosure, line without any csv fields ***
66
67-- Testing fgetcsv() with file opened using r mode --
68array(1) {
69  [0]=>
70  string(39) "This is line of text without csv fields"
71}
72int(40)
73bool(false)
74
75-- Testing fgetcsv() with file opened using rb mode --
76array(1) {
77  [0]=>
78  string(39) "This is line of text without csv fields"
79}
80int(40)
81bool(false)
82
83-- Testing fgetcsv() with file opened using rt mode --
84array(1) {
85  [0]=>
86  string(39) "This is line of text without csv fields"
87}
88int(40)
89bool(false)
90
91-- Testing fgetcsv() with file opened using r+ mode --
92array(1) {
93  [0]=>
94  string(39) "This is line of text without csv fields"
95}
96int(40)
97bool(false)
98
99-- Testing fgetcsv() with file opened using r+b mode --
100array(1) {
101  [0]=>
102  string(39) "This is line of text without csv fields"
103}
104int(40)
105bool(false)
106
107-- Testing fgetcsv() with file opened using r+t mode --
108array(1) {
109  [0]=>
110  string(39) "This is line of text without csv fields"
111}
112int(40)
113bool(false)
114
115-- Testing fgetcsv() with file opened using a+ mode --
116array(1) {
117  [0]=>
118  string(39) "This is line of text without csv fields"
119}
120int(40)
121bool(false)
122
123-- Testing fgetcsv() with file opened using a+b mode --
124array(1) {
125  [0]=>
126  string(39) "This is line of text without csv fields"
127}
128int(40)
129bool(false)
130
131-- Testing fgetcsv() with file opened using a+t mode --
132array(1) {
133  [0]=>
134  string(39) "This is line of text without csv fields"
135}
136int(40)
137bool(false)
138
139-- Testing fgetcsv() with file opened using w+ mode --
140array(1) {
141  [0]=>
142  string(39) "This is line of text without csv fields"
143}
144int(40)
145bool(false)
146
147-- Testing fgetcsv() with file opened using w+b mode --
148array(1) {
149  [0]=>
150  string(39) "This is line of text without csv fields"
151}
152int(40)
153bool(false)
154
155-- Testing fgetcsv() with file opened using w+t mode --
156array(1) {
157  [0]=>
158  string(39) "This is line of text without csv fields"
159}
160int(40)
161bool(false)
162
163-- Testing fgetcsv() with file opened using x+ mode --
164array(1) {
165  [0]=>
166  string(39) "This is line of text without csv fields"
167}
168int(40)
169bool(false)
170
171-- Testing fgetcsv() with file opened using x+b mode --
172array(1) {
173  [0]=>
174  string(39) "This is line of text without csv fields"
175}
176int(40)
177bool(false)
178
179-- Testing fgetcsv() with file opened using x+t mode --
180array(1) {
181  [0]=>
182  string(39) "This is line of text without csv fields"
183}
184int(40)
185bool(false)
186Done
187