|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Unit\MessageQueue; |
|
7
|
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Api\CustomerRepositoryInterface; |
|
9
|
|
|
use CommerceLeague\ActiveCampaign\Api\Data\CustomerInterface; |
|
10
|
|
|
use CommerceLeague\ActiveCampaign\Helper\Client as ClientHelper; |
|
11
|
|
|
use CommerceLeague\ActiveCampaign\Logger\Logger; |
|
12
|
|
|
use CommerceLeague\ActiveCampaign\MessageQueue\SyncCustomerConsumer; |
|
13
|
|
|
use CommerceLeague\ActiveCampaignApi\Api\CustomerApiResourceInterface; |
|
14
|
|
|
use CommerceLeague\ActiveCampaignApi\Exception\HttpException; |
|
15
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
class SyncCustomerConsumerTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var MockObject|CustomerRepositoryInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $customerRepository; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var MockObject|Logger |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $logger; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var MockObject|ClientHelper |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $clientHelper; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var MockObject|CustomerInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $customer; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var MockObject|CustomerApiResourceInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $customerApi; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var SyncCustomerConsumer |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $syncCustomerConsumer; |
|
49
|
|
|
|
|
50
|
|
|
protected function setUp() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->customerRepository = $this->createMock(CustomerRepositoryInterface::class); |
|
53
|
|
|
$this->logger = $this->createMock(Logger::class); |
|
54
|
|
|
$this->clientHelper = $this->createMock(ClientHelper::class); |
|
55
|
|
|
$this->customer = $this->createMock(CustomerInterface::class); |
|
56
|
|
|
$this->customerApi = $this->createMock(CustomerApiResourceInterface::class); |
|
57
|
|
|
|
|
58
|
|
|
$this->syncCustomerConsumer = new SyncCustomerConsumer( |
|
59
|
|
|
$this->customerRepository, |
|
60
|
|
|
$this->logger, |
|
61
|
|
|
$this->clientHelper |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testConsumeApiResponseException() |
|
66
|
|
|
{ |
|
67
|
|
|
$magentoCustomerId = 123; |
|
68
|
|
|
|
|
69
|
|
|
$this->customerRepository->expects($this->once()) |
|
|
|
|
|
|
70
|
|
|
->method('getOrCreateByMagentoCustomerId') |
|
71
|
|
|
->with($magentoCustomerId) |
|
72
|
|
|
->willReturn($this->customer); |
|
73
|
|
|
|
|
74
|
|
|
$this->clientHelper->expects($this->once()) |
|
|
|
|
|
|
75
|
|
|
->method('getCustomerApi') |
|
76
|
|
|
->willReturn($this->customerApi); |
|
77
|
|
|
|
|
78
|
|
|
/** @var MockObject|HttpException $httpException */ |
|
79
|
|
|
$httpException = $this->createMock(HttpException::class); |
|
80
|
|
|
|
|
81
|
|
|
$this->customerApi->expects($this->once()) |
|
|
|
|
|
|
82
|
|
|
->method('create') |
|
83
|
|
|
->with(['ecomCustomer' => []]) |
|
84
|
|
|
->willThrowException($httpException); |
|
85
|
|
|
|
|
86
|
|
|
$this->logger->expects($this->once()) |
|
|
|
|
|
|
87
|
|
|
->method('error'); |
|
88
|
|
|
|
|
89
|
|
|
$this->customer->expects($this->never()) |
|
|
|
|
|
|
90
|
|
|
->method('setActiveCampaignId'); |
|
91
|
|
|
|
|
92
|
|
|
$this->syncCustomerConsumer->consume( |
|
93
|
|
|
json_encode(['magento_customer_id' => $magentoCustomerId, 'request' => []]) |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testConsumeUpdate() |
|
98
|
|
|
{ |
|
99
|
|
|
$magentoCustomerId = 123; |
|
100
|
|
|
$activeCampaignId = 123; |
|
101
|
|
|
$response = [ |
|
102
|
|
|
'ecomCustomer' => ['id' => $activeCampaignId] |
|
103
|
|
|
]; |
|
104
|
|
|
|
|
105
|
|
|
$this->customerRepository->expects($this->once()) |
|
106
|
|
|
->method('getOrCreateByMagentoCustomerId') |
|
107
|
|
|
->with($magentoCustomerId) |
|
108
|
|
|
->willReturn($this->customer); |
|
109
|
|
|
|
|
110
|
|
|
$this->clientHelper->expects($this->once()) |
|
111
|
|
|
->method('getCustomerApi') |
|
112
|
|
|
->willReturn($this->customerApi); |
|
113
|
|
|
|
|
114
|
|
|
$this->customer->expects($this->once()) |
|
115
|
|
|
->method('getActiveCampaignId') |
|
116
|
|
|
->willReturn($activeCampaignId); |
|
117
|
|
|
|
|
118
|
|
|
$this->customerApi->expects($this->once()) |
|
119
|
|
|
->method('update') |
|
120
|
|
|
->with($activeCampaignId, ['ecomCustomer' => []]) |
|
121
|
|
|
->willReturn($response); |
|
122
|
|
|
|
|
123
|
|
|
$this->customer->expects($this->once()) |
|
124
|
|
|
->method('setActiveCampaignId') |
|
125
|
|
|
->with($activeCampaignId) |
|
126
|
|
|
->willReturnSelf(); |
|
127
|
|
|
|
|
128
|
|
|
$this->customerRepository->expects($this->once()) |
|
129
|
|
|
->method('save') |
|
130
|
|
|
->with($this->customer); |
|
131
|
|
|
|
|
132
|
|
|
$this->syncCustomerConsumer->consume( |
|
133
|
|
|
json_encode(['magento_customer_id' => $magentoCustomerId, 'request' => []]) |
|
134
|
|
|
); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function testConsumeCreate() |
|
138
|
|
|
{ |
|
139
|
|
|
$magentoCustomerId = 123; |
|
140
|
|
|
$activeCampaignId = 123; |
|
141
|
|
|
$response = [ |
|
142
|
|
|
'ecomCustomer' => ['id' => $activeCampaignId] |
|
143
|
|
|
]; |
|
144
|
|
|
|
|
145
|
|
|
$this->customerRepository->expects($this->once()) |
|
146
|
|
|
->method('getOrCreateByMagentoCustomerId') |
|
147
|
|
|
->with($magentoCustomerId) |
|
148
|
|
|
->willReturn($this->customer); |
|
149
|
|
|
|
|
150
|
|
|
$this->clientHelper->expects($this->once()) |
|
151
|
|
|
->method('getCustomerApi') |
|
152
|
|
|
->willReturn($this->customerApi); |
|
153
|
|
|
|
|
154
|
|
|
$this->customer->expects($this->once()) |
|
155
|
|
|
->method('getActiveCampaignId') |
|
156
|
|
|
->willReturn(null); |
|
157
|
|
|
|
|
158
|
|
|
$this->customerApi->expects($this->once()) |
|
159
|
|
|
->method('create') |
|
160
|
|
|
->with(['ecomCustomer' => []]) |
|
161
|
|
|
->willReturn($response); |
|
162
|
|
|
|
|
163
|
|
|
$this->customer->expects($this->once()) |
|
164
|
|
|
->method('setActiveCampaignId') |
|
165
|
|
|
->with($activeCampaignId) |
|
166
|
|
|
->willReturnSelf(); |
|
167
|
|
|
|
|
168
|
|
|
$this->customerRepository->expects($this->once()) |
|
169
|
|
|
->method('save') |
|
170
|
|
|
->with($this->customer); |
|
171
|
|
|
|
|
172
|
|
|
$this->syncCustomerConsumer->consume( |
|
173
|
|
|
json_encode(['magento_customer_id' => $magentoCustomerId, 'request' => []]) |
|
174
|
|
|
); |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|
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.