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();