always write rows even with no cells #492

This commit is contained in:
madflow authored and Adrien Loison committed 2017-11-10 11:21:57 +01:00
1 parent 8aec9ea992
commit 7367b89384
2 files changed
+2 -5

No files matched your search

-3
View File
@@ -178,8 +178,6 @@ abstract class WriterAbstract implements WriterInterface
public function addRow(Row $row) public function addRow(Row $row)
{ {
if ($this->isWriterOpened) { if ($this->isWriterOpened) {
// empty $dataRow should not add an empty line
if ($row->hasCells()) {
try { try {
$this->addRowToWriter($row); $this->addRowToWriter($row);
} catch (SpoutException $e) { } catch (SpoutException $e) {
@@ -190,7 +188,6 @@ abstract class WriterAbstract implements WriterInterface
// re-throw the exception to alert developers of the error // re-throw the exception to alert developers of the error
throw $e; throw $e;
} }
}
} else { } else {
throw new WriterNotOpenedException('The writer needs to be opened before adding row.'); throw new WriterNotOpenedException('The writer needs to be opened before adding row.');
} }
+2 -2
View File
@@ -133,7 +133,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
/** /**
* @return void * @return void
*/ */
public function testWriteShouldSkipEmptyRows() public function testWriteShouldNotSkipEmptyRows()
{ {
$allRows = $this->createRowsFromValues([ $allRows = $this->createRowsFromValues([
['csv--11', 'csv--12'], ['csv--11', 'csv--12'],
@@ -143,7 +143,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$writtenContent = $this->writeToCsvFileAndReturnWrittenContent($allRows, 'csv_with_empty_rows.csv'); $writtenContent = $this->writeToCsvFileAndReturnWrittenContent($allRows, 'csv_with_empty_rows.csv');
$writtenContent = $this->trimWrittenContent($writtenContent); $writtenContent = $this->trimWrittenContent($writtenContent);
$this->assertEquals("csv--11,csv--12\ncsv--31,csv--32", $writtenContent, 'Empty rows should be skipped'); $this->assertEquals("csv--11,csv--12\n\ncsv--31,csv--32", $writtenContent, 'Empty rows should be skipped');
} }
/** /**