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 ( b3bc9a...63b552 )
by Andreas
03:47
created

testExecuteWithOmittedOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 46
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 30
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 46
rs 9.44
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace Test\Unit\Console\Command;
7
8
use CommerceLeague\ActiveCampaign\Console\Command\ExportContactCommand;
9
use CommerceLeague\ActiveCampaign\MessageQueue\Topics;
10
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Magento\CustomerCollection;
11
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Magento\CustomerCollectionFactory;
0 ignored issues
show
Bug introduced by
The type CommerceLeague\ActiveCam...stomerCollectionFactory 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...
12
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Magento\SubscriberCollection;
13
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Magento\SubscriberCollectionFactory;
0 ignored issues
show
Bug introduced by
The type CommerceLeague\ActiveCam...criberCollectionFactory 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...
14
use CommerceLeague\ActiveCampaign\Test\Unit\Console\Command\TestOutput;
15
use Magento\Framework\Console\Cli;
16
use Magento\Framework\MessageQueue\PublisherInterface;
17
use PHPUnit\Framework\MockObject\MockObject;
18
use PHPUnit\Framework\TestCase;
19
use Symfony\Component\Console\Exception\RuntimeException;
20
use Symfony\Component\Console\Helper\ProgressBar;
21
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...
22
use Symfony\Component\Console\Tester\CommandTester;
23
24
/**
25
 * @group current
26
 */
27
class ExportContactCommandTest extends TestCase
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|SubscriberCollectionFactory
41
     */
42
    protected $subscriberCollectionFactory;
43
44
    /**
45
     * @var MockObject|SubscriberCollection
46
     */
47
    protected $subscriberCollection;
48
49
    /**
50
     * @var MockObject|PublisherInterface
51
     */
52
    protected $publisher;
53
54
    /**
55
     * @var MockObject|ProgressBarFactory
56
     */
57
    protected $progressBarFactory;
58
59
    /**
60
     * @var ExportContactCommand
61
     */
62
    protected $exportContactCommand;
63
64
    /**
65
     * @var CommandTester
66
     */
67
    protected $exportContactCommandTester;
68
69
    protected function setUp()
70
    {
71
        $this->customerCollectionFactory = $this->getMockBuilder(CustomerCollectionFactory::class)
72
            ->disableOriginalConstructor()
73
            ->setMethods(['create'])
74
            ->getMock();
75
76
        $this->customerCollection = $this->createMock(CustomerCollection::class);
77
78
        $this->customerCollectionFactory->expects($this->any())
79
            ->method('create')
80
            ->willReturn($this->customerCollection);
81
82
        $this->subscriberCollectionFactory = $this->getMockBuilder(SubscriberCollectionFactory::class)
83
            ->disableOriginalConstructor()
84
            ->setMethods(['create'])
85
            ->getMock();
86
87
        $this->subscriberCollection = $this->createMock(SubscriberCollection::class);
88
89
        $this->subscriberCollectionFactory->expects($this->any())
90
            ->method('create')
91
            ->willReturn($this->subscriberCollection);
92
93
        $this->publisher = $this->createMock(PublisherInterface::class);
94
95
        $this->progressBarFactory = $this->getMockBuilder(ProgressBarFactory::class)
96
            ->disableOriginalConstructor()
97
            ->setMethods(['create'])
98
            ->getMock();
99
100
        $this->exportContactCommand = new ExportContactCommand(
101
            $this->customerCollectionFactory,
102
            $this->subscriberCollectionFactory,
103
            $this->publisher,
104
            $this->progressBarFactory
105
        );
106
107
        $this->exportContactCommandTester = new CommandTester($this->exportContactCommand);
108
    }
109
110
111
    public function testExecuteWithoutOptions()
112
    {
113
        $this->expectException(RuntimeException::class);
114
        $this->expectExceptionMessage('Please provide at least one option');
115
116
        $this->exportContactCommandTester->execute([]);
117
    }
118
119
    public function testExecuteWithEmailAndOtherOptions()
