diff options
author | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-06-04 14:57:58 +0200 |
---|---|---|
committer | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-06-04 14:57:58 +0200 |
commit | 8dc8628111e31030152ecc1d926985ddf11c3c78 (patch) | |
tree | fa9f6c57352ed13df1899b81ce7cb7fa607b14cd /test | |
parent | d9c9759cd22bef4b2d1801617856d8fdcd4eece0 (diff) | |
download | csv-8dc8628111e31030152ecc1d926985ddf11c3c78.zip csv-8dc8628111e31030152ecc1d926985ddf11c3c78.tar.gz csv-8dc8628111e31030152ecc1d926985ddf11c3c78.tar.bz2 |
Add missing test
Test regarding #102 issue added
Diffstat (limited to 'test')
-rw-r--r-- | test/ReaderTest.php | 51 | ||||
-rw-r--r-- | test/StreamFilterTest.php | 21 |
2 files changed, 69 insertions, 3 deletions
diff --git a/test/ReaderTest.php b/test/ReaderTest.php index 33d3c41..cca83a7 100644 --- a/test/ReaderTest.php +++ b/test/ReaderTest.php @@ -253,13 +253,13 @@ class ReaderTest extends PHPUnit_Framework_TestCase public function testStripBOMWithFetchAssoc() { - $expected = [ + $source = [ [Reader::BOM_UTF16_LE.'john', 'doe', 'john.doe@example.com', ], ['jane', 'doe', 'jane.doe@example.com', ], ]; $tmp = new SplTempFileObject(); - foreach ($expected as $row) { + foreach ($source as $row) { $tmp->fputcsv($row); } $csv = Reader::createFromFileObject($tmp); @@ -269,6 +269,53 @@ class ReaderTest extends PHPUnit_Framework_TestCase $this->assertSame('john', $res[0]); } + public function testStripBOMWithEnclosureFetchAssoc() + { + $expected = ["parent name", "parentA"]; + $source = Reader::BOM_UTF8.'"parent name","child name","title" + "parentA","childA","titleA"'; + $csv = Reader::createFromString($source); + $csv->stripBom(true); + $expected = [ + ["parent name" => "parentA", "child name" => "childA", "title" => "titleA"], + ]; + $this->assertSame($expected, $csv->fetchAssoc()); + } + + public function testStripBOMWithEnclosureFetchColumn() + { + $expected = ["parent name", "parentA"]; + $source = Reader::BOM_UTF8.'"parent name","child name","title" + "parentA","childA","titleA"'; + $csv = Reader::createFromString($source); + $csv->stripBom(true); + $this->assertSame($expected, $csv->fetchColumn()); + } + + public function testStripBOMWithEnclosureFetchAll() + { + $source = Reader::BOM_UTF8.'"parent name","child name","title" + "parentA","childA","titleA"'; + $csv = Reader::createFromString($source); + $csv->stripBom(true); + $expected = [ + ["parent name", "child name", "title"], + ["parentA", "childA", "titleA"], + ]; + $this->assertSame($expected, $csv->fetchAll()); + } + + public function testStripBOMWithEnclosureFetchOne() + { + $source = Reader::BOM_UTF8.'"parent name","child name","title" + "parentA","childA","titleA"'; + $csv = Reader::createFromString($source); + $csv->stripBom(true); + $this->assertSame(Reader::BOM_UTF8, $csv->getInputBom()); + $expected = ["parent name", "child name", "title"]; + $this->assertEquals($expected, $csv->fetchOne()); + } + /** * @expectedException \InvalidArgumentException */ diff --git a/test/StreamFilterTest.php b/test/StreamFilterTest.php index 56862ed..ead990a 100644 --- a/test/StreamFilterTest.php +++ b/test/StreamFilterTest.php @@ -13,19 +13,30 @@ use SplTempFileObject; */ class StreamFilterTest extends PHPUnit_Framework_TestCase { - public function testInitStreamFilter() + public function testInitStreamFilterWithWriterStream() { $filter = 'php://filter/write=string.rot13/resource='.__DIR__.'/foo.csv'; $csv = Reader::createFromPath($filter); $this->assertTrue($csv->hasStreamFilter('string.rot13')); $this->assertSame(STREAM_FILTER_WRITE, $csv->getStreamFilterMode()); + } + public function testInitStreamFilterWithReaderStream() + { $filter = 'php://filter/read=string.toupper/resource='.__DIR__.'/foo.csv'; $csv = Reader::createFromPath($filter); $this->assertTrue($csv->hasStreamFilter('string.toupper')); $this->assertSame(STREAM_FILTER_READ, $csv->getStreamFilterMode()); } + public function testInitStreamFilterWithBothStream() + { + $filter = 'php://filter/string.toupper/resource='.__DIR__.'/foo.csv'; + $csv = Reader::createFromPath($filter); + $this->assertTrue($csv->hasStreamFilter('string.toupper')); + $this->assertSame(STREAM_FILTER_ALL, $csv->getStreamFilterMode()); + } + /** * @expectedException LogicException */ @@ -101,4 +112,12 @@ class StreamFilterTest extends PHPUnit_Framework_TestCase $csv->prependStreamFilter('string.toupper'); $this->assertFalse($csv->getIterator()->getRealPath()); } + + + public function testGetFilterPathWithAllStream() + { + $filter = 'php://filter/string.toupper/resource='.__DIR__.'/foo.csv'; + $csv = Reader::createFromPath($filter); + $this->assertFalse($csv->getIterator()->getRealPath()); + } } |