summaryrefslogtreecommitdiffstats
path: root/test/Plugin/NullValidatorTest.php
diff options
context:
space:
mode:
authorIgnace Nyamagana Butera <nyamsprod@gmail.com>2015-02-19 08:49:17 +0100
committerIgnace Nyamagana Butera <nyamsprod@gmail.com>2015-02-19 08:52:39 +0100
commit0a493cecf0216f4c797671601251e3c1a6452ffa (patch)
treea23aeb9c31d7e05ccffa30bd4e5dc46cd27a5139 /test/Plugin/NullValidatorTest.php
parent959ede56075fec54891fad13744aeed6d42ad345 (diff)
downloadcsv-0a493cecf0216f4c797671601251e3c1a6452ffa.zip
csv-0a493cecf0216f4c797671601251e3c1a6452ffa.tar.gz
csv-0a493cecf0216f4c797671601251e3c1a6452ffa.tar.bz2
final package structure
Diffstat (limited to 'test/Plugin/NullValidatorTest.php')
-rw-r--r--test/Plugin/NullValidatorTest.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/Plugin/NullValidatorTest.php b/test/Plugin/NullValidatorTest.php
new file mode 100644
index 0000000..fd0336c
--- /dev/null
+++ b/test/Plugin/NullValidatorTest.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace League\Csv\Test\Plugin;
+
+use League\Csv\Exception\InvalidRowException;
+use League\Csv\Plugin\ForbiddenNullValuesValidator;
+use League\Csv\Writer;
+use PHPUnit_Framework_TestCase;
+use SplFileObject;
+use SplTempFileObject;
+
+/**
+ * @group validators
+ */
+class NullValidatorTest 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 testInsertNullThrowsException()
+ {
+ $validator = new ForbiddenNullValuesValidator();
+ $validator_name = 'null_as_exception';
+ $expected = ['john', null, 'john.doe@example.com'];
+ $this->csv->addValidator($validator, $validator_name);
+ try {
+ $this->csv->insertOne($expected);
+ } catch (InvalidRowException $e) {
+ $this->assertSame($validator_name, $e->getName());
+ $this->assertSame($expected, $e->getData());
+ $this->assertSame('row validation failed', $e->getMessage());
+ }
+ }
+}