120
    {
121
        $this->expectException(RuntimeException::class);
122
        $this->expectExceptionMessage('You cannot use --email together with another option');
123
124
        $this->exportContactCommandTester->execute(
125
            ['--email' => '[email protected]', '--omitted' => true, '--all' => true]
126
        );
127
    }
128
129
    public function testExecuteWithAllAndOmittedOption()
130
    {
131
        $this->expectException(RuntimeException::class);
132
        $this->expectExceptionMessage('You cannot use --omitted and --all together');
133
134
        $this->exportContactCommandTester->execute(
135
            ['--omitted' => true, '--all' => true]
136
        );
137
    }
138
139
    public function testExecuteWithoutCustomerIdsAndSubscriberEmails()
140
    {
141
        $this->customerCollection->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...ento\CustomerCollection. ( Ignorable by Annotation )

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

141
        $this->customerCollection->/** @scrutinizer ignore-call */ 
142
                                   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...
142
            ->method('getAllIds')
143
            ->willReturn([]);
144
145
        $this->subscriberCollection->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...to\SubscriberCollection. ( Ignorable by Annotation )

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

145
        $this->subscriberCollection->/** @scrutinizer ignore-call */ 
146
                                     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...
146
            ->method('getAllEmails')
147
            ->willReturn([]);
148
149
        $this->exportContactCommandTester->execute(
150
            ['--all' => true]
151
        );
152
153
        $this->assertContains(
154
            'No contact(s) found matching your criteria',
155
            $this->exportContactCommandTester->getDisplay()
156
        );
157
158
        $this->assertEquals(
159
            Cli::RETURN_FAILURE,
160
            $this->exportContactCommandTester->getStatusCode()
161
        );
162
    }
163
164
    public function testExecuteWithEmailFromCustomerOption()
165
    {
166
        $email = '[email protected]';
167
        $customerId = 123;
168
169
        $this->customerCollection->expects($this->once())
170
            ->method('addEmailFilter')
171
            ->with($email)
172
            ->willReturnSelf();
173
174
        $this->customerCollection->expects($this->never())
175
            ->method('addCustomerOmittedFilter');
176
177
        $this->customerCollection->expects($this->once())
178
            ->method('getAllIds')
179
            ->willReturn([$customerId]);
180
181
        $progressBar = new ProgressBar(new TestOutput());
182
183
        $this->progressBarFactory->expects($this->once())
184
            ->method('create')
185
            ->willReturn($progressBar);
186
187
        $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

187
        $this->publisher->/** @scrutinizer ignore-call */ 
188
                          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...
188
            ->method('publish')
189
            ->with(
190
                Topics::CUSTOMER_CONTACT_EXPORT,
191
                json_encode(['magento_customer_id' => $customerId])
192
            );
193
194
        $this->exportContactCommandTester->execute(
195
            ['--email' => $email]
196
        );
197
198
        $this->assertContains(
199
            '1 contact(s) have been scheduled for export.',
200
            $this->exportContactCommandTester->getDisplay()
201
        );
202
203
        $this->assertEquals(Cli::RETURN_SUCCESS, $this->exportContactCommandTester->getStatusCode());
204
    }
205
206
    public function testExecuteWithEmailFromSubscriberOption()
