Skip to content

Commit be01691

Browse files
committed
changed class name and Bump version 1.0
1 parent 2dce131 commit be01691

File tree

3 files changed

+69
-34
lines changed

3 files changed

+69
-34
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ Of course, since a `SplFileObject` is returned you are free to modify the flags
4747
<?php
4848

4949

50-
use Bakame\Csv\Wrapper;
50+
use Bakame\Csv\CsvCodec;
5151

52-
$csv = new Wrapper;
53-
$csv->setDelimeter(',');
54-
$csv->setEnclosure('"');
55-
$csv->setEscape('\\');
52+
$codec = new CsvCodec;
53+
$codec->setDelimeter(',');
54+
$codec->setEnclosure('"');
55+
$codec->setEscape('\\');
5656

57-
$file = $csv->loadFile('path/to/my/csv/file.csv');
57+
$file = $codec->loadFile('path/to/my/csv/file.csv');
5858
//returns a SplFileObject object you can use to iterate throught your CSV data
5959

60-
$file = $csv->loadString(['foo,bar,baz', ['foo', 'bar', 'baz']]);
60+
$file = $codec->loadString(['foo,bar,baz', ['foo', 'bar', 'baz']]);
6161
//returns a SplTempFileObject object you can use to iterate throught your CSV data
6262

6363
```
@@ -75,7 +75,7 @@ If for any reason the
7575

7676
```php
7777

78-
$file = $csv->save([1,2,3,4], '/path/to/my/saved/csv/file.csv');
78+
$file = $codec->save([1,2,3,4], '/path/to/my/saved/csv/file.csv');
7979
//returns a SplFileObject object to manage the newly saved data
8080

8181
```
Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
<?php
2-
2+
/**
3+
* Bakame.csv - A lightweight CSV Coder/Decoder library
4+
*
5+
* @author Ignace Nyamagana Butera <nyamsprod@gmail.com>
6+
* @copyright 2013 Ignace Nyamagana Butera
7+
* @link https://github.com/nyamsprod/Bakame.csv
8+
* @license http://opensource.org/licenses/MIT
9+
* @version 1.0.0
10+
* @package Bakame.csv
11+
*
12+
* MIT LICENSE
13+
*
14+
* Permission is hereby granted, free of charge, to any person obtaining
15+
* a copy of this software and associated documentation files (the
16+
* "Software"), to deal in the Software without restriction, including
17+
* without limitation the rights to use, copy, modify, merge, publish,
18+
* distribute, sublicense, and/or sell copies of the Software, and to
19+
* permit persons to whom the Software is furnished to do so, subject to
20+
* the following conditions:
21+
*
22+
* The above copyright notice and this permission notice shall be
23+
* included in all copies or substantial portions of the Software.
24+
*
25+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32+
*/
333
namespace Bakame\Csv;
434

535
use SplFileInfo;
@@ -9,7 +39,12 @@
939
use InvalidArgumentException;
1040
use RuntimeException;
1141

12-
class Wrapper
42+
/**
43+
* A simple Coder/Decoder to ease CSV management in PHP 5.4+
44+
*
45+
* @package Bakame.csv
46+
*/
47+
class CsvCodec
1348
{
1449
/**
1550
* the field delimiter (one character only)
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,54 @@
55
use SplFileObject;
66
use 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

Comments
 (0)