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 ( 416677...d8aab5 )
by Andreas
03:56
created

ExportOmittedContactsTest::testRun()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 65
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 46
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 65
rs 9.1781

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Test\Unit\Cron;
7
8
use CommerceLeague\ActiveCampaign\Cron\ExportOmittedContacts;
9
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper;
10
use CommerceLeague\ActiveCampaign\MessageQueue\Topics;
11
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Customer\Collection as CustomerCollection;
12
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...
13
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Subscriber\Collection as SubscriberCollection;
14
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Subscriber\CollectionFactory as SubscriberCollectionFactory;
0 ignored issues
show
Bug introduced by
The type CommerceLeague\ActiveCam...riber\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 Magento\Framework\MessageQueue\PublisherInterface;
16
use PHPUnit\Framework\MockObject\MockObject;
17
use PHPUnit\Framework\TestCase;
18
19
class ExportOmittedContactsTest extends TestCase
20
{
21
    /**
22
     * @var MockObject|ConfigHelper
23
     */
24
    protected $configHelper;
25
26
    /**
27
     * @var MockObject|CustomerCollectionFactory
28
     */
29
    protected $customerCollectionFactory;
30
31
    /**
32
     * @var MockObject|CustomerCollection
33
     */
34
    protected $customerCollection;
35
36
    /**
37
     * @var MockObject|SubscriberCollectionFactory
38
     */
39
    protected $subscriberCollectionFactory;
40
41
    /**
42
     * @var MockObject|SubscriberCollection
43
     */
44
    protected $subscriberCollection;
45
46
    /**
47
     * @var MockObject|PublisherInterface
48
     */
49
    protected $publisher;
50
51
    /**
52
     * @var ExportOmittedContacts
53
     */
54
    protected $exportOmittedContacts;
55
56
    protected function setUp()
57
    {
58
        $this->configHelper = $this->createMock(ConfigHelper::class);
59
60
        $this->customerCollectionFactory = $this->getMockBuilder(CustomerCollectionFactory::class)
61
            ->disableOriginalConstructor()
62
            ->setMethods(['create'])
63
            ->getMock();
64
65
        $this->customerCollection = $this->createMock(CustomerCollection::class);
66
67
        $this->customerCollectionFactory->expects($this->any())
68
            ->method('create')
69
            ->willReturn($this->customerCollection);
70
71
        $this->subscriberCollectionFactory = $this->getMockBuilder(SubscriberCollectionFactory::class)
72
            ->disableOriginalConstructor()
73
            ->setMethods(['create'])
74
            ->getMock();
75
76
        $this->subscriberCollection = $this->createMock(SubscriberCollection::class);
77
78
        $this->subscriberCollectionFactory->expects($this->any())
79
            ->method('create')
80
            ->willReturn($this->subscriberCollection);
81
82
        $this->publisher = $this->createMock(PublisherInterface::class);
83
84
        $this->exportOmittedContacts = new ExportOmittedContacts(
85
            $this->configHelper,
86
            $this->customerCollectionFactory,
87
            $this->subscriberCollectionFactory,
88
            $this->publisher
89
        );
90
    }
91
92
    public function testRunDisabled()
93
    {
94
        $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

94
        $this->configHelper->/** @scrutinizer ignore-call */ 
95
                             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...
95
            ->method('isEnabled')
96
            ->willReturn(false);
97
98
        $this->customerCollection->expects($this->never())
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

98
        $this->customerCollection->/** @scrutinizer ignore-call */ 
99
                                   expects($this->never())

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...
99
            ->method('addContactOmittedFilter');
100
101
        $this->exportOmittedContacts->run();
102
    }
103
104
    public function testRunContactExportDisabled()
105
    {
106
        $this->configHelper->expects($this->once())
107
            ->method('isEnabled')
108
            ->willReturn(true);
109
110
        $this->configHelper->expects($this->once())
111
            ->method('isContactExportEnabled')
112
            ->willReturn(false);
113
114
        $this->customerCollection->expects($this->never())
115
            ->method('addContactOmittedFilter');
116
117
        $this->exportOmittedContacts->run();
118
    }
119
120
    public function testRun()
121
    {
122
        $customerIds = [123, 456];
123
        $emails = ['[email protected]', '[email protected]'];
124
125
        $this->configHelper->expects($this->once())
126
            ->method('isEnabled')
127
            ->willReturn(true);
128
129
        $this->configHelper->expects($this->once())
130
            ->method('isContactExportEnabled')
131
            ->willReturn(true);
132
133
        $this->customerCollection->expects($this->once())
134
            ->method('addContactOmittedFilter')
135
            ->willReturnSelf();
136
137
        $this->customerCollection->expects($this->once())
138
            ->method('getAllIds')
139
            ->willReturn($customerIds);
140
141
        $this->subscriberCollection->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on CommerceLeague\ActiveCam...l\Subscriber\Collection. ( 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->subscriberCollection->/** @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('excludeCustomers')
143
            ->willReturnSelf();
144
145
        $this->subscriberCollection->expects($this->once())
146
            ->method('addContactOmittedFilter')
147
            ->willReturnSelf();
148
149
        $this->subscriberCollection->expects($this->once())
150
            ->method('getAllEmails')
151
            ->willReturn($emails);
152
153
        $this->publisher->expects($this->exactly(4))
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->exactly(4))

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
156
        $this->publisher->expects($this->at(0))
157
            ->method('publish')
158
            ->with(
159
                Topics::CUSTOMER_CONTACT_EXPORT,
160
                json_encode(['magento_customer_id' => $customerIds[0]])
161
            );
162
163
        $this->publisher->expects($this->at(1))
164
            ->method('publish')
165
            ->with(
166
                Topics::CUSTOMER_CONTACT_EXPORT,
167
                json_encode(['magento_customer_id' => $customerIds[1]])
168
            );
169
170
        $this->publisher->expects($this->at(2))
171
            ->method('publish')
172
            ->with(
173
                Topics::NEWSLETTER_CONTACT_EXPORT,
174
                json_encode(['email' => $emails[0]])
175
            );
176
177
        $this->publisher->expects($this->at(3))
178
            ->method('publish')
179
            ->with(
180
                Topics::NEWSLETTER_CONTACT_EXPORT,
181
                json_encode(['email' => $emails[1]])
182
            );
183
184
        $this->exportOmittedContacts->run();
185
    }
186
}
187