diff --git a/tests/methods/DataRowCountTest.php b/tests/methods/DataRowCountTest.php new file mode 100644 index 0000000..a1fb0e2 --- /dev/null +++ b/tests/methods/DataRowCountTest.php @@ -0,0 +1,66 @@ +csv = new Csv(); + } + + public function countRowsProvider() { + return [ + 'auto-double-enclosure' => [ + 'auto-double-enclosure.csv', + 2, + ], + 'auto-single-enclosure' => [ + 'auto-single-enclosure.csv', + 2, + ], + 'UTF-8_sep_row' => [ + 'datatype.csv', + 3, + ], + ]; + } + + /** + * @dataProvider countRowsProvider + * + * @param string $file + * @param int $expectedRows + */ + public function testGetTotalRowCountFromFile($file, $expectedRows) { + $this->csv->heading = true; + $this->csv->load_data(__DIR__ . '/fixtures/' . $file); + $this->assertEquals($expectedRows, $this->csv->getTotalDataRowCount()); + } + + public function testGetTotalRowCountMissingEndingLineBreak() { + $this->csv->heading = false; + $this->csv->enclosure = '"'; + $sInput = "86545235689,a\r\n34365587654,b\r\n13469874576,\"c\r\nd\""; + $this->csv->load_data($sInput); + $this->assertEquals(3, $this->csv->getTotalDataRowCount()); + } +} diff --git a/tests/methods/ParseTest.php b/tests/methods/ParseTest.php index 5851438..9566499 100644 --- a/tests/methods/ParseTest.php +++ b/tests/methods/ParseTest.php @@ -198,41 +198,4 @@ class ParseTest extends TestCase $this->assertArrayHasKey('column1', $csv->data[0], 'Data parsed incorrectly with enclosure ' . $enclosure); $this->assertEquals('value1', $csv->data[0]['column1'], 'Data parsed incorrectly with enclosure ' . $enclosure); } - - public function countRowsProvider(){ - return [ - 'auto-double-enclosure' => [ - 'auto-double-enclosure.csv', - 2 - ], - 'auto-single-enclosure' => [ - 'auto-single-enclosure.csv', - 2 - ], - 'UTF-8_sep_row' => [ - 'datatype.csv', - 3 - ] - ]; - } - - /** - * @dataProvider countRowsProvider - * - * @param string $file - * @param int $expectedRows - */ - public function testGetTotalRowCountFromFile($file, $expectedRows){ - $this->csv->heading = true; - $this->csv->load_data(__DIR__ . '/fixtures/' . $file); - $this->assertEquals($expectedRows, $this->csv->getTotalDataRowCount()); - } - - public function testGetTotalRowCountMissingEndingLineBreak(){ - $this->csv->heading = false; - $this->csv->enclosure = '"'; - $sInput = "86545235689,a\r\n34365587654,b\r\n13469874576,\"c\r\nd\""; - $this->csv->load_data($sInput); - $this->assertEquals(3, $this->csv->getTotalDataRowCount()); - } }