55use SplFileObject ;
66use SplFileInfo ;
77
8- class WrapperTest extends \PHPUnit_Framework_TestCase
8+ class CsvCodecTest extends \PHPUnit_Framework_TestCase
99{
1010
11- private $ wrapper ;
11+ private $ codec ;
1212
1313 public function setUp ()
1414 {
15- $ this ->wrapper = new Wrapper ;
15+ $ this ->codec = new CsvCodec ;
1616 }
1717
1818 /**
1919 * @expectedException InvalidArgumentException
2020 */
2121 public function testDelimeter ()
2222 {
23- $ this ->wrapper ->setDelimiter ('o ' );
24- $ this ->assertSame ('o ' , $ this ->wrapper ->getDelimiter ());
23+ $ this ->codec ->setDelimiter ('o ' );
24+ $ this ->assertSame ('o ' , $ this ->codec ->getDelimiter ());
2525
26- $ this ->wrapper ->setDelimiter ('foo ' );
26+ $ this ->codec ->setDelimiter ('foo ' );
2727 }
2828
2929 /**
3030 * @expectedException InvalidArgumentException
3131 */
3232 public function testEscape ()
3333 {
34- $ this ->wrapper ->setEscape ('o ' );
35- $ this ->assertSame ('o ' , $ this ->wrapper ->getEscape ());
34+ $ this ->codec ->setEscape ('o ' );
35+ $ this ->assertSame ('o ' , $ this ->codec ->getEscape ());
3636
37- $ this ->wrapper ->setEscape ('foo ' );
37+ $ this ->codec ->setEscape ('foo ' );
3838 }
3939
4040 /**
4141 * @expectedException InvalidArgumentException
4242 */
4343 public function testEnclosure ()
4444 {
45- $ this ->wrapper ->setEnclosure ('o ' );
46- $ this ->assertSame ('o ' , $ this ->wrapper ->getEnclosure ());
45+ $ this ->codec ->setEnclosure ('o ' );
46+ $ this ->assertSame ('o ' , $ this ->codec ->getEnclosure ());
4747
48- $ this ->wrapper ->setEnclosure ('foo ' );
48+ $ this ->codec ->setEnclosure ('foo ' );
4949 }
5050
5151 public function testloadString ()
5252 {
5353 $ expected = ['foo ' , 'bar ' , 'baz ' ];
5454 $ str = "foo,bar,baz \nfoo,bar,baz " ;
55- $ res = $ this ->wrapper ->loadString ($ str );
55+ $ res = $ this ->codec ->loadString ($ str );
5656 $ this ->assertInstanceof ('SplTempFileObject ' , $ res );
5757 foreach ($ res as $ row ) {
5858 $ this ->assertSame ($ expected , $ row );
@@ -64,22 +64,22 @@ public function testloadString()
6464 */
6565 public function testCreateException ()
6666 {
67- $ this ->wrapper ->create (__DIR__ .'/bar.csv ' , 'z ' );
67+ $ this ->codec ->create (__DIR__ .'/bar.csv ' , 'z ' );
6868 }
6969
7070 /**
7171 * @expectedException RuntimeException
7272 */
7373 public function testCreateException2 ()
7474 {
75- $ this ->wrapper ->create ('/etc/foo.csv ' , 'w ' );
75+ $ this ->codec ->create ('/etc/foo.csv ' , 'w ' );
7676 }
7777
7878 public function testloadFile ()
7979 {
8080 $ expected = ['foo ' , 'bar ' , 'baz ' ];
8181 $ file = __DIR__ .'/foo.csv ' ;
82- $ res = $ this ->wrapper ->loadFile ($ file );
82+ $ res = $ this ->codec ->loadFile ($ file );
8383 $ this ->assertInstanceof ('SplFileObject ' , $ res );
8484 $ this ->assertSame ($ file , $ res ->getRealPath ());
8585 $ res ->setFlags (SplFileObject::READ_CSV |SplFileObject::READ_AHEAD |SplFileObject::SKIP_EMPTY );
@@ -96,7 +96,7 @@ public function testloadFile()
9696 */
9797 public function testloadFileException ()
9898 {
99- $ this ->wrapper ->loadFile (__DIR__ .'/foo.csv ' , 'w ' );
99+ $ this ->codec ->loadFile (__DIR__ .'/foo.csv ' , 'w ' );
100100 }
101101
102102 public function testSaveArray ()
@@ -106,12 +106,12 @@ public function testSaveArray()
106106 'foo,bar, baz ' ,
107107 ];
108108 $ expected = ['foo ' , 'bar ' , 'baz ' ];
109- $ this ->wrapper
109+ $ this ->codec
110110 ->setDelimiter (', ' )
111111 ->setEnclosure ('" ' )
112112 ->setEscape ("\\" );
113113
114- $ res = $ this ->wrapper ->save ($ arr , 'php://temp ' );
114+ $ res = $ this ->codec ->save ($ arr , 'php://temp ' );
115115 $ this ->assertInstanceof ('SplFileObject ' , $ res );
116116 foreach ($ res as $ row ) {
117117 $ this ->assertSame ($ expected , $ row );
@@ -126,7 +126,7 @@ public function testSaveTransversable()
126126 ];
127127 $ expected = ['foo ' , 'bar ' , 'baz ' ];
128128 $ obj = new \ArrayObject ($ arr );
129- $ res = $ this ->wrapper ->save ($ obj , 'php://temp ' );
129+ $ res = $ this ->codec ->save ($ obj , 'php://temp ' );
130130 $ this ->assertInstanceof ('\SplFileObject ' , $ res );
131131 foreach ($ res as $ row ) {
132132 $ this ->assertSame ($ expected , $ row );
@@ -138,29 +138,29 @@ public function testSaveTransversable()
138138 */
139139 public function testSaveExceptionBadData ()
140140 {
141- $ this ->wrapper ->save ('foo ' , 'php://temp ' );
141+ $ this ->codec ->save ('foo ' , 'php://temp ' );
142142 }
143143
144144 /**
145145 * @expectedException InvalidArgumentException
146146 */
147147 public function testSaveExceptionBadMode ()
148148 {
149- $ this ->wrapper ->save (['foo ' ], 'php://temp ' , 'r ' );
149+ $ this ->codec ->save (['foo ' ], 'php://temp ' , 'r ' );
150150 }
151151
152152 /**
153153 * @expectedException InvalidArgumentException
154154 */
155155 public function testSaveExceptionBadPath ()
156156 {
157- $ this ->wrapper ->save (['foo ' ], ['bar ' ]);
157+ $ this ->codec ->save (['foo ' ], ['bar ' ]);
158158 }
159159
160160 public function testSaveSplFileInfo ()
161161 {
162162 $ obj = new SplFileInfo ('php://temp ' );
163- $ res = $ this ->wrapper ->save (['foo ' ], $ obj );
163+ $ res = $ this ->codec ->save (['foo ' ], $ obj );
164164 $ this ->assertInstanceof ('\SplFileObject ' , $ res );
165165 }
166166}
0 commit comments