|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Unit\Cron; |
|
7
|
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Cron\ExportOmittedCustomers; |
|
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 Magento\Framework\MessageQueue\PublisherInterface; |
|
14
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
class ExportOmittedCustomersTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var MockObject|ConfigHelper |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $configHelper; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var MockObject|CustomerCollectionFactory |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $customerCollectionFactory; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var MockObject|CustomerCollection |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $customerCollection; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var MockObject|PublisherInterface |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $publisher; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var ExportOmittedCustomers |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $exportOmittedCustomers; |
|
43
|
|
|
|
|
44
|
|
|
protected function setUp() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->configHelper = $this->createMock(ConfigHelper::class); |
|
47
|
|
|
|
|
48
|
|
|
$this->customerCollectionFactory = $this->getMockBuilder(CustomerCollectionFactory::class) |
|
49
|
|
|
->disableOriginalConstructor() |
|
50
|
|
|
->setMethods(['create']) |
|
51
|
|
|
->getMock(); |
|
52
|
|
|
|
|
53
|
|
|
$this->customerCollection = $this->createMock(CustomerCollection::class); |
|
54
|
|
|
|
|
55
|
|
|
$this->customerCollectionFactory->expects($this->any()) |
|
56
|
|
|
->method('create') |
|
57
|
|
|
->willReturn($this->customerCollection); |
|
58
|
|
|
|
|
59
|
|
|
$this->publisher = $this->createMock(PublisherInterface::class); |
|
60
|
|
|
|
|
61
|
|
|
$this->exportOmittedCustomers = new ExportOmittedCustomers( |
|
62
|
|
|
$this->configHelper, |
|
63
|
|
|
$this->customerCollectionFactory, |
|
64
|
|
|
$this->publisher |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testRunDisabled() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->configHelper->expects($this->once()) |
|
|
|
|
|
|
71
|
|
|
->method('isEnabled') |
|
72
|
|
|
->willReturn(false); |
|
73
|
|
|
|
|
74
|
|
|
$this->customerCollection->expects($this->never()) |
|
|
|
|
|
|
75
|
|
|
->method('addCustomerOmittedFilter'); |
|
76
|
|
|
|
|
77
|
|
|
$this->exportOmittedCustomers->run(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testRunContactExportDisabled() |
|
81
|
|
|
{ |
|
82
|
|
|
$this->configHelper->expects($this->once()) |
|
83
|
|
|
->method('isEnabled') |
|
84
|
|
|
->willReturn(true); |
|
85
|
|
|
|
|
86
|
|
|
$this->configHelper->expects($this->once()) |
|
87
|
|
|
->method('isCustomerExportEnabled') |
|
88
|
|
|
->willReturn(false); |
|
89
|
|
|
|
|
90
|
|
|
$this->customerCollection->expects($this->never()) |
|
91
|
|
|
->method('addCustomerOmittedFilter'); |
|
92
|
|
|
|
|
93
|
|
|
$this->exportOmittedCustomers->run(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testRun() |
|
97
|
|
|
{ |
|
98
|
|
|
$customerIds = [123, 456]; |
|
99
|
|
|
|
|
100
|
|
|
$this->configHelper->expects($this->once()) |
|
101
|
|
|
->method('isEnabled') |
|
102
|
|
|
->willReturn(true); |
|
103
|
|
|
|
|
104
|
|
|
$this->configHelper->expects($this->once()) |
|
105
|
|
|
->method('isCustomerExportEnabled') |
|
106
|
|
|
->willReturn(true); |
|
107
|
|
|
|
|
108
|
|
|
$this->customerCollection->expects($this->once()) |
|
109
|
|
|
->method('addCustomerOmittedFilter') |
|
110
|
|
|
->willReturnSelf(); |
|
111
|
|
|
|
|
112
|
|
|
$this->customerCollection->expects($this->once()) |
|
113
|
|
|
->method('getAllIds') |
|
114
|
|
|
->willReturn($customerIds); |
|
115
|
|
|
|
|
116
|
|
|
$this->publisher->expects($this->exactly(2)) |
|
|
|
|
|
|
117
|
|
|
->method('publish'); |
|
118
|
|
|
|
|
119
|
|
|
$this->publisher->expects($this->at(0)) |
|
120
|
|
|
->method('publish') |
|
121
|
|
|
->with( |
|
122
|
|
|
Topics::CUSTOMER_CUSTOMER_EXPORT, |
|
123
|
|
|
json_encode(['magento_customer_id' => $customerIds[0]]) |
|
124
|
|
|
); |
|
125
|
|
|
|
|
126
|
|
|
$this->publisher->expects($this->at(1)) |
|
127
|
|
|
->method('publish') |
|
128
|
|
|
->with( |
|
129
|
|
|
Topics::CUSTOMER_CUSTOMER_EXPORT, |
|
130
|
|
|
json_encode(['magento_customer_id' => $customerIds[1]]) |
|
131
|
|
|
); |
|
132
|
|
|
|
|
133
|
|
|
$this->exportOmittedCustomers->run(); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
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