Skip to content

Commit 255b94a

Browse files
committed
Store the step element name instead of classname
This is more usefull for displaying purpose. Classname is still sent into the InvalidItemEvent, thus being displayed in the log.
1 parent d5fd1aa commit 255b94a

File tree

4 files changed

+50
-41
lines changed

4 files changed

+50
-41
lines changed

Entity/StepExecution.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Oro\Bundle\BatchBundle\Item\ExecutionContext;
88
use Oro\Bundle\BatchBundle\Job\BatchStatus;
99
use Oro\Bundle\BatchBundle\Job\ExitStatus;
10-
use Oro\Bundle\BatchBundle\Item\ItemReaderInterface;
1110

1211
/**
1312
* Batch domain object representation the execution of a step. Unlike
@@ -137,7 +136,6 @@ class StepExecution
137136
*/
138137
private $warnings = array();
139138

140-
141139
/**
142140
* Constructor with mandatory properties.
143141
*
@@ -498,10 +496,10 @@ public function getErrors()
498496
* @param string $reason
499497
* @param mixed $item
500498
*/
501-
public function addWarning($class, $reason, $item)
499+
public function addWarning($name, $reason, $item)
502500
{
503501
$this->warnings[] = array(
504-
'class' => $class,
502+
'name' => sprintf('oro_batch.%s.title', $name),
505503
'reason' => $reason,
506504
'item' => $item,
507505
);

Step/ItemStep.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function doExecute(StepExecution $stepExecution)
176176
continue;
177177
}
178178
} catch (InvalidItemException $e) {
179-
$this->handleStepExecutionWarning($stepExecution, get_class($this->reader), $e);
179+
$this->handleStepExecutionWarning($stepExecution, $this->reader, $e);
180180

181181
continue;
182182
}
@@ -193,7 +193,7 @@ public function doExecute(StepExecution $stepExecution)
193193
);
194194
}
195195
} catch (InvalidItemException $e) {
196-
$this->handleStepExecutionWarning($stepExecution, get_class($this->processor), $e);
196+
$this->handleStepExecutionWarning($stepExecution, $this->processor, $e);
197197

198198
continue;
199199
}
@@ -205,7 +205,7 @@ public function doExecute(StepExecution $stepExecution)
205205
$this->writer->write($itemsToWrite);
206206
$itemsToWrite = array();
207207
} catch (InvalidItemException $e) {
208-
$this->handleStepExecutionWarning($stepExecution, get_class($this->writer), $e);
208+
$this->handleStepExecutionWarning($stepExecution, $this->writer, $e);
209209

210210
continue;
211211
}
@@ -217,7 +217,7 @@ public function doExecute(StepExecution $stepExecution)
217217
$this->writer->write($itemsToWrite);
218218
$itemsToWrite = array();
219219
} catch (InvalidItemException $e) {
220-
$this->handleStepExecutionWarning($stepExecution, get_class($this->writer), $e);
220+
$this->handleStepExecutionWarning($stepExecution, $this->writer, $e);
221221
}
222222
}
223223
}
@@ -247,9 +247,12 @@ protected function initializeStepComponents(StepExecution $stepExecution)
247247
* @param string $class
248248
* @param InvalidItemException $e
249249
*/
250-
private function handleStepExecutionWarning(StepExecution $stepExecution, $class, InvalidItemException $e)
251-
{
252-
$stepExecution->addWarning($class, $e->getMessage(), $e->getItem());
253-
$this->dispatchInvalidItemEvent($class, $e->getMessage(), $e->getItem());
250+
private function handleStepExecutionWarning(
251+
StepExecution $stepExecution,
252+
AbstractConfigurableStepElement $element,
253+
InvalidItemException $e
254+
) {
255+
$stepExecution->addWarning($element->getName(), $e->getMessage(), $e->getItem());
256+
$this->dispatchInvalidItemEvent(get_class($element), $e->getMessage(), $e->getItem());
254257
}
255258
}

