diff --git a/src/Spout/Writer/WriterAbstract.php b/src/Spout/Writer/WriterAbstract.php index 0df4522..9555d73 100644 --- a/src/Spout/Writer/WriterAbstract.php +++ b/src/Spout/Writer/WriterAbstract.php @@ -178,18 +178,15 @@ abstract class WriterAbstract implements WriterInterface public function addRow(Row $row) { if ($this->isWriterOpened) { - // empty $dataRow should not add an empty line - if ($row->hasCells()) { - try { - $this->addRowToWriter($row); - } catch (SpoutException $e) { - // if an exception occurs while writing data, - // close the writer and remove all files created so far. - $this->closeAndAttemptToCleanupAllFiles(); + try { + $this->addRowToWriter($row); + } catch (SpoutException $e) { + // if an exception occurs while writing data, + // close the writer and remove all files created so far. + $this->closeAndAttemptToCleanupAllFiles(); - // re-throw the exception to alert developers of the error - throw $e; - } + // re-throw the exception to alert developers of the error + throw $e; } } else { throw new WriterNotOpenedException('The writer needs to be opened before adding row.'); diff --git a/tests/Spout/Writer/CSV/WriterTest.php b/tests/Spout/Writer/CSV/WriterTest.php index 94a6fc1..f7e4a6e 100644 --- a/tests/Spout/Writer/CSV/WriterTest.php +++ b/tests/Spout/Writer/CSV/WriterTest.php @@ -133,7 +133,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase /** * @return void */ - public function testWriteShouldSkipEmptyRows() + public function testWriteShouldNotSkipEmptyRows() { $allRows = $this->createRowsFromValues([ ['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->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'); } /**