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 ( a4bd13...c92bdf )
by Andreas
03:29
created

testExecuteWithAllAndOmittedOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 7
rs 10
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\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\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...
15
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Quote\Collection as QuoteCollection;
16
use Symfony\Component\Console\Exception\RuntimeException;
17
use Symfony\Component\Console\Helper\ProgressBar;
18
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...
19
use Symfony\Component\Console\Tester\CommandTester;
20
21
class ExportAbandonedCartCommandTest extends TestCase
22
{
23
    /**
24
     * @var MockObject|QuoteCollectionFactory
25
     */
26
    protected $quoteCollectionFactory;
27
28
    /**
29
     * @var MockObject|QuoteCollection
30
     */
31
    protected $quoteCollection;
32
33
    /**
34
     * @var MockObject|PublisherInterface
35
     */
36
    protected $publisher;
37
38
    /**
39
     * @var MockObject|ProgressBarFactory
40
     */
41
    protected $progressBarFactory;
42
43
    /**
44
     * @var ExportAbandonedCartCommand
45
     */
46
    protected $exportAbandonedCartCommand;
47
48
    /**
49
     * @var CommandTester
50
     */
51
    protected $exportAbandonedCartCommandTester;
52
53
    protected function setUp()
54
    {
55
        $this->quoteCollectionFactory = $this->getMockBuilder(QuoteCollectionFactory::class)
56
            ->disableOriginalConstructor()
57
            ->setMethods(['create'])
58
            ->getMock();
59
60
        $this->quoteCollection = $this->createMock(QuoteCollection::class);
61
62
        $this->quoteCollectionFactory->expects($this->any())
63
            ->method('create')
64
            ->willReturn($this->quoteCollection);
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->exportAbandonedCartCommand = new ExportAbandonedCartCommand(
74
            $this->quoteCollectionFactory,
75
            $this->progressBarFactory,
76
            $this->publisher
77
        );
78
79
        $this->exportAbandonedCartCommandTester = new CommandTester($this->exportAbandonedCartCommand);
80
    }
81
82
    public function testExecuteWithoutOptions()
83
    {
84
        $this->expectException(RuntimeException::class);
85
        $this->expectExceptionMessage('Please provide at least one option');
86
87
        $this->exportAbandonedCartCommandTester->execute([]);
88
    }
89
90
    public function testExecuteWithQuoteIdAndOtherOptions()
91
    {
92
        $this->expectException(RuntimeException::class);
93
        $this->expectExceptionMessage('You cannot use --quote-id together with another option');
94
95
        $this->exportAbandonedCartCommandTester->execute(
96
            ['--quote-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->exportAbandonedCartCommandTester->execute(
106
            ['--omitted' => true, '--all' => true]
107
        );
108
    }
109
110
    public function testExecuteWithoutQuoteIds()
111
    {
112
        $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

112
        $this->quoteCollection->/** @scrutinizer ignore-call */ 
113
                                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...
113
            ->method('getAllIds')
114
            ->willReturn([]);
115
116
        $this->exportAbandonedCartCommandTester->execute(
117
            ['--all' => true]
118
        );
119
120
        $this->assertContains(
121
            'No abandoned cart(s) found matching your criteria',
122
            $this->exportAbandonedCartCommandTester->getDisplay()
123
        );
124
125
        $this->assertEquals(
126
            Cli::RETURN_FAILURE,
127
            $this->exportAbandonedCartCommandTester->getStatusCode()
128
        );
129
    }
130
131
    public function testExecuteWithQuoteIdOption()
132
    {
133
        $quoteId = 123;
134
135
        $this->quoteCollection->expects($this->once())
136
            ->method('addIdFilter')
137
            ->with($quoteId)
138
            ->willReturnSelf();
139
140
        $this->quoteCollection->expects($this->never())
141
            ->method('addOmittedFilter');
142
143
        $this->quoteCollection->expects($this->once())
144
            ->method('getAllIds')
145
            ->willReturn([$quoteId]);
146
147
        $progressBar = new ProgressBar(new TestOutput());
148
149
        $this->progressBarFactory->expects($this->once())
150
            ->method('create')
151
            ->willReturn($progressBar);
152
153
        $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

153
        $this->publisher->/** @scrutinizer ignore-call */ 
154
                          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...
154
            ->method('publish')
155
            ->with(
156
                Topics::QUOTE_ABANDONED_CART_EXPORT,
157
                json_encode(['quote_id' => $quoteId])
158
            );
159
160
        $this->exportAbandonedCartCommandTester->execute(
161
            ['--quote-id' => $quoteId]
162
        );
163
164
        $this->assertContains(
165
            '1 abandoned cart(s) have been scheduled for export.',
166
            $this->exportAbandonedCartCommandTester->getDisplay()
167
        );
168
169
        $this->assertEquals(Cli::RETURN_SUCCESS, $this->exportAbandonedCartCommandTester->getStatusCode());
170
    }
171
172
    public function testExecuteWithOmittedOption()
173
    {
174
        $quoteIds = [123, 456];
175
176
        $this->quoteCollection->expects($this->never())
177
            ->method('addIdFilter');
178
179
        $this->quoteCollection->expects($this->once())
180
            ->method('addOmittedFilter')
181
            ->willReturnSelf();
182
183
        $this->quoteCollection->expects($this->once())
184
            ->method('getAllIds')
185
            ->willReturn($quoteIds);
186
187
        $progressBar = new ProgressBar(new TestOutput());
188
189
        $this->progressBarFactory->expects($this->once())
190
            ->method('create')
191
            ->willReturn($progressBar);
192
193
        $this->publisher->expects($this->exactly(2))
194
            ->method('publish');
195
196
        $this->exportAbandonedCartCommandTester->execute(
197
            ['--omitted' => true]
198
        );
199
200
        $this->assertContains(
201
            '2 abandoned cart(s) have been scheduled for export.',
202
            $this->exportAbandonedCartCommandTester->getDisplay()
203
        );
204
205
        $this->assertEquals(Cli::RETURN_SUCCESS, $this->exportAbandonedCartCommandTester->getStatusCode());
206
    }
207
208
    public function testExecuteWithAllOption()
209
    {
210
        $quoteIds = [123, 456, 789];
211
212
        $this->quoteCollection->expects($this->never())
213
            ->method('addIdFilter');
214
215
        $this->quoteCollection->expects($this->never())
216
            ->method('addOmittedFilter');
217
218
        $this->quoteCollection->expects($this->once())
219
            ->method('getAllIds')
220
            ->willReturn($quoteIds);
221
222
        $progressBar = new ProgressBar(new TestOutput());
223
224
        $this->progressBarFactory->expects($this->once())
225
            ->method('create')
226
            ->willReturn($progressBar);
227
228
        $this->publisher->expects($this->exactly(3))
229
            ->method('publish');
230
231
        $this->exportAbandonedCartCommandTester->execute(
232
            ['--all' => true]
233
        );
234
235
        $this->assertContains(
236
            '3 abandoned cart(s) have been scheduled for export.',
237
            $this->exportAbandonedCartCommandTester->getDisplay()
238
        );
239
240
        $this->assertEquals(Cli::RETURN_SUCCESS, $this->exportAbandonedCartCommandTester->getStatusCode());
241
    }
242
}
243