diff --git a/tests/Spout/Reader/CSV/ReaderTest.php b/tests/Spout/Reader/CSV/ReaderTest.php index 00a0f2c..c4c00ba 100644 --- a/tests/Spout/Reader/CSV/ReaderTest.php +++ b/tests/Spout/Reader/CSV/ReaderTest.php @@ -377,4 +377,50 @@ class ReaderTest extends \PHPUnit_Framework_TestCase return $allRows; } + + /** + * @return array + */ + public function dataProviderForTestReadCustomEOL() + { + return [ + ['csv_with_CR_EOL.csv', "\r"], + ['csv_standard.csv', "\n"], + ]; + } + + /** + * @dataProvider dataProviderForTestReadCustomEOL + * + * @param string $fileName + * @param string $customEOL + * @return void + */ + public function testReadCustomEOLs($fileName, $customEOL) + { + $allRows = []; + $resourcePath = $this->getResourcePath($fileName); + + /** @var \Box\Spout\Reader\CSV\Reader $reader */ + $reader = ReaderFactory::create(Type::CSV); + $reader + ->setEndOfLineCharacter($customEOL) + ->open($resourcePath); + + foreach ($reader->getSheetIterator() as $sheet) { + foreach ($sheet->getRowIterator() as $row) { + $allRows[] = $row; + } + } + + $reader->close(); + + $expectedRows = [ + ['csv--11', 'csv--12', 'csv--13'], + ['csv--21', 'csv--22', 'csv--23'], + ['csv--31', 'csv--32', 'csv--33'], + ]; + $this->assertEquals($expectedRows, $allRows); + } + } diff --git a/tests/resources/csv/csv_with_CR_EOL.csv b/tests/resources/csv/csv_with_CR_EOL.csv new file mode 100644 index 0000000..004f328 --- /dev/null +++ b/tests/resources/csv/csv_with_CR_EOL.csv @@ -0,0 +1 @@ +csv--11,csv--12,csv--13 csv--21,csv--22,csv--23 csv--31,csv--32,csv--33 \ No newline at end of file