diff --git a/.travis.yml b/.travis.yml index f664c2e5..569d738a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: php sudo: false +dist: trusty matrix: include: diff --git a/CHANGELOG.md b/CHANGELOG.md index 20c27727..08cfbb4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,26 @@ All Notable changes to `Csv` will be documented in this file +## 8.2.2 - TBD + +### Added + +- None + +### Deprecated + +- None + +### Fixed + +- `Writer::insertOne` was silently failing when inserted record in a CSV document in non-writing mode. +- bug fix docblock + + +### Removed + +- None + ## 8.2.1 - 2017-02-22 ### Added diff --git a/src/Writer.php b/src/Writer.php index 449f7264..b2f26f7e 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -16,6 +16,7 @@ use League\Csv\Modifier\RowFilter; use League\Csv\Modifier\StreamIterator; use ReflectionMethod; +use RuntimeException; use SplFileObject; use Traversable; @@ -109,7 +110,10 @@ public function insertOne($row) protected function addRow(array $row) { $this->initCsv(); - $this->fputcsv->invokeArgs($this->csv, $this->getFputcsvParameters($row)); + if (!$this->fputcsv->invokeArgs($this->csv, $this->getFputcsvParameters($row))) { + throw new RuntimeException('Unable to write record to the CSV document'); + } + if ("\n" !== $this->newline) { $this->csv->fseek(-1, SEEK_CUR); $this->csv->fwrite($this->newline, strlen($this->newline)); diff --git a/test/WriterTest.php b/test/WriterTest.php index 37a9a309..605fe2bf 100644 --- a/test/WriterTest.php +++ b/test/WriterTest.php @@ -66,6 +66,14 @@ public function testFailedSaveWithWrongType() $this->csv->insertAll(new stdClass()); } + /** + * @expectedException RuntimeException + */ + public function testInsertOneThrowsRuntimeException() + { + Writer::createFromPath('php://temp', 'r')->insertOne(['foo', 'bar']); + } + /** * @param $argument * @param $expected diff --git a/test/data/newline.csv b/test/data/newline.csv index a9da13c6..9645aebf 100644 --- a/test/data/newline.csv +++ b/test/data/newline.csv @@ -1,2 +1,4 @@ 1,two,3,"new line" +1,two,3,"new +line"