|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\MagentoBundle\Tests\Unit\ImportExport\Writer; |
|
4
|
|
|
|
|
5
|
|
|
use Akeneo\Bundle\BatchBundle\Item\ItemWriterInterface; |
|
6
|
|
|
|
|
7
|
|
|
use Oro\Bundle\ImportExportBundle\Field\DatabaseHelper; |
|
8
|
|
|
|
|
9
|
|
|
use OroCRM\Bundle\MagentoBundle\Entity\Cart; |
|
10
|
|
|
use OroCRM\Bundle\MagentoBundle\Entity\Customer; |
|
11
|
|
|
use OroCRM\Bundle\MagentoBundle\Entity\Order; |
|
12
|
|
|
use OroCRM\Bundle\MagentoBundle\ImportExport\Writer\ProxyEntityWriter; |
|
13
|
|
|
|
|
14
|
|
|
class ProxyEntityWriterTest extends \PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var ItemWriterInterface|\PHPUnit_Framework_MockObject_MockObject */ |
|
17
|
|
|
protected $wrapped; |
|
18
|
|
|
|
|
19
|
|
|
/** @var ProxyEntityWriter */ |
|
20
|
|
|
protected $writer; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|DatabaseHelper |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $databaseHelper; |
|
26
|
|
|
|
|
27
|
|
|
protected function setUp() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->wrapped = $this->getMock('Akeneo\Bundle\BatchBundle\Item\ItemWriterInterface'); |
|
30
|
|
|
|
|
31
|
|
|
$this->databaseHelper = $this->getMockBuilder('Oro\Bundle\ImportExportBundle\Field\DatabaseHelper') |
|
32
|
|
|
->disableOriginalConstructor() |
|
33
|
|
|
->getMock(); |
|
34
|
|
|
|
|
35
|
|
|
$this->writer = new ProxyEntityWriter($this->wrapped, $this->databaseHelper); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function tearDown() |
|
39
|
|
|
{ |
|
40
|
|
|
unset($this->writer, $this->wrapped); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @dataProvider itemsProvider |
|
45
|
|
|
* |
|
46
|
|
|
* @param array $items |
|
47
|
|
|
* @param array $expectedItems |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testWrite(array $items, array $expectedItems) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->wrapped->expects($this->once())->method('write') |
|
|
|
|
|
|
52
|
|
|
->with($this->equalTo($expectedItems)); |
|
53
|
|
|
|
|
54
|
|
|
$stepExecution = $this->getMockBuilder('Akeneo\Bundle\BatchBundle\Entity\StepExecution') |
|
55
|
|
|
->disableOriginalConstructor()->getMock(); |
|
56
|
|
|
$this->databaseHelper->expects($this->once())->method('onClear'); |
|
|
|
|
|
|
57
|
|
|
$this->writer->setStepExecution($stepExecution); |
|
58
|
|
|
|
|
59
|
|
|
$this->writer->write($items); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
|
|
public function itemsProvider() |
|
66
|
|
|
{ |
|
67
|
|
|
$order1 = new Order(); |
|
68
|
|
|
$order2 = new Order(); |
|
69
|
|
|
$order1->setIncrementId('1111'); |
|
70
|
|
|
$order2->setIncrementId('2222'); |
|
71
|
|
|
$order3 = clone $order1; |
|
72
|
|
|
|
|
73
|
|
|
$cart1 = new Cart(); |
|
74
|
|
|
$cart2 = new Cart(); |
|
75
|
|
|
$cart1->setOriginId(1111); |
|
76
|
|
|
$cart2->setOriginId(2222); |
|
77
|
|
|
$cart3 = clone $cart1; |
|
78
|
|
|
|
|
79
|
|
|
$customer1 = new Customer(); |
|
80
|
|
|
$customer1->setOriginId(111); |
|
81
|
|
|
$customer2 = clone $customer1; |
|
82
|
|
|
|
|
83
|
|
|
$customerGuest1 = new Customer(); |
|
84
|
|
|
$customerGuest2 = new Customer(); |
|
85
|
|
|
|
|
86
|
|
|
$someEntity = new \stdClass(); |
|
87
|
|
|
$someEntity2 = new \stdClass(); |
|
88
|
|
|
|
|
89
|
|
|
return [ |
|
90
|
|
|
'should skip non-unique orders' => [ |
|
91
|
|
|
'$items' => [$order1, $order2, $order3], |
|
92
|
|
|
'$expectedItems' => [$order3->getIncrementId() => $order3, $order2->getIncrementId() => $order2] |
|
93
|
|
|
], |
|
94
|
|
|
'should skip non-unique carts' => [ |
|
95
|
|
|
'$items' => [$cart1, $cart2, $cart3], |
|
96
|
|
|
'$expectedItems' => [$cart3->getOriginId() => $cart3, $cart2->getOriginId() => $cart2] |
|
97
|
|
|
], |
|
98
|
|
|
'should skip non-unique customers' => [ |
|
99
|
|
|
'$items' => [$customer1, $customer2], |
|
100
|
|
|
'$expectedItems' => [$customer2->getOriginId() => $customer2] |
|
101
|
|
|
], |
|
102
|
|
|
'dont skip guest customers' => [ |
|
103
|
|
|
'$items' => [$customerGuest1, $customerGuest1, $customerGuest2], |
|
104
|
|
|
'$expectedItems' => [ |
|
105
|
|
|
spl_object_hash($customerGuest1) => $customerGuest1, |
|
106
|
|
|
spl_object_hash($customerGuest2) => $customerGuest2, |
|
107
|
|
|
], |
|
108
|
|
|
], |
|
109
|
|
|
'should not break logic with entities that not consist originId' => [ |
|
110
|
|
|
'$items' => [$someEntity, $someEntity2], |
|
111
|
|
|
'$expectedItems' => [$someEntity, $someEntity2] |
|
112
|
|
|
] |
|
113
|
|
|
]; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
View Code Duplication |
public function testSetStepExecutionSetToWrappedWriter() |
|
|
|
|
|
|
117
|
|
|
{ |
|
118
|
|
|
$wrapped = $this->getMock('OroCRM\Bundle\MagentoBundle\Tests\Unit\Stub\StepExecutionAwareWriter'); |
|
119
|
|
|
$writer = new ProxyEntityWriter($wrapped, $this->databaseHelper); |
|
120
|
|
|
$stepExecution = $this->getMockBuilder('Akeneo\Bundle\BatchBundle\Entity\StepExecution') |
|
121
|
|
|
->disableOriginalConstructor()->getMock(); |
|
122
|
|
|
$wrapped->expects($this->once())->method('setStepExecution') |
|
123
|
|
|
->with($this->equalTo($stepExecution)); |
|
124
|
|
|
|
|
125
|
|
|
$writer->setStepExecution($stepExecution); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function testSetStepExecutionDoesNotProvokeErrorWithRegularWriter() |
|
129
|
|
|
{ |
|
130
|
|
|
$stepExecution = $this->getMockBuilder('Akeneo\Bundle\BatchBundle\Entity\StepExecution') |
|
131
|
|
|
->disableOriginalConstructor()->getMock(); |
|
132
|
|
|
|
|
133
|
|
|
$this->writer->setStepExecution($stepExecution); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.