1--TEST--
2SplFileObject::fputcsv(): functionality tests
3--FILE--
4<?php
5$file = __DIR__ . '/SplFileObject_fputcsv.csv';
6$fo = new SplFileObject($file, 'w');
7
8$list = array (
9  0 => 'aaa,bbb',
10  1 => 'aaa,"bbb"',
11  2 => '"aaa","bbb"',
12  3 => 'aaa,bbb',
13  4 => '"aaa",bbb',
14  5 => '"aaa",   "bbb"',
15  6 => ',',
16  7 => 'aaa,',
17  8 => ',"aaa"',
18  9 => '"",""',
19  10 => '"""""",',
20  11 => '""""",aaa',
21  12 => 'aaa,bbb   ',
22  13 => 'aaa,"bbb   "',
23  14 => 'aaa"aaa","bbb"bbb',
24  15 => 'aaa"aaa""",bbb',
25  16 => 'aaa,"\\"bbb,ccc',
26  17 => 'aaa"\\"a","bbb"',
27  18 => '"\\"","aaa"',
28  19 => '"\\""",aaa',
29);
30
31foreach ($list as $v) {
32    $fo->fputcsv(explode(',', $v));
33}
34unset($fo);
35
36$res = file($file);
37foreach($res as &$val)
38{
39    $val = substr($val, 0, -1);
40}
41echo '$list = ';var_export($res);echo ";\n";
42
43$fp = fopen($file, "r");
44$res = array();
45while($l=fgetcsv($fp))
46{
47    $res[] = join(',',$l);
48}
49fclose($fp);
50
51echo '$list = ';var_export($res);echo ";\n";
52
53?>
54--CLEAN--
55<?php
56$file = __DIR__ . '/SplFileObject_fputcsv.csv';
57unlink($file);
58?>
59--EXPECT--
60$list = array (
61  0 => 'aaa,bbb',
62  1 => 'aaa,"""bbb"""',
63  2 => '"""aaa""","""bbb"""',
64  3 => 'aaa,bbb',
65  4 => '"""aaa""",bbb',
66  5 => '"""aaa""","   ""bbb"""',
67  6 => ',',
68  7 => 'aaa,',
69  8 => ',"""aaa"""',
70  9 => '"""""",""""""',
71  10 => '"""""""""""""",',
72  11 => '"""""""""""",aaa',
73  12 => 'aaa,"bbb   "',
74  13 => 'aaa,"""bbb   """',
75  14 => '"aaa""aaa""","""bbb""bbb"',
76  15 => '"aaa""aaa""""""",bbb',
77  16 => 'aaa,"""\\"bbb",ccc',
78  17 => '"aaa""\\"a""","""bbb"""',
79  18 => '"""\\"""","""aaa"""',
80  19 => '"""\\"""""",aaa',
81);
82$list = array (
83  0 => 'aaa,bbb',
84  1 => 'aaa,"bbb"',
85  2 => '"aaa","bbb"',
86  3 => 'aaa,bbb',
87  4 => '"aaa",bbb',
88  5 => '"aaa",   "bbb"',
89  6 => ',',
90  7 => 'aaa,',
91  8 => ',"aaa"',
92  9 => '"",""',
93  10 => '"""""",',
94  11 => '""""",aaa',
95  12 => 'aaa,bbb   ',
96  13 => 'aaa,"bbb   "',
97  14 => 'aaa"aaa","bbb"bbb',
98  15 => 'aaa"aaa""",bbb',
99  16 => 'aaa,"\\"bbb,ccc',
100  17 => 'aaa"\\"a","bbb"',
101  18 => '"\\"","aaa"',
102  19 => '"\\""",aaa',
103);
104