Skip to content

Commit

Permalink
Merge pull request #96 from gries/item_converter_breaks_mappings_fix
Browse files Browse the repository at this point in the history
Fixed php-error "undefined offset" when adding an item-converter and multiple mappings
  • Loading branch information
ddeboer committed Jul 28, 2014
2 parents 87283d9 + 2acf9f3 commit 72d4f93
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Ddeboer/DataImport/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
28 changes: 28 additions & 0 deletions tests/Ddeboer/DataImport/Tests/WorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 72d4f93

Please sign in to comment.