From 745c147a03a7967a445645c3d31b79f564cfdc7c Mon Sep 17 00:00:00 2001 From: Markus Thielen Date: Sat, 20 Jun 2015 22:24:37 +0200 Subject: [PATCH] fixed mapping new fieldlowercaseconverter --- .../ItemConverter/FieldLowercaseConverter.php | 14 ++++++++++++++ src/Mathielen/ImportEngine/Mapping/Mappings.php | 2 +- .../ImportEngine/Storage/LocalFileStorage.php | 2 +- .../ImportEngine/Import/Run/ImportRunnerTest.php | 8 ++++---- 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 src/Mathielen/DataImport/ItemConverter/FieldLowercaseConverter.php diff --git a/src/Mathielen/DataImport/ItemConverter/FieldLowercaseConverter.php b/src/Mathielen/DataImport/ItemConverter/FieldLowercaseConverter.php new file mode 100644 index 0000000..34fd29c --- /dev/null +++ b/src/Mathielen/DataImport/ItemConverter/FieldLowercaseConverter.php @@ -0,0 +1,14 @@ +addValueConverter($from, $converter); + $workflow->addValueConverter($to, $converter); } elseif ($converter instanceof ItemConverterInterface) { $workflow->addItemConverter($converter); } diff --git a/src/Mathielen/ImportEngine/Storage/LocalFileStorage.php b/src/Mathielen/ImportEngine/Storage/LocalFileStorage.php index f6a184e..dc1a960 100644 --- a/src/Mathielen/ImportEngine/Storage/LocalFileStorage.php +++ b/src/Mathielen/ImportEngine/Storage/LocalFileStorage.php @@ -88,7 +88,7 @@ private function formatToReader(Format $format, \SplFileInfo $file) $reader = new CsvReader($file->openFile(), $format->getDelimiter(), $format->getEnclosure(), $format->getEscape()); $reader->setStrict(false); if ($format->isHeaderInFirstRow()) { - $reader->setHeaderRowNumber(0); + $reader->setHeaderRowNumber(0, CsvReader::DUPLICATE_HEADERS_MERGE); $reader->setColumnHeaders(array_map('trim', $reader->getColumnHeaders())); //TODO some header-collaborator? } diff --git a/tests/integration/Mathielen/ImportEngine/Import/Run/ImportRunnerTest.php b/tests/integration/Mathielen/ImportEngine/Import/Run/ImportRunnerTest.php index 17015ef..70a6b95 100644 --- a/tests/integration/Mathielen/ImportEngine/Import/Run/ImportRunnerTest.php +++ b/tests/integration/Mathielen/ImportEngine/Import/Run/ImportRunnerTest.php @@ -59,14 +59,14 @@ public function test() $import = $importBuilder->build($importRequest); $import->mappings() - ->add('Anrede', 'salutation', 'upperCase') - ->add('Name', 'name', 'lowerCase'); + ->add('prefix', 'Anrede', 'upperCase') + ->add('name', 'Name', 'lowerCase'); $importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher)); $expectedResult = array( - 'name' => 'Jennie Abernathy', - 'prefix' => 'Ms.', + 'Name' => 'jennie abernathy', + 'Anrede' => 'MS.', 'street' => '866 Hyatt Isle Apt. 888', 'zip' => '65982', 'city' => 'East Laurie',