Skip to content

Commit

Permalink
Merge pull request #76 from WeareJH/hotfix/import-exception-interface
Browse files Browse the repository at this point in the history
Hotfix/import exception interface
  • Loading branch information
ddeboer committed May 14, 2014
2 parents f597e9d + 73d3a46 commit ad21938
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Ddeboer/DataImport/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Psr\Log\NullLogger;

use Ddeboer\DataImport\Exception\UnexpectedTypeException;
use Ddeboer\DataImport\Exception\Exception;
use Ddeboer\DataImport\Exception\ExceptionInterface;
use Ddeboer\DataImport\ItemConverter\MappingItemConverter;
use Ddeboer\DataImport\Reader\ReaderInterface;
use Ddeboer\DataImport\Writer\WriterInterface;
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 @@ -9,6 +9,7 @@
use Ddeboer\DataImport\ValueConverter\CallbackValueConverter;
use Ddeboer\DataImport\ItemConverter\CallbackItemConverter;
use Ddeboer\DataImport\Writer\CallbackWriter;
use Ddeboer\DataImport\Exception\SourceNotFoundException;

class WorkflowTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -259,6 +260,33 @@ public function testAddFilterAfterConversion()
$this->assertEquals(2, $afterConversionFilterCalledIncrementor);
}

public function testExceptionInterfaceThrownFromWriterIsCaught()
{
$originalData = array(array('foo' => 'bar'));
$reader = new ArrayReader($originalData);

$array = array();
$writer = $this->getMock('Ddeboer\DataImport\Writer\ArrayWriter', array(), array(&$array));

$exception = new SourceNotFoundException("Log me!");

$writer->expects($this->once())
->method('writeItem')
->with($originalData[0])
->will($this->throwException($exception));

$logger = $this->getMock('Psr\Log\LoggerInterface');
$logger->expects($this->once())
->method('error')
->with($exception->getMessage());


$workflow = new Workflow($reader, $logger);
$workflow->setSkipItemOnFailure(true);
$workflow->addWriter($writer);
$workflow->process();
}

protected function getWorkflow()
{
$reader = new ArrayReader(array(
Expand Down

0 comments on commit ad21938

Please sign in to comment.