diff options
author | ignace nyamagana butera <nyamsprod@gmail.com> | 2014-03-22 13:34:59 +0100 |
---|---|---|
committer | ignace nyamagana butera <nyamsprod@gmail.com> | 2014-03-24 21:39:41 +0100 |
commit | 774c56e5ca7c86895ce5b05e8b93c6c64834e7f2 (patch) | |
tree | 1e2cade7a3a6c838802aea27f3f99452dc6c1474 /test | |
parent | d271a29ce97c03c9d4a46b8c8b801c78ed571ca9 (diff) | |
download | csv-774c56e5ca7c86895ce5b05e8b93c6c64834e7f2.zip csv-774c56e5ca7c86895ce5b05e8b93c6c64834e7f2.tar.gz csv-774c56e5ca7c86895ce5b05e8b93c6c64834e7f2.tar.bz2 |
adding null value handling in Writer class #28
Diffstat (limited to 'test')
-rw-r--r-- | test/WriterTest.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/WriterTest.php b/test/WriterTest.php index e22cd9a..2e87c91 100644 --- a/test/WriterTest.php +++ b/test/WriterTest.php @@ -4,6 +4,7 @@ namespace League\Csv\Test; use SplTempFileObject; use ArrayIterator; +use LimitIterator; use PHPUnit_Framework_TestCase; use DateTime; use League\Csv\Writer; @@ -39,6 +40,51 @@ class WriterTest extends PHPUnit_Framework_TestCase } /** + * @expectedException OutOfBoundsException + */ + public function testSetterGetterNullBehavior() + { + $this->csv->setNullHandling(Writer::NULL_AS_SKIP_CELL); + $this->assertSame(Writer::NULL_AS_SKIP_CELL, $this->csv->getNullHandling()); + + $this->csv->setNullHandling(23); + } + + public function testInsertNullToSkipCell() + { + $expected = [ + ['john', 'doe', 'john.doe@example.com'], + 'john,doe,john.doe@example.com', + ['john', null, 'john.doe@example.com'], + ]; + $this->csv->setNullHandling(Writer::NULL_AS_SKIP_CELL); + foreach ($expected as $row) { + $this->csv->insertOne($row); + } + $iterator = new LimitIterator($this->csv->getIterator(), 2, 1); + $iterator->rewind(); + $res = $iterator->getInnerIterator()->current(); + $this->assertSame(['john', 'john.doe@example.com'], $res); + } + + public function testInsertNullToEmpty() + { + $expected = [ + ['john', 'doe', 'john.doe@example.com'], + 'john,doe,john.doe@example.com', + ['john', null, 'john.doe@example.com'], + ]; + $this->csv->setNullHandling(Writer::NULL_AS_EMPTY); + foreach ($expected as $row) { + $this->csv->insertOne($row); + } + $iterator = new LimitIterator($this->csv->getIterator(), 2, 1); + $iterator->rewind(); + $res = $iterator->getInnerIterator()->current(); + $this->assertSame(['john', '', 'john.doe@example.com'], $res); + } + + /** * @expectedException InvalidArgumentException */ public function testFailedInsertWithWrongData() |