diff options
author | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-03-09 13:20:40 +0100 |
---|---|---|
committer | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-03-09 13:20:40 +0100 |
commit | 32b97e3889c67dcb30a6400ab9cf57727f606e92 (patch) | |
tree | f7dfe173e0e25c68a41105612f30f688361b9c4e /test/Plugin/SkipNullValuesFormatterTest.php | |
parent | e79b1411559508b4111f649ac0618eeaa756d7c9 (diff) | |
download | csv-32b97e3889c67dcb30a6400ab9cf57727f606e92.zip csv-32b97e3889c67dcb30a6400ab9cf57727f606e92.tar.gz csv-32b97e3889c67dcb30a6400ab9cf57727f606e92.tar.bz2 |
update test coverage
Diffstat (limited to 'test/Plugin/SkipNullValuesFormatterTest.php')
-rw-r--r-- | test/Plugin/SkipNullValuesFormatterTest.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/Plugin/SkipNullValuesFormatterTest.php b/test/Plugin/SkipNullValuesFormatterTest.php new file mode 100644 index 0000000..97ac3be --- /dev/null +++ b/test/Plugin/SkipNullValuesFormatterTest.php @@ -0,0 +1,50 @@ +<?php + +namespace League\Csv\Test\Plugin; + +use League\Csv\Writer; +use League\Csv\Plugin\SkipNullValuesFormatter; +use LimitIterator; +use PHPUnit_Framework_TestCase; +use SplFileObject; +use SplTempFileObject; + +/** + * @group formatter + */ +class SkipNullValuesFormatterTest extends PHPUnit_Framework_TestCase +{ + private $csv; + + public function setUp() + { + $this->csv = Writer::createFromFileObject(new SplTempFileObject()); + } + + public function tearDown() + { + $csv = new SplFileObject(dirname(__DIR__).'/foo.csv', 'w'); + $csv->setCsvControl(); + $csv->fputcsv(["john", "doe", "john.doe@example.com"], ",", '"'); + $this->csv = null; + } + + + public function testInsertNullToSkipCell() + { + $expected = [ + ['john', 'doe', 'john.doe@example.com'], + 'john,doe,john.doe@example.com', + ['john', null, 'john.doe@example.com'], + ]; + $formatter = new SkipNullValuesFormatter(); + $this->csv->addFormatter($formatter); + 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); + } +} |