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; |
|
|
|
|
13
|
|
|
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Subscriber\Collection as SubscriberCollection; |
14
|
|
|
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Subscriber\CollectionFactory as SubscriberCollectionFactory; |
|
|
|
|
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()) |
|
|
|
|
95
|
|
|
->method('isEnabled') |
96
|
|
|
->willReturn(false); |
97
|
|
|
|
98
|
|
|
$this->customerCollection->expects($this->never()) |
|
|
|
|
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()) |
|
|
|
|
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)) |
|
|
|
|
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
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths