public function CsvParserTest::testCsvParsing in Feeds 8.3
Basic test for parsing CSV.
@dataProvider csvFileProvider
File
- tests/
src/ Unit/ Component/ CsvParserTest.php, line 124
Class
- CsvParserTest
- @coversDefaultClass \Drupal\feeds\Component\CsvParser @group feeds
Namespace
Drupal\Tests\feeds\Unit\ComponentCode
public function testCsvParsing($file, $expected) {
$parser = CsvParser::createFromFilePath($file);
$parser
->setHasHeader();
$header = $parser
->getHeader();
$output = [];
$test = [];
foreach (iterator_to_array($parser) as $row) {
$new_row = [];
foreach ($row as $key => $value) {
if (isset($header[$key])) {
$new_row[$header[$key]] = $value;
}
}
$output[] = $new_row;
}
$this
->assertSame($expected, $output);
}