From 2acf9f34fddf93d5f2447389e7a9142bb2c39379 Mon Sep 17 00:00:00 2001 From: crosse Date: Fri, 25 Jul 2014 14:52:38 +0200 Subject: [PATCH] Fixed a bug that caused a php-error "undefined offset" when adding a item-converter and later on adding multiple mappings. --- src/Ddeboer/DataImport/Workflow.php | 3 +- .../Ddeboer/DataImport/Tests/WorkflowTest.php | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Ddeboer/DataImport/Workflow.php b/src/Ddeboer/DataImport/Workflow.php index 912ae0a4..cef20bac 100644 --- a/src/Ddeboer/DataImport/Workflow.php +++ b/src/Ddeboer/DataImport/Workflow.php @@ -359,7 +359,8 @@ function ($converter) { if (count($converters) > 0) { // Return first mapping item converter that we encounter - $converter = $converters[0]; + reset($converters); + $converter = current($converters); } else { // Create default converter $converter = new MappingItemConverter(); diff --git a/tests/Ddeboer/DataImport/Tests/WorkflowTest.php b/tests/Ddeboer/DataImport/Tests/WorkflowTest.php index ce126a58..dbbb8ac8 100644 --- a/tests/Ddeboer/DataImport/Tests/WorkflowTest.php +++ b/tests/Ddeboer/DataImport/Tests/WorkflowTest.php @@ -324,6 +324,34 @@ public function testWorkflowResultWhenAllSuccessful() $this->assertSame(null, $result->getName()); } + public function testMultipleMappingsForAnItemAfterAnotherItemConverterwasAdded() + { + $originalData = array(array('foo' => 'bar', 'baz' => 'value')); + + $ouputTestData = array(); + + $writer = new ArrayWriter($ouputTestData); + $reader = new ArrayReader($originalData); + + $workflow = new Workflow($reader); + + // add a dummy item converter + $workflow->addItemConverter(new CallbackItemConverter(function($item) { + return $item; + })); + + // add multiple mappings + $workflow + ->addMapping('foo', 'bar') + ->addMapping('baz', 'bazzoo') + ->addWriter($writer) + ->process() + ; + + $this->assertArrayHasKey('bar', $ouputTestData[0]); + $this->assertArrayHasKey('bazzoo', $ouputTestData[0]); + } + public function testWorkflowResultWithExceptionThrowFromWriter() { $workflow = $this->getWorkflow();