Skip to content

Commit 43cdbd3

Browse files
committed
Throw an exception if the processor returns a null value
1 parent 6b19e35 commit 43cdbd3

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

Step/ItemStep.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,13 @@ public function doExecute(StepExecution $stepExecution)
188188
// Processing
189189
try {
190190
if (null === $processedItem = $this->processor->process($item)) {
191-
continue;
191+
throw new \Exception(
192+
sprintf(
193+
'Processor %s returned unexpected value: NULL. ' .
194+
'Use Oro\Bundle\BatchBundle\Item\InvalidItemException to warn invalid value.',
195+
get_class($this->processor)
196+
)
197+
);
192198
}
193199
} catch (InvalidItemException $e) {
194200
$this->dispatchInvalidItemEvent(

Tests/Unit/Step/ItemStepTest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function testExecute()
133133
->with($stepExecution);
134134
$processor->expects($this->exactly(7))
135135
->method('process')
136-
->will($this->onConsecutiveCalls(1, null, 3, 4, 5, 6, 7, null));
136+
->will($this->onConsecutiveCalls(1, 2, 3, 4, 5, 6, 7));
137137

138138
$writer = $this->getMockBuilder('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Step\\Stub\\WriterStub')
139139
->setMethods(array('setStepExecution', 'write'))
@@ -299,6 +299,47 @@ public function testDispatchWriteInvalidItemException()
299299
$this->itemStep->execute($stepExecution);
300300
}
301301

302+
public function testProcessShouldNotReturnNull()
303+
{
304+
$stepExecution = $this->getMockBuilder('Oro\\Bundle\\BatchBundle\\Entity\\StepExecution')
305+
->disableOriginalConstructor()
306+
->getMock();
307+
$stepExecution->expects($this->any())
308+
->method('getStatus')
309+
->will($this->returnValue(new BatchStatus(BatchStatus::STARTING)));
310+
311+
$stepExecution->expects($this->once())
312+
->method('addFailureException');
313+
314+
315+
$this->eventDispatcher
316+
->expects($this->at(1))
317+
->method('dispatch')
318+
->with(
319+
EventInterface::STEP_EXECUTION_ERRORED,
320+
$this->anything()
321+
);
322+
323+
324+
$reader = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemReaderInterface');
325+
$reader->expects($this->any())
326+
->method('read')
327+
->will($this->returnValue(array('foo' => 'bar')));
328+
329+
$processor = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemProcessorInterface');
330+
$processor->expects($this->any())
331+
->method('process')
332+
->will($this->returnValue(null));
333+
334+
$writer = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemWriterInterface');
335+
336+
$this->itemStep->setReader($reader);
337+
$this->itemStep->setProcessor($processor);
338+
$this->itemStep->setWriter($writer);
339+
340+
$this->itemStep->execute($stepExecution);
341+
}
342+
302343
/**
303344
* Assert the entity tested
304345
*

0 commit comments

Comments
 (0)