summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/WriterTest.php46
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()