|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oro\Bundle\BatchBundle\Tests\Unit\Step; |
|
4
|
|
|
|
|
5
|
|
|
use Akeneo\Bundle\BatchBundle\Job\ExitStatus; |
|
6
|
|
|
use Oro\Bundle\BatchBundle\Step\ItemStep; |
|
7
|
|
|
use Akeneo\Bundle\BatchBundle\Job\BatchStatus; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Tests related to the ItemStep class |
|
11
|
|
|
* |
|
12
|
|
|
*/ |
|
13
|
|
|
class ItemStepTest extends \PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
const STEP_NAME = 'test_step_name'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var ItemStep |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $itemStep = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $eventDispatcher = null; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $jobRepository = null; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function setUp() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); |
|
38
|
|
|
$this->jobRepository = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Job\\JobRepositoryInterface'); |
|
39
|
|
|
|
|
40
|
|
|
$this->itemStep = new ItemStep(self::STEP_NAME); |
|
41
|
|
|
|
|
42
|
|
|
$this->itemStep->setEventDispatcher($this->eventDispatcher); |
|
43
|
|
|
$this->itemStep->setJobRepository($this->jobRepository); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testExecute() |
|
47
|
|
|
{ |
|
48
|
|
|
$stepExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution') |
|
49
|
|
|
->disableOriginalConstructor() |
|
50
|
|
|
->getMock(); |
|
51
|
|
|
$stepExecution->expects($this->any()) |
|
52
|
|
|
->method('getStatus') |
|
53
|
|
|
->will($this->returnValue(new BatchStatus(BatchStatus::STARTING))); |
|
54
|
|
|
$stepExecution->expects($this->any()) |
|
55
|
|
|
->method('getExitStatus') |
|
56
|
|
|
->will($this->returnValue(new ExitStatus())); |
|
57
|
|
|
|
|
58
|
|
|
$reader = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Tests\\Unit\\Step\\Stub\\ReaderStub') |
|
59
|
|
|
->setMethods(array('setStepExecution', 'read')) |
|
60
|
|
|
->getMock(); |
|
61
|
|
|
$reader->expects($this->once()) |
|
62
|
|
|
->method('setStepExecution') |
|
63
|
|
|
->with($stepExecution); |
|
64
|
|
|
$reader->expects($this->exactly(8)) |
|
65
|
|
|
->method('read') |
|
66
|
|
|
->will($this->onConsecutiveCalls(1, 2, 3, 4, 5, 6, 7, null)); |
|
67
|
|
|
|
|
68
|
|
|
$processor = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Tests\\Unit\\Step\\Stub\\ProcessorStub') |
|
69
|
|
|
->setMethods(array('setStepExecution', 'process')) |
|
70
|
|
|
->getMock(); |
|
71
|
|
|
$processor->expects($this->once()) |
|
72
|
|
|
->method('setStepExecution') |
|
73
|
|
|
->with($stepExecution); |
|
74
|
|
|
$processor->expects($this->exactly(7)) |
|
75
|
|
|
->method('process') |
|
76
|
|
|
->will($this->onConsecutiveCalls(1, 2, 3, 4, 5, 6, 7)); |
|
77
|
|
|
|
|
78
|
|
|
$writer = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Tests\\Unit\\Step\\Stub\\WriterStub') |
|
79
|
|
|
->setMethods(array('setStepExecution', 'write')) |
|
80
|
|
|
->getMock(); |
|
81
|
|
|
$writer->expects($this->once()) |
|
82
|
|
|
->method('setStepExecution') |
|
83
|
|
|
->with($stepExecution); |
|
84
|
|
|
$writer->expects($this->exactly(2)) |
|
85
|
|
|
->method('write'); |
|
86
|
|
|
|
|
87
|
|
|
$this->itemStep->setReader($reader); |
|
88
|
|
|
$this->itemStep->setProcessor($processor); |
|
89
|
|
|
$this->itemStep->setWriter($writer); |
|
90
|
|
|
$this->itemStep->setBatchSize(5); |
|
91
|
|
|
$this->itemStep->execute($stepExecution); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Assert the entity tested |
|
96
|
|
|
* |
|
97
|
|
|
* @param object $entity |
|
98
|
|
|
*/ |
|
99
|
|
|
protected function assertEntity($entity) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->assertInstanceOf('Oro\\Bundle\\BatchBundle\\Step\\ItemStep', $entity); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|