Tests/Unit/Entity/StepExecutionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,25 @@ public function testToString()
171171
public function testAddWarning()
172172
{
173173
$this->stepExecution->addWarning(
174-
'Oro\Bundle\BatchBundle\Item\ItemReaderInterface',
174+
'foo',
175175
'something is wrong on line 1',
176176
array('foo' => 'bar')
177177
);
178178
$this->stepExecution->addWarning(
179-
'Oro\Bundle\BatchBundle\Item\ItemReaderInterface',
179+
'bar',
180180
'something is wrong on line 2',
181181
array('baz' => false)
182182
);
183183

184184
$this->assertEquals(
185185
array(
186186
array(
187-
'class' => 'Oro\Bundle\BatchBundle\Item\ItemReaderInterface',
187+
'name' => 'oro_batch.foo.title',
188188
'reason' => 'something is wrong on line 1',
189189
'item' => array('foo' => 'bar')
190190
),
191191
array(
192-
'class' => 'Oro\Bundle\BatchBundle\Item\ItemReaderInterface',
192+
'name' => 'oro_batch.bar.title',
193193
'reason' => 'something is wrong on line 2',
194194
'item' => array('baz' => false)
195195
)

Tests/Unit/Step/ItemStepTest.php

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function testExecute()
151151
$this->itemStep->execute($stepExecution);
152152
}
153153

154-
public function testDispatchReaderInvalidItemException()
154+
public function testDispatchReadInvalidItemException()
155155
{
156156
$stepExecution = $this->getMockBuilder('Oro\\Bundle\\BatchBundle\\Entity\\StepExecution')
157157
->disableOriginalConstructor()
@@ -166,25 +166,28 @@ public function testDispatchReaderInvalidItemException()
166166
->with(
167167
EventInterface::INVALID_ITEM,
168168
$this->logicalAnd(
169-
$this->isInstanceOf('Oro\Bundle\BatchBundle\Event\InvalidItemEvent'),
169+
$this->isInstanceOf('Oro\\Bundle\\BatchBundle\\Event\\InvalidItemEvent'),
170170
$this->attributeEqualTo('reason', 'The read item is invalid'),
171171
$this->attributeEqualTo('item', array('foo' => 'bar'))
172172
)
173173
);
174174

175-
$reader = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemReaderInterface');
175+
$reader = $this->getMock('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemReaderTestHelper');
176176
$reader->expects($this->exactly(2))
177177
->method('read')
178178
->will($this->onConsecutiveCalls(
179179
$this->throwException(new InvalidItemException('The read item is invalid', array('foo' => 'bar'))),
180180
$this->returnValue(null)
181181
));
182+
$reader->expects($this->any())
183+
->method('getName')
184+
->will($this->returnValue('stub_reader'));
182185

183-
$processor = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemProcessorInterface');
186+
$processor = $this->getMock('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemProcessorTestHelper');
184187
$processor->expects($this->never())
185188
->method('process');
186189

187-
$writer = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemWriterInterface');
190+
$writer = $this->getMock('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemWriterTestHelper');
188191
$writer->expects($this->never())
189192
->method('write');
190193

@@ -195,7 +198,7 @@ public function testDispatchReaderInvalidItemException()
195198
$stepExecution->expects($this->once())
196199
->method('addWarning')
197200
->with(
198-
get_class($reader),
201+
'stub_reader',
199202
'The read item is invalid',
200203
array('foo' => 'bar')
201204
);
@@ -219,30 +222,33 @@ public function testDispatchProcessInvalidItemException()
219222
->with(
220223
EventInterface::INVALID_ITEM,
221224
$this->logicalAnd(
222-
$this->isInstanceOf('Oro\Bundle\BatchBundle\Event\InvalidItemEvent'),
225+
$this->isInstanceOf('Oro\\Bundle\\BatchBundle\\Event\\InvalidItemEvent'),
223226
$this->attributeEqualTo('reason', 'The processed item is invalid'),
224227
$this->attributeEqualTo('item', array('foo' => 'bar'))
225228
)
226229
);
227230

228-
$reader = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemReaderInterface');
231+
$reader = $this->getMock('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemReaderTestHelper');
229232
$reader->expects($this->exactly(2))
230233
->method('read')
231234
->will($this->onConsecutiveCalls(
232235
$this->returnValue(array('foo' => 'bar')),
233236
$this->returnValue(null)
234237
));
235238

236-
$processor = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemProcessorInterface');
239+
$processor = $this->getMock('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemProcessorTestHelper');
237240
$processor->expects($this->exactly(1))
238241
->method('process')
239242
->will(
240243
$this->throwException(
241244
new InvalidItemException('The processed item is invalid', array('foo' => 'bar'))
242245
)
243246
);
247+
$processor->expects($this->any())
248+
->method('getName')
249+
->will($this->returnValue('stub_processor'));
244250

245-
$writer = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemWriterInterface');
251+
$writer = $this->getMock('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemWriterTestHelper');
246252
$writer->expects($this->never())
247253
->method('write');
248254

@@ -253,7 +259,7 @@ public function testDispatchProcessInvalidItemException()
253259
$stepExecution->expects($this->once())
254260
->method('addWarning')
255261
->with(
256-
get_class($processor),
262+
'stub_processor',
257263
'The processed item is invalid',
258264
array('foo' => 'bar')
259265
);
@@ -277,35 +283,38 @@ public function testDispatchWriteInvalidItemException()
277283
->with(
278284
EventInterface::INVALID_ITEM,
279285
$this->logicalAnd(
280-
$this->isInstanceOf('Oro\Bundle\BatchBundle\Event\InvalidItemEvent'),
286+
$this->isInstanceOf('Oro\\Bundle\\BatchBundle\\Event\\InvalidItemEvent'),
281287
$this->attributeEqualTo('reason', 'The written item is invalid'),
282288
$this->attributeEqualTo('item', array('foo' => 'bar'))
283289
)
284290
);
285291

286-
$reader = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemReaderInterface');
292+
$reader = $this->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemReaderInterface');
287293
$reader->expects($this->exactly(2))
288294
->method('read')
289295
->will($this->onConsecutiveCalls(
290296
$this->returnValue(array('foo' => 'bar')),
291297
$this->returnValue(null)
292298
));
293299

294-
$processor = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemProcessorInterface');
300+
$processor = $this->getMock('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemProcessorTestHelper');
295301
$processor->expects($this->exactly(1))
296302
->method('process')
297303
->will(
298304
$this->returnValue(array('foo' => 'bar'))
299305
);
300306

301-
$writer = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemWriterInterface');
307+
$writer = $this->getMock('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemWriterTestHelper');
302308
$writer->expects($this->exactly(1))
303309
->method('write')
304310
->will(
305311
$this->throwException(
306312
new InvalidItemException('The written item is invalid', array('foo' => 'bar'))
307313
)
308314
);
315+
$writer->expects($this->any())
316+
->method('getName')
317+
->will($this->returnValue('stub_writer'));
309318

310319
$this->itemStep->setReader($reader);
311320
$this->itemStep->setProcessor($processor);
@@ -314,7 +323,7 @@ public function testDispatchWriteInvalidItemException()
314323
$stepExecution->expects($this->once())
315324
->method('addWarning')
316325
->with(
317-
get_class($writer),
326+
'stub_writer',
318327
'The written item is invalid',
319328
array('foo' => 'bar')
320329
);
@@ -335,7 +344,6 @@ public function testProcessShouldNotReturnNull()
335344
$stepExecution->expects($this->once())
336345
->method('addFailureException');
337346

338-
339347
$this->eventDispatcher
340348
->expects($this->at(1))
341349
->method('dispatch')
@@ -344,18 +352,17 @@ public function testProcessShouldNotReturnNull()
344352
$this->anything()
345353
);
346354

347-
348-
$reader = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemReaderInterface');
355+
$reader = $this->getMock('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemReaderTestHelper');
349356
$reader->expects($this->any())
350357
->method('read')
351358
->will($this->returnValue(array('foo' => 'bar')));
352359

353-
$processor = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemProcessorInterface');
360+
$processor = $this->getMock('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemProcessorTestHelper');
354361
$processor->expects($this->any())
355362
->method('process')
356363
->will($this->returnValue(null));
357364

358-
$writer = $this ->getMock('Oro\\Bundle\\BatchBundle\\Item\\ItemWriterInterface');
365+
$writer = $this->getMock('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemWriterTestHelper');
359366

360367
$this->itemStep->setReader($reader);
361368
$this->itemStep->setProcessor($processor);
@@ -371,12 +378,13 @@ public function testProcessShouldNotReturnNull()
371378
*/
372379
protected function assertEntity($entity)
373380
{
374-
$this->assertInstanceOf('Oro\Bundle\BatchBundle\Step\ItemStep', $entity);
381+
$this->assertInstanceOf('Oro\\Bundle\\BatchBundle\\Step\\ItemStep', $entity);
375382
}
383+
376384
private function getReaderMock(array $configuration, array $fields = array())
377385
{
378386
$reader = $this
379-
->getMockBuilder('Oro\Bundle\BatchBundle\Tests\Unit\Item\ItemReaderTestHelper')
387+
->getMockBuilder('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemReaderTestHelper')
380388
->disableOriginalConstructor()
381389
->getMock();
382390

@@ -394,7 +402,7 @@ private function getReaderMock(array $configuration, array $fields = array())
394402
private function getProcessorMock(array $configuration, array $fields = array())
395403
{
396404
$processor = $this
397-
->getMockBuilder('Oro\Bundle\BatchBundle\Tests\Unit\Item\ItemProcessorTestHelper')
405+
->getMockBuilder('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemProcessorTestHelper')
398406
->disableOriginalConstructor()
399407
->getMock();
400408

@@ -412,7 +420,7 @@ private function getProcessorMock(array $configuration, array $fields = array())
412420
private function getWriterMock(array $configuration, array $fields = array())
413421
{
414422
$writer = $this
415-
->getMockBuilder('Oro\Bundle\BatchBundle\Tests\Unit\Item\ItemWriterTestHelper')
423+
->getMockBuilder('Oro\\Bundle\\BatchBundle\\Tests\\Unit\\Item\\ItemWriterTestHelper')
416424
->disableOriginalConstructor()
417425
->getMock();
418426

0 commit comments

Comments
 (0)