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

testExecuteWithAllAndOmittedOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 15
rs 9.9332
c 1
b 0
f 1
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\ExportCustomerCommand;
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\Customer\CollectionFactory as CustomerCollectionFactory;
0 ignored issues
show
Bug introduced by
The type CommerceLeague\ActiveCam...tomer\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\Customer\Collection as CustomerCollection;
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 ExportCustomerCommandTest extends TestCase
23
{
24
    /**
25
     * @var MockObject|ConfigHelper
26
     */
27
    protected $configHelper;
28
29
    /**
30
     * @var MockObject|CustomerCollectionFactory
31
     */
32
    protected $customerCollectionFactory;
33
34
    /**
35
     * @var MockObject|CustomerCollection
36
     */
37
    protected $customerCollection;
38
39
    /**
40
     * @var MockObject|ProgressBarFactory
41
     */
42
    protected $progressBarFactory;
43
44
    /**
45
     * @var MockObject|PublisherInterface
46
     */
47
    protected $publisher;
48
49
    /**
50
     * @var ExportCustomerCommand
51
     */
52
    protected $exportCustomerCommand;
53
54
    /**
55
     * @var CommandTester
56
     */
57
    protected $exportCustomerCommandTester;
58
59
    protected function setUp()
60
    {
61
        $this->configHelper = $this->createMock(ConfigHelper::class);
62
63
        $this->customerCollectionFactory = $this->getMockBuilder(CustomerCollectionFactory::class)
64
            ->disableOriginalConstructor()
65
            ->setMethods(['create'])
66
            ->getMock();
67
68
        $this->customerCollection = $this->createMock(CustomerCollection::class);
69
70
        $this->customerCollectionFactory->expects($this->any())
71
            ->method('create')
72
            ->willReturn($this->customerCollection);
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->exportCustomerCommand = new ExportCustomerCommand(
82
            $this->configHelper,
83
            $this->customerCollectionFactory,
84
            $this->progressBarFactory,
85
            $this->publisher
86
        );
87
88
        $this->exportCustomerCommandTester = new CommandTester($this->exportCustomerCommand);
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->exportCustomerCommandTester->execute([]);
101
    }
102
103
    public function testExecuteCustomerExportDisabled()
104
    {
105
        $this->configHelper->expects($this->once())
106
            ->method('isEnabled')
107
            ->willReturn(true);
108
109
        $this->configHelper->expects($this->once())
110
            ->method('isCustomerExportEnabled')
111
            ->willReturn(false);
112
113
        $this->expectException(RuntimeException::class);
114
        $this->expectExceptionMessage('Export disabled by system configuration');
115
116
        $this->exportCustomerCommandTester->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('isCustomerExportEnabled')
127
            ->willReturn(true);
128
129
        $this->expectException(RuntimeException::class);
130
        $this->expectExceptionMessage('Please provide at least one option');
131
132
        $this->exportCustomerCommandTester->execute([]);
133
    }
134
135
    public function testExecuteWithEmailAndOtherOptions()
136
    {
137
        $this->configHelper->expects($this->once())
138
            ->method('isEnabled')
139
            ->willReturn(true);
140
141
        $this->configHelper->expects($this->once())
142
            ->method('isCustomerExportEnabled')
143
            ->willReturn(true);
144
145
        $this->expectException(RuntimeException::class);
146
        $this->expectExceptionMessage('You cannot use --email together with another option');
147
148
        $this->exportCustomerCommandTester->execute(
149
            ['--email' => '[email protected]', '--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('isCustomerExportEnabled')
161
            ->willReturn(true);
162
163
        $this->expectException(RuntimeException::class);
164
        $this->expectExceptionMessage('You cannot use --omitted and --all together');
165
166
        $this->exportCustomerCommandTester->execute(
167
            ['--omitted' => true, '--all' => true]
168
        );
169
    }
170
171
    public function testExecuteWithoutCustomerIds()
172
    {
173
        $this->configHelper->expects($this->once())
174
            ->method('isEnabled')
175
            ->willReturn(true);
176
177
        $this->configHelper->expects($this->once())
178
            ->method('isCustomerExportEnabled')
179
            ->willReturn(true);
180
181
        $this->customerCollection->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...del\Customer\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->customerCollection->/** @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->exportCustomerCommandTester->execute(
186
            ['--all' => true]
187
        );
188
189
        $this->assertContains(
190
            'No customer(s) found matching your criteria',
191
            $this->exportCustomerCommandTester->getDisplay()
192
        );
193
194
        $this->assertEquals(
195
            Cli::RETURN_FAILURE,
196
            $this->exportCustomerCommandTester->getStatusCode()
197
        );
198
    }
199
200
    public function testExecuteWithEmailOption()
201
    {
202
        $email = '[email protected]';
203
        $customerId = 123;
204
205
        $this->configHelper->expects($this->once())
206
            ->method('isEnabled')
207
            ->willReturn(true);
208
209
        $this->configHelper->expects($this->once())
210
            ->method('isCustomerExportEnabled')
211
            ->willReturn(true);
212
213
        $this->customerCollection->expects($this->once())
214
            ->method('addEmailFilter')
215
            ->with($email)
216
            ->willReturnSelf();
217
218
        $this->customerCollection->expects($this->never())
219
            ->method('addCustomerOmittedFilter');
220
221
        $this->customerCollection->expects($this->once())
222
            ->method('getAllIds')
223
            ->willReturn([$customerId]);
224
225
        $progressBar = new ProgressBar(new TestOutput());
226
227
        $this->progressBarFactory->expects($this->once())
228
            ->method('create')
229
            ->willReturn($progressBar);
230
231
        $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

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