SplFileObject_fputcsv_variation10.phpt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. --TEST--
  2. SplFileObject::fputcsv(): Usage variations -- with line without any CSV fields
  3. --FILE--
  4. <?php
  5. /* Testing fputcsv() to write to a file when the field has no CSV format */
  6. echo "*** Testing fputcsv() : with no CSV format in the field ***\n";
  7. /* the array is with three elements in it. Each element should be read as
  8. 1st element is delimiter, 2nd element is enclosure
  9. and 3rd element is csv fields
  10. */
  11. $fields = array( array('water_fruit\n'),
  12. array("water_fruit\n"),
  13. array("")
  14. );
  15. $file_path = __DIR__;
  16. $file = "$file_path/fputcsv_variation10.tmp";
  17. $file_modes = array ("r+", "r+b", "r+t",
  18. "a+", "a+b", "a+t",
  19. "w+", "w+b", "w+t",
  20. "x+", "x+b", "x+t");
  21. $loop_counter = 1;
  22. foreach ($fields as $field) {
  23. for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
  24. echo "\n-- file opened in $file_modes[$mode_counter] --\n";
  25. // create the file and add the content with has csv fields
  26. if ( strstr($file_modes[$mode_counter], "r") ) {
  27. $fo = new SplFileObject($file, 'w');
  28. } else {
  29. $fo = new SplFileObject($file, $file_modes[$mode_counter]);
  30. }
  31. $csv_field = $field;
  32. // write to a file in csv format
  33. var_dump( $fo->fputcsv($csv_field) );
  34. // check the file pointer position and eof
  35. var_dump( $fo->ftell() );
  36. var_dump( $fo->eof() );
  37. //close the file
  38. unset($fo);
  39. // print the file contents
  40. var_dump( file_get_contents($file) );
  41. //delete file
  42. unlink($file);
  43. } //end of mode loop
  44. } // end of foreach
  45. echo "Done\n";
  46. ?>
  47. --EXPECTF--
  48. *** Testing fputcsv() : with no CSV format in the field ***
  49. -- file opened in r+ --
  50. int(16)
  51. int(16)
  52. bool(false)
  53. string(16) ""water_fruit\n"
  54. "
  55. -- file opened in r+b --
  56. int(16)
  57. int(16)
  58. bool(false)
  59. string(16) ""water_fruit\n"
  60. "
  61. -- file opened in r+t --
  62. int(16)
  63. int(16)
  64. bool(false)
  65. string(%d) ""water_fruit\n"
  66. "
  67. -- file opened in a+ --
  68. int(16)
  69. int(16)
  70. bool(false)
  71. string(16) ""water_fruit\n"
  72. "
  73. -- file opened in a+b --
  74. int(16)
  75. int(16)
  76. bool(false)
  77. string(16) ""water_fruit\n"
  78. "
  79. -- file opened in a+t --
  80. int(16)
  81. int(16)
  82. bool(false)
  83. string(%d) ""water_fruit\n"
  84. "
  85. -- file opened in w+ --
  86. int(16)
  87. int(16)
  88. bool(false)
  89. string(16) ""water_fruit\n"
  90. "
  91. -- file opened in w+b --
  92. int(16)
  93. int(16)
  94. bool(false)
  95. string(16) ""water_fruit\n"
  96. "
  97. -- file opened in w+t --
  98. int(16)
  99. int(16)
  100. bool(false)
  101. string(%d) ""water_fruit\n"
  102. "
  103. -- file opened in x+ --
  104. int(16)
  105. int(16)
  106. bool(false)
  107. string(16) ""water_fruit\n"
  108. "
  109. -- file opened in x+b --
  110. int(16)
  111. int(16)
  112. bool(false)
  113. string(16) ""water_fruit\n"
  114. "
  115. -- file opened in x+t --
  116. int(16)
  117. int(16)
  118. bool(false)
  119. string(%d) ""water_fruit\n"
  120. "
  121. -- file opened in r+ --
  122. int(15)
  123. int(15)
  124. bool(false)
  125. string(15) ""water_fruit
  126. "
  127. "
  128. -- file opened in r+b --
  129. int(15)
  130. int(15)
  131. bool(false)
  132. string(15) ""water_fruit
  133. "
  134. "
  135. -- file opened in r+t --
  136. int(15)
  137. int(15)
  138. bool(false)
  139. string(%d) ""water_fruit
  140. "
  141. "
  142. -- file opened in a+ --
  143. int(15)
  144. int(15)
  145. bool(false)
  146. string(15) ""water_fruit
  147. "
  148. "
  149. -- file opened in a+b --
  150. int(15)
  151. int(15)
  152. bool(false)
  153. string(15) ""water_fruit
  154. "
  155. "
  156. -- file opened in a+t --
  157. int(15)
  158. int(15)
  159. bool(false)
  160. string(%d) ""water_fruit
  161. "
  162. "
  163. -- file opened in w+ --
  164. int(15)
  165. int(15)
  166. bool(false)
  167. string(15) ""water_fruit
  168. "
  169. "
  170. -- file opened in w+b --
  171. int(15)
  172. int(15)
  173. bool(false)
  174. string(15) ""water_fruit
  175. "
  176. "
  177. -- file opened in w+t --
  178. int(15)
  179. int(15)
  180. bool(false)
  181. string(%d) ""water_fruit
  182. "
  183. "
  184. -- file opened in x+ --
  185. int(15)
  186. int(15)
  187. bool(false)
  188. string(15) ""water_fruit
  189. "
  190. "
  191. -- file opened in x+b --
  192. int(15)
  193. int(15)
  194. bool(false)
  195. string(15) ""water_fruit
  196. "
  197. "
  198. -- file opened in x+t --
  199. int(15)
  200. int(15)
  201. bool(false)
  202. string(%d) ""water_fruit
  203. "
  204. "
  205. -- file opened in r+ --
  206. int(1)
  207. int(1)
  208. bool(false)
  209. string(1) "
  210. "
  211. -- file opened in r+b --
  212. int(1)
  213. int(1)
  214. bool(false)
  215. string(1) "
  216. "
  217. -- file opened in r+t --
  218. int(1)
  219. int(1)
  220. bool(false)
  221. string(%d) "
  222. "
  223. -- file opened in a+ --
  224. int(1)
  225. int(1)
  226. bool(false)
  227. string(1) "
  228. "
  229. -- file opened in a+b --
  230. int(1)
  231. int(1)
  232. bool(false)
  233. string(1) "
  234. "
  235. -- file opened in a+t --
  236. int(1)
  237. int(1)
  238. bool(false)
  239. string(%d) "
  240. "
  241. -- file opened in w+ --
  242. int(1)
  243. int(1)
  244. bool(false)
  245. string(1) "
  246. "
  247. -- file opened in w+b --
  248. int(1)
  249. int(1)
  250. bool(false)
  251. string(1) "
  252. "
  253. -- file opened in w+t --
  254. int(1)
  255. int(1)
  256. bool(false)
  257. string(%d) "
  258. "
  259. -- file opened in x+ --
  260. int(1)
  261. int(1)
  262. bool(false)
  263. string(1) "
  264. "
  265. -- file opened in x+b --
  266. int(1)
  267. int(1)
  268. bool(false)
  269. string(1) "
  270. "
  271. -- file opened in x+t --
  272. int(1)
  273. int(1)
  274. bool(false)
  275. string(%d) "
  276. "
  277. Done