From f8c68a6cd72a44b8012b3f3591be68284c31f9b4 Mon Sep 17 00:00:00 2001 From: Susann Sgorzaly Date: Sat, 17 Feb 2018 22:24:19 +0100 Subject: [PATCH] test improvements --- tests/methods/ParseTest.php | 52 +++++++++---------- .../fixtures}/auto-double-enclosure.csv | 0 .../fixtures}/auto-single-enclosure.csv | 0 3 files changed, 26 insertions(+), 26 deletions(-) rename tests/{example_files => methods/fixtures}/auto-double-enclosure.csv (100%) rename tests/{example_files => methods/fixtures}/auto-single-enclosure.csv (100%) diff --git a/tests/methods/ParseTest.php b/tests/methods/ParseTest.php index c7f8fcb..d941f40 100644 --- a/tests/methods/ParseTest.php +++ b/tests/methods/ParseTest.php @@ -39,9 +39,26 @@ class ParseTest extends PHPUnit\Framework\TestCase { $this->assertEquals($expected_data, $row); } - public function test_sep_row_auto_detection_UTF8_no_BOM() { - $this->_autoparse_magazine_file( - __DIR__ . '/../example_files/UTF-8_sep_row_but_no_BOM.csv'); + /** + * @depends test_parse + * + * @dataProvider autoDetectionProvider + */ + public function testSepRowAutoDetection($file) { + // This file (parse_test.php) is encoded in UTF-8, hence comparison will + // fail unless we to this: + $this->csv->output_encoding = 'UTF-8'; + + $this->csv->auto($file); + $this->assertEquals($this->_get_magazines_data(), $this->csv->data); + } + + public function autoDetectionProvider(){ + return [ + 'UTF8_no_BOM' => [__DIR__ . '/../example_files/UTF-8_sep_row_but_no_BOM.csv'], + 'UTF8' => [__DIR__ . '/../example_files/UTF-8_with_BOM_and_sep_row.csv'], + 'UTF16' => [__DIR__ . '/../example_files/UTF-16LE_with_BOM_and_sep_row.csv'], + ]; } public function testSingleColumnWithZeros() { @@ -77,25 +94,6 @@ class ParseTest extends PHPUnit\Framework\TestCase { ], array_map('next', $actual_data)); } - public function test_sep_row_auto_detection_UTF8() { - $this->_autoparse_magazine_file( - __DIR__ . '/../example_files/UTF-8_with_BOM_and_sep_row.csv'); - } - - public function test_sep_row_auto_detection_UTF16() { - $this->_autoparse_magazine_file( - __DIR__ . '/../example_files/UTF-16LE_with_BOM_and_sep_row.csv'); - } - - protected function _autoparse_magazine_file($file) { - // This file (parse_test.php) is encoded in UTF-8, hence comparison will - // fail unless we to this: - $this->csv->output_encoding = 'UTF-8'; - - $this->csv->auto($file); - $this->assertEquals($this->_get_magazines_data(), $this->csv->data); - } - public function test_single_column() { $this->csv->auto(__DIR__ . '/../example_files/single_column.csv'); $expected = [ @@ -151,13 +149,15 @@ class ParseTest extends PHPUnit\Framework\TestCase { } public function autoQuotesDataProvider() { - return array( - array('tests/methods/fixtures/auto-double-enclosure.csv', '"'), - array('tests/methods/fixtures/auto-single-enclosure.csv', "'"), - ); + return [ + 'double-enclosure' => ['tests/methods/fixtures/auto-double-enclosure.csv', '"'], + 'single-enclosure' => ['tests/methods/fixtures/auto-single-enclosure.csv', "'"], + ]; } /** + * @depends testSepRowAutoDetection + * * @dataProvider autoQuotesDataProvider * * @param string $file diff --git a/tests/example_files/auto-double-enclosure.csv b/tests/methods/fixtures/auto-double-enclosure.csv similarity index 100% rename from tests/example_files/auto-double-enclosure.csv rename to tests/methods/fixtures/auto-double-enclosure.csv diff --git a/tests/example_files/auto-single-enclosure.csv b/tests/methods/fixtures/auto-single-enclosure.csv similarity index 100% rename from tests/example_files/auto-single-enclosure.csv rename to tests/methods/fixtures/auto-single-enclosure.csv