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

testExecuteWithoutOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 6
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\ExportCustomerCommand;
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\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...
15
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Magento\CustomerCollection;
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 ExportCustomerCommandTest extends TestCase
22
{
23
    /**
24
     * @var MockObject|CustomerCollectionFactory
25
     */
26
    protected $customerCollectionFactory;
27
28
    /**
29
     * @var MockObject|CustomerCollection
30
     */
31
    protected $customerCollection;
32
33
    /**
34
     * @var MockObject|PublisherInterface
35
     */
36
    protected $publisher;
37
38
    /**
39
     * @var MockObject|ProgressBarFactory
40
     */
41
    protected $progressBarFactory;
42
43
    /**
44
     * @var ExportCustomerCommand
45
     */
46
    protected $exportCustomerCommand;
47
48
    /**
49
     * @var CommandTester
50
     */
51
    protected $exportCustomerCommandTester;
52
53
    public function setUp()
54
    {
55
        $this->customerCollectionFactory = $this->getMockBuilder(CustomerCollectionFactory::class)
56
            ->disableOriginalConstructor()
57
            ->setMethods(['create'])
58
            ->getMock();
59
60
        $this->customerCollection = $this->createMock(CustomerCollection::class);
61
62
        $this->customerCollectionFactory->expects($this->any())
63
            ->method('create')
64
            ->willReturn($this->customerCollection);
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->exportCustomerCommand = new ExportCustomerCommand(
74
            $this->customerCollectionFactory,
75
            $this->publisher,
76
            $this->progressBarFactory
77
        );
78
79
        $this->exportCustomerCommandTester = new CommandTester($this->exportCustomerCommand);
80
    }
81
82
    public function testExecuteWithoutOptions()
83
    {
84
        $this->expectException(RuntimeException::class);
85
        $this->expectExceptionMessage('Please provide at least one option');
86
87
        $this->exportCustomerCommandTester->execute([]);
88
    }
89
90
    public function testExecuteWithEmailAndOtherOptions()
91
    {
92
        $this->expectException(RuntimeException::class);
93
        $this->expectExceptionMessage('You cannot use --email together with another option');
94
95
        $this->exportCustomerCommandTester->execute(
96
            ['--email' => '[email protected]', '--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->exportCustomerCommandTester->execute(
106
            ['--omitted' => true, '--all' => true]
107
        );
108
    }
109
110
    public function testExecuteWithoutCustomerIds()
111
    {
112
        $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

112
        $this->customerCollection->/** @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->exportCustomerCommandTester->execute(
117
            ['--all' => true]
118
        );
119
120
        $this->assertContains(
121
            'No customer(s) found matching your criteria',
122
            $this->exportCustomerCommandTester->getDisplay()
123
        );
124
125
        $this->assertEquals(
126
            Cli::RETURN_FAILURE,
127
            $this->exportCustomerCommandTester->getStatusCode()
128
        );
129
    }
130
131
    public function testExecuteWithEmailOption()
132
    {
133
        $email = '[email protected]';
134
        $customerId = 123;
135
136
        $this->customerCollection->expects($this->once())
137
            ->method('addEmailFilter')
138
            ->with($email)
139
            ->willReturnSelf();
140
141
        $this->customerCollection->expects($this->never())
142
            ->method('addCustomerOmittedFilter');
143
144
        $this->customerCollection->expects($this->once())
145
            ->method('getAllIds')
146
            ->willReturn([$customerId]);
147
148
        $progressBar = new ProgressBar(new TestOutput());
149
150
        $this->progressBarFactory->expects($this->once())
151
            ->method('create')
152
            ->willReturn($progressBar);
153
154
        $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

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