GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c92bdf...416677 )
by Andreas
04:49
created

testExecuteAbandonedCartExportDisabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
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\ExportAbandonedCartCommand;
9
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper;
10
use CommerceLeague\ActiveCampaign\MessageQueue\Topics;
11
use Magento\Framework\Console\Cli;
12
use Magento\Framework\MessageQueue\PublisherInterface;
13
use PHPUnit\Framework\MockObject\MockObject;
14
use PHPUnit\Framework\TestCase;
15
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory;
0 ignored issues
show
Bug introduced by
The type CommerceLeague\ActiveCam...Quote\CollectionFactory was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Quote\Collection as QuoteCollection;
17
use Symfony\Component\Console\Exception\RuntimeException;
18
use Symfony\Component\Console\Helper\ProgressBar;
19
use Symfony\Component\Console\Helper\ProgressBarFactory;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Consol...lper\ProgressBarFactory was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Symfony\Component\Console\Tester\CommandTester;
21
22
class ExportAbandonedCartCommandTest extends TestCase
23
{
24
    /**
25
     * @var MockObject|ConfigHelper
26
     */
27
    protected $configHelper;
28
29
    /**
30
     * @var MockObject|QuoteCollectionFactory
31
     */
32
    protected $quoteCollectionFactory;
33
34
    /**
35
     * @var MockObject|QuoteCollection
36
     */
37
    protected $quoteCollection;
38
39
    /**
40
     * @var MockObject|PublisherInterface
41
     */
42
    protected $publisher;
43
44
    /**
45
     * @var MockObject|ProgressBarFactory
46
     */
47
    protected $progressBarFactory;
48
49
    /**
50
     * @var ExportAbandonedCartCommand
51
     */
52
    protected $exportAbandonedCartCommand;
53
54
    /**
55
     * @var CommandTester
56
     */
57
    protected $exportAbandonedCartCommandTester;
58
59
    protected function setUp()
60
    {
61
        $this->configHelper = $this->createMock(ConfigHelper::class);
62
63
        $this->quoteCollectionFactory = $this->getMockBuilder(QuoteCollectionFactory::class)
64
            ->disableOriginalConstructor()
65
            ->setMethods(['create'])
66
            ->getMock();
67
68
        $this->quoteCollection = $this->createMock(QuoteCollection::class);
69
70
        $this->quoteCollectionFactory->expects($this->any())
71
            ->method('create')
72
            ->willReturn($this->quoteCollection);
73
74
        $this->publisher = $this->createMock(PublisherInterface::class);
75
76
        $this->progressBarFactory = $this->getMockBuilder(ProgressBarFactory::class)
77
            ->disableOriginalConstructor()
78
            ->setMethods(['create'])
79
            ->getMock();
80
81
        $this->exportAbandonedCartCommand = new ExportAbandonedCartCommand(
82
            $this->configHelper,
83
            $this->quoteCollectionFactory,
84
            $this->progressBarFactory,
85
            $this->publisher
86
        );
87
88
        $this->exportAbandonedCartCommandTester = new CommandTester($this->exportAbandonedCartCommand);
89
    }
90
91
    public function testExecuteDisabled()
92
    {
93
        $this->configHelper->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCampaign\Helper\Config. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

93
        $this->configHelper->/** @scrutinizer ignore-call */ 
94
                             expects($this->once())

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.

Loading history...
94
            ->method('isEnabled')
95
            ->willReturn(false);
96
97
        $this->expectException(RuntimeException::class);
98
        $this->expectExceptionMessage('Export disabled by system configuration');
99
100
        $this->exportAbandonedCartCommandTester->execute([]);
101
    }
102
103
    public function testExecuteAbandonedCartExportDisabled()
104
    {
105
        $this->configHelper->expects($this->once())
106
            ->method('isEnabled')
107
            ->willReturn(true);
108
109
        $this->configHelper->expects($this->once())
110
            ->method('isAbandonedCartExportEnabled')
111
            ->willReturn(false);
112
113
        $this->expectException(RuntimeException::class);
114
        $this->expectExceptionMessage('Export disabled by system configuration');
115
116
        $this->exportAbandonedCartCommandTester->execute([]);
117
    }
118
119
    public function testExecuteWithoutOptions()
120
    {
121
        $this->configHelper->expects($this->once())
122
            ->method('isEnabled')
123
            ->willReturn(true);
124
125
        $this->configHelper->expects($this->once())
126
            ->method('isAbandonedCartExportEnabled')
127
            ->willReturn(true);
128
129
        $this->expectException(RuntimeException::class);
130
        $this->expectExceptionMessage('Please provide at least one option');
131
132
        $this->exportAbandonedCartCommandTester->execute([]);
133
    }
134
135
    public function testExecuteWithQuoteIdAndOtherOptions()
136
    {
137
        $this->configHelper->expects($this->once())
138
            ->method('isEnabled')
139
            ->willReturn(true);
140
141
        $this->configHelper->expects($this->once())
142
            ->method('isAbandonedCartExportEnabled')
143
            ->willReturn(true);
144
145
        $this->expectException(RuntimeException::class);
146
        $this->expectExceptionMessage('You cannot use --quote-id together with another option');
147
148
        $this->exportAbandonedCartCommandTester->execute(
149
            ['--quote-id' => 123, '--omitted' => true, '--all' => true]
150
        );
151
    }
152
153
    public function testExecuteWithAllAndOmittedOption()
154
    {
155
        $this->configHelper->expects($this->once())
156
            ->method('isEnabled')
157
            ->willReturn(true);
158
159
        $this->configHelper->expects($this->once())
160
            ->method('isAbandonedCartExportEnabled')
161
            ->willReturn(true);
162
163
        $this->expectException(RuntimeException::class);
164
        $this->expectExceptionMessage('You cannot use --omitted and --all together');
165
166
        $this->exportAbandonedCartCommandTester->execute(
167
            ['--omitted' => true, '--all' => true]
168
        );
169
    }
170
171
    public function testExecuteWithoutQuoteIds()
172
    {
173
        $this->configHelper->expects($this->once())
174
            ->method('isEnabled')
175
            ->willReturn(true);
176
177
        $this->configHelper->expects($this->once())
178
            ->method('isAbandonedCartExportEnabled')
179
            ->willReturn(true);
180
181
        $this->quoteCollection->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...eModel\Quote\Collection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

181
        $this->quoteCollection->/** @scrutinizer ignore-call */ 
182
                                expects($this->once())

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.

Loading history...
182
            ->method('getAllIds')
183
            ->willReturn([]);
184
185
        $this->exportAbandonedCartCommandTester->execute(
186
            ['--all' => true]
187
        );
188
189
        $this->assertContains(
190
            'No abandoned cart(s) found matching your criteria',
191
            $this->exportAbandonedCartCommandTester->getDisplay()
192
        );
193
194
        $this->assertEquals(
195
            Cli::RETURN_FAILURE,
196
            $this->exportAbandonedCartCommandTester->getStatusCode()
197
        );
198
    }
199
200
    public function testExecuteWithQuoteIdOption()
201
    {
202
        $quoteId = 123;
203
204
        $this->configHelper->expects($this->once())
205
            ->method('isEnabled')
206
            ->willReturn(true);
207
208
        $this->configHelper->expects($this->once())
209
            ->method('isAbandonedCartExportEnabled')
210
            ->willReturn(true);
211
212
        $this->quoteCollection->expects($this->once())
213
            ->method('addIdFilter')
214
            ->with($quoteId)
215
            ->willReturnSelf();
216
217
        $this->quoteCollection->expects($this->never())
218
            ->method('addOmittedFilter');
219
220
        $this->quoteCollection->expects($this->once())
221
            ->method('getAllIds')
222
            ->willReturn([$quoteId]);
223
224
        $progressBar = new ProgressBar(new TestOutput());
225
226
        $this->progressBarFactory->expects($this->once())
227
            ->method('create')
228
            ->willReturn($progressBar);
229
230
        $this->publisher->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Magento\Framework\MessageQueue\PublisherInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

230
        $this->publisher->/** @scrutinizer ignore-call */ 
231
                          expects($this->once())

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.

Loading history...
231
            ->method('publish')
232
            ->with(
233
                Topics::QUOTE_ABANDONED_CART_EXPORT,
234
                json_encode(['quote_id' => $quoteId])
235
            );
236
237
        $this->exportAbandonedCartCommandTester->execute(
238
            ['--quote-id' => $quoteId]
239
        );
240
241
        $this->assertContains(
242
            '1 abandoned cart(s) have been scheduled for export.',
243
            $this->exportAbandonedCartCommandTester->getDisplay()
244
        );
245
246
        $this->assertEquals(Cli::RETURN_SUCCESS, $this->exportAbandonedCartCommandTester->getStatusCode());
247
    }
248
249
    public function testExecuteWithOmittedOption()
250
    {
251
        $quoteIds = [123, 456];
252
253
        $this->configHelper->expects($this->once())
254
            ->method('isEnabled')
255
            ->willReturn(true);
256
257
        $this->configHelper->expects($this->once())
258
            ->method('isAbandonedCartExportEnabled')
259
            ->willReturn(true);
260
261
        $this->quoteCollection->expects($this->never())
262
            ->method('addIdFilter');
263
264
        $this->quoteCollection->expects($this->once())
265
            ->method('addOmittedFilter')
266
            ->willReturnSelf();
267
268
        $this->quoteCollection->expects($this->once())
269
            ->method('getAllIds')
270
            ->willReturn($quoteIds);
271
272
        $progressBar = new ProgressBar(new TestOutput());
273
274
        $this->progressBarFactory->expects($this->once())
275
            ->method('create')
276
            ->willReturn($progressBar);
277
278
        $this->publisher->expects($this->exactly(2))
279
            ->method('publish');
280
281
        $this->exportAbandonedCartCommandTester->execute(
282
            ['--omitted' => true]
283
        );
284
285
        $this->assertContains(
286
            '2 abandoned cart(s) have been scheduled for export.',
287
            $this->exportAbandonedCartCommandTester->getDisplay()
288
        );
289
290
        $this->assertEquals(Cli::RETURN_SUCCESS, $this->exportAbandonedCartCommandTester->getStatusCode());
291
    }
292
293
    public function testExecuteWithAllOption()
294
    {
295
        $quoteIds = [123, 456, 789];
296
297
        $this->configHelper->expects($this->once())
298
            ->method('isEnabled')
299
            ->willReturn(true);
300
301
        $this->configHelper->expects($this->once())
302
            ->method('isAbandonedCartExportEnabled')
303
            ->willReturn(true);
304
305
        $this->quoteCollection->expects($this->never())
306
            ->method('addIdFilter');
307
308
        $this->quoteCollection->expects($this->never())
309
            ->method('addOmittedFilter');
310
311
        $this->quoteCollection->expects($this->once())
312
            ->method('getAllIds')
313
            ->willReturn($quoteIds);
314
315
        $progressBar = new ProgressBar(new TestOutput());
316
317
        $this->progressBarFactory->expects($this->once())
318
            ->method('create')
319
            ->willReturn($progressBar);
320
321
        $this->publisher->expects($this->exactly(3))
322
            ->method('publish');
323
324
        $this->exportAbandonedCartCommandTester->execute(
325
            ['--all' => true]
326
        );
327
328
        $this->assertContains(
329
            '3 abandoned cart(s) have been scheduled for export.',
330
            $this->exportAbandonedCartCommandTester->getDisplay()
331
        );
332
333
        $this->assertEquals(Cli::RETURN_SUCCESS, $this->exportAbandonedCartCommandTester->getStatusCode());
334
    }
335
}
336