207
    {
208
        $email = '[email protected]';
209
210
        $this->customerCollection->expects($this->once())
211
            ->method('addEmailFilter')
212
            ->with($email)
213
            ->willReturnSelf();
214
215
        $this->customerCollection->expects($this->never())
216
            ->method('addCustomerOmittedFilter');
217
218
        $this->customerCollection->expects($this->once())
219
            ->method('getAllIds')
220
            ->willReturn([]);
221
222
        $this->subscriberCollection->expects($this->once())
223
            ->method('excludeCustomers')
224
            ->willReturnSelf();
225
226
        $this->subscriberCollection->expects($this->once())
227
            ->method('addEmailFilter')
228
            ->willReturnSelf();
229
230
        $this->subscriberCollection->expects($this->never())
231
            ->method('addContactOmittedFilter');
232
233
        $this->subscriberCollection->expects($this->once())
234
            ->method('getAllEmails')
235
            ->willReturn([$email]);
236
237
        $progressBar = new ProgressBar(new TestOutput());
238
239
        $this->progressBarFactory->expects($this->once())
240
            ->method('create')
241
            ->willReturn($progressBar);
242
243
        $this->publisher->expects($this->once())
244
            ->method('publish')
245
            ->with(
246
                Topics::NEWSLETTER_CONTACT_EXPORT,
247
                json_encode(['email' => $email])
248
            );
249
250
        $this->exportContactCommandTester->execute(
251
            ['--email' => $email]
252
        );
253
254
        $this->assertContains(
255
            '1 contact(s) have been scheduled for export.',
256
            $this->exportContactCommandTester->getDisplay()
257
        );
258
259
        $this->assertEquals(Cli::RETURN_SUCCESS, $this->exportContactCommandTester->getStatusCode());
260
    }
261
262
    public function testExecuteWithOmittedOption()
263
    {
264
        $customerIds = [123, 456];
265
        $emails = ['[email protected]', '[email protected]'];
266
267
        $this->customerCollection->expects($this->never())
268
            ->method('addEmailFilter');
269
270
        $this->customerCollection->expects($this->once())
271
            ->method('addContactOmittedFilter')
272
            ->willReturnSelf();
273
274
        $this->customerCollection->expects($this->once())
275
            ->method('getAllIds')
276
            ->willReturn($customerIds);
277
278
        $this->subscriberCollection->expects($this->never())
279
            ->method('addEmailFilter');
280
281
        $this->subscriberCollection->expects($this->once())
282
            ->method('addContactOmittedFilter')
283
            ->willReturnSelf();
284
285
        $this->subscriberCollection->expects($this->once())
286
            ->method('getAllEmails')
287
            ->willReturn($emails);
288
289
        $progressBar = new ProgressBar(new TestOutput());
290
291
        $this->progressBarFactory->expects($this->exactly(2))
292
            ->method('create')
293
            ->willReturn($progressBar);
294
295
        $this->publisher->expects($this->exactly(4))
296
            ->method('publish');
297
298
        $this->exportContactCommandTester->execute(
299
            ['--omitted' => true]
300
        );
301
302
        $this->assertContains(
303
            '4 contact(s) have been scheduled for export.',
304
            $this->exportContactCommandTester->getDisplay()
305
        );
306
307
        $this->assertEquals(Cli::RETURN_SUCCESS, $this->exportContactCommandTester->getStatusCode());
308
    }
309
310
311
    public function testExecuteWithAllOption()
312
    {
313
        $customerIds = [123, 456];
314
        $emails = ['[email protected]', '[email protected]'];
315
316
        $this->customerCollection->expects($this->never())
317
            ->method('addEmailFilter');
318
319
        $this->customerCollection->expects($this->never())
320
            ->method('addContactOmittedFilter');
321
322
        $this->customerCollection->expects($this->once())
323
            ->method('getAllIds')
324
            ->willReturn($customerIds);
325
326
        $this->subscriberCollection->expects($this->never())
327
            ->method('addEmailFilter');
328
329
        $this->subscriberCollection->expects($this->never())
330
            ->method('addContactOmittedFilter');
331
332
        $this->subscriberCollection->expects($this->once())
333
            ->method('getAllEmails')
334
            ->willReturn($emails);
335
336
        $progressBar = new ProgressBar(new TestOutput());
337
338
        $this->progressBarFactory->expects($this->exactly(2))
339
            ->method('create')
340
            ->willReturn($progressBar);
341
342
        $this->publisher->expects($this->exactly(4))
343
            ->method('publish');
344
345
        $this->exportContactCommandTester->execute(
346
            ['--all' => true]
347
        );
348
349
        $this->assertContains(
350
            '4 contact(s) have been scheduled for export.',
351
            $this->exportContactCommandTester->getDisplay()
352
        );
353
354
        $this->assertEquals(Cli::RETURN_SUCCESS, $this->exportContactCommandTester->getStatusCode());
355
    }
356
}
357