Skip to content

Commit

Permalink
bug fixing insertOne silently failing
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jul 10, 2017
1 parent 209c92c commit 2b023ec
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php

sudo: false
dist: trusty

matrix:
include:
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use League\Csv\Modifier\RowFilter;
use League\Csv\Modifier\StreamIterator;
use ReflectionMethod;
use RuntimeException;
use SplFileObject;
use Traversable;

Expand Down Expand Up @@ -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));
Expand Down
8 changes: 8 additions & 0 deletions test/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/data/newline.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
1,two,3,"new
line"
1,two,3,"new
line"

0 comments on commit 2b023ec

Please sign in to comment.