1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Unit\Console\Command; |
7
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Console\Command\ExportOrderCommand; |
9
|
|
|
use CommerceLeague\ActiveCampaign\MessageQueue\Topics; |
10
|
|
|
use Magento\Framework\Console\Cli; |
11
|
|
|
use Magento\Framework\MessageQueue\PublisherInterface; |
12
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Order\CollectionFactory as OrderCollectionFactory; |
|
|
|
|
15
|
|
|
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Order\Collection as OrderCollection; |
16
|
|
|
use Symfony\Component\Console\Exception\RuntimeException; |
17
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
18
|
|
|
use Symfony\Component\Console\Helper\ProgressBarFactory; |
|
|
|
|
19
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
20
|
|
|
|
21
|
|
|
class ExportOrderCommandTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var MockObject|OrderCollectionFactory |
25
|
|
|
*/ |
26
|
|
|
protected $orderCollectionFactory; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var MockObject|OrderCollection |
30
|
|
|
*/ |
31
|
|
|
protected $orderCollection; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var MockObject|PublisherInterface |
35
|
|
|
*/ |
36
|
|
|
protected $publisher; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var MockObject|ProgressBarFactory |
40
|
|
|
*/ |
41
|
|
|
protected $progressBarFactory; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var ExportOrderCommand |
45
|
|
|
*/ |
46
|
|
|
protected $exportOrderCommand; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var CommandTester |
50
|
|
|
*/ |
51
|
|
|
protected $exportOrderCommandTester; |
52
|
|
|
|
53
|
|
|
protected function setUp() |
54
|
|
|
{ |
55
|
|
|
$this->orderCollectionFactory = $this->getMockBuilder(OrderCollectionFactory::class) |
56
|
|
|
->disableOriginalConstructor() |
57
|
|
|
->setMethods(['create']) |
58
|
|
|
->getMock(); |
59
|
|
|
|
60
|
|
|
$this->orderCollection = $this->createMock(OrderCollection::class); |
61
|
|
|
|
62
|
|
|
$this->orderCollectionFactory->expects($this->any()) |
63
|
|
|
->method('create') |
64
|
|
|
->willReturn($this->orderCollection); |
65
|
|
|
|
66
|
|
|
$this->publisher = $this->createMock(PublisherInterface::class); |
67
|
|
|
|
68
|
|
|
$this->progressBarFactory = $this->getMockBuilder(ProgressBarFactory::class) |
69
|
|
|
->disableOriginalConstructor() |
70
|
|
|
->setMethods(['create']) |
71
|
|
|
->getMock(); |
72
|
|
|
|
73
|
|
|
$this->exportOrderCommand = new ExportOrderCommand( |
74
|
|
|
$this->orderCollectionFactory, |
75
|
|
|
$this->progressBarFactory, |
76
|
|
|
$this->publisher |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$this->exportOrderCommandTester = new CommandTester($this->exportOrderCommand); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testExecuteWithoutOptions() |
83
|
|
|
{ |
84
|
|
|
$this->expectException(RuntimeException::class); |
85
|
|
|
$this->expectExceptionMessage('Please provide at least one option'); |
86
|
|
|
|
87
|
|
|
$this->exportOrderCommandTester->execute([]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testExecuteWithOrderIdAndOtherOptions() |
91
|
|
|
{ |
92
|
|
|
$this->expectException(RuntimeException::class); |
93
|
|
|
$this->expectExceptionMessage('You cannot use --order-id together with another option'); |
94
|
|
|
|
95
|
|
|
$this->exportOrderCommandTester->execute( |
96
|
|
|
['--order-id' => 123, '--omitted' => true, '--all' => true] |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testExecuteWithAllAndOmittedOption() |
101
|
|
|
{ |
102
|
|
|
$this->expectException(RuntimeException::class); |
103
|
|
|
$this->expectExceptionMessage('You cannot use --omitted and --all together'); |
104
|
|
|
|
105
|
|
|
$this->exportOrderCommandTester->execute( |
106
|
|
|
['--omitted' => true, '--all' => true] |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testExecuteWithoutOrderIds() |
111
|
|
|
{ |
112
|
|
|
$this->orderCollection->expects($this->once()) |
|
|
|
|
113
|
|
|
->method('getAllIds') |
114
|
|
|
->willReturn([]); |
115
|
|
|
|
116
|
|
|
$this->exportOrderCommandTester->execute( |
117
|
|
|
['--all' => true] |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
$this->assertContains( |
121
|
|
|
'No order(s) found matching your criteria', |
122
|
|
|
$this->exportOrderCommandTester->getDisplay() |
123
|
|
|
); |
124
|
|
|
|
125
|
|
|
$this->assertEquals( |
126
|
|
|
Cli::RETURN_FAILURE, |
127
|
|
|
$this->exportOrderCommandTester->getStatusCode() |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function testExecuteWithOrderIdOption() |
132
|
|
|
{ |
133
|
|
|
$orderId = 123; |
134
|
|
|
|
135
|
|
|
$this->orderCollection->expects($this->once()) |
136
|
|
|
->method('addExcludeGuestFilter') |
137
|
|
|
->willReturnSelf(); |
138
|
|
|
|
139
|
|
|
$this->orderCollection->expects($this->once()) |
140
|
|
|
->method('addIdFilter') |
141
|
|
|
->with($orderId) |
142
|
|
|
->willReturnSelf(); |
143
|
|
|
|
144
|
|
|
$this->orderCollection->expects($this->never()) |
145
|
|
|
->method('addOmittedFilter'); |
146
|
|
|
|
147
|
|
|
$this->orderCollection->expects($this->once()) |
148
|
|
|
->method('getAllIds') |
149
|
|
|
->willReturn([$orderId]); |
150
|
|
|
|
151
|
|
|
$progressBar = new ProgressBar(new TestOutput()); |
152
|
|
|
|
153
|
|
|
$this->progressBarFactory->expects($this->once()) |
154
|
|
|
->method('create') |
155
|
|
|
->willReturn($progressBar); |
156
|
|
|
|
157
|
|
|
$this->publisher->expects($this->once()) |
|
|
|
|
158
|
|
|
->method('publish') |
159
|
|
|
->with( |
160
|
|
|
Topics::SALES_ORDER_EXPORT, |
161
|
|
|
json_encode(['magento_order_id' => $orderId]) |
162
|
|
|
); |
163
|
|
|
|
164
|
|
|
$this->exportOrderCommandTester->execute( |
165
|
|
|
['--order-id' => $orderId] |
166
|
|
|
); |
167
|
|
|
|
168
|
|
|
$this->assertContains( |
169
|
|
|
'1 order(s) have been scheduled for export.', |
170
|
|
|
$this->exportOrderCommandTester->getDisplay() |
171
|
|
|
); |
172
|
|
|
|
173
|
|
|
$this->assertEquals(Cli::RETURN_SUCCESS, $this->exportOrderCommandTester->getStatusCode()); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function testWithOmittedOption() |
177
|
|
|
{ |
178
|
|
|
$orderIds = [123, 456]; |
179
|
|
|
|
180
|
|
|
$this->orderCollection->expects($this->once()) |
181
|
|
|
->method('addExcludeGuestFilter') |
182
|
|
|
->willReturnSelf(); |
183
|
|
|
|
184
|
|
|
$this->orderCollection->expects($this->never()) |
185
|
|
|
->method('addIdFilter'); |
186
|
|
|
|
187
|
|
|
$this->orderCollection->expects($this->once()) |
188
|
|
|
->method('addOmittedFilter') |
189
|
|
|
->willReturnSelf(); |
190
|
|
|
|
191
|
|
|
$this->orderCollection->expects($this->once()) |
192
|
|
|
->method('getAllIds') |
193
|
|
|
->willReturn($orderIds); |
194
|
|
|
|
195
|
|
|
$progressBar = new ProgressBar(new TestOutput()); |
196
|
|
|
|
197
|
|
|
$this->progressBarFactory->expects($this->once()) |
198
|
|
|
->method('create') |
199
|
|
|
->willReturn($progressBar); |
200
|
|
|
|
201
|
|
|
$this->publisher->expects($this->exactly(2)) |
202
|
|
|
->method('publish'); |
203
|
|
|
|
204
|
|
|
$this->exportOrderCommandTester->execute( |
205
|
|
|
['--omitted' => true] |
206
|
|
|
); |
207
|
|
|
|
208
|
|
|
$this->assertContains( |
209
|
|
|
'2 order(s) have been scheduled for export.', |
210
|
|
|
$this->exportOrderCommandTester->getDisplay() |
211
|
|
|
); |
212
|
|
|
|
213
|
|
|
$this->assertEquals(Cli::RETURN_SUCCESS, $this->exportOrderCommandTester->getStatusCode()); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function testExecuteWithAllOption() |
217
|
|
|
{ |
218
|
|
|
$orderIds = [123, 456, 789]; |
219
|
|
|
|
220
|
|
|
$this->orderCollection->expects($this->once()) |
221
|
|
|
->method('addExcludeGuestFilter') |
222
|
|
|
->willReturnSelf(); |
223
|
|
|
|
224
|
|
|
$this->orderCollection->expects($this->never()) |
225
|
|
|
->method('addIdFilter'); |
226
|
|
|
|
227
|
|
|
$this->orderCollection->expects($this->never()) |
228
|
|
|
->method('addOmittedFilter'); |
229
|
|
|
|
230
|
|
|
$this->orderCollection->expects($this->once()) |
231
|
|
|
->method('getAllIds') |
232
|
|
|
->willReturn($orderIds); |
233
|
|
|
|
234
|
|
|
$progressBar = new ProgressBar(new TestOutput()); |
235
|
|
|
|
236
|
|
|
$this->progressBarFactory->expects($this->once()) |
237
|
|
|
->method('create') |
238
|
|
|
->willReturn($progressBar); |
239
|
|
|
|
240
|
|
|
$this->publisher->expects($this->exactly(3)) |
241
|
|
|
->method('publish'); |
242
|
|
|
|
243
|
|
|
$this->exportOrderCommandTester->execute( |
244
|
|
|
['--all' => true] |
245
|
|
|
); |
246
|
|
|
|
247
|
|
|
$this->assertContains( |
248
|
|
|
'3 order(s) have been scheduled for export.', |
249
|
|
|
$this->exportOrderCommandTester->getDisplay() |
250
|
|
|
); |
251
|
|
|
|
252
|
|
|
$this->assertEquals(Cli::RETURN_SUCCESS, $this->exportOrderCommandTester->getStatusCode()); |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths