diff options
author | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-02-19 08:49:17 +0100 |
---|---|---|
committer | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2015-02-19 08:52:39 +0100 |
commit | 0a493cecf0216f4c797671601251e3c1a6452ffa (patch) | |
tree | a23aeb9c31d7e05ccffa30bd4e5dc46cd27a5139 /test/Plugin/NullValidatorTest.php | |
parent | 959ede56075fec54891fad13744aeed6d42ad345 (diff) | |
download | csv-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.php | 46 |
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()); + } + } +} |