1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Unit\MessageQueue\Contact; |
7
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Api\Data\ContactInterface; |
9
|
|
|
use CommerceLeague\ActiveCampaign\MessageQueue\Contact\CreateUpdateMessage; |
10
|
|
|
use CommerceLeague\ActiveCampaign\MessageQueue\Contact\CreateUpdateMessageBuilder; |
11
|
|
|
use CommerceLeague\ActiveCampaign\MessageQueue\Contact\CreateUpdateMessageFactory; |
|
|
|
|
12
|
|
|
use Magento\Customer\Model\Customer; |
13
|
|
|
use Magento\Newsletter\Model\Subscriber; |
14
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
class CreateUpdateMessageBuilderTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var MockObject|CreateUpdateMessageFactory |
21
|
|
|
*/ |
22
|
|
|
protected $createUpdateMessageFactory; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var MockObject|CreateUpdateMessage |
26
|
|
|
*/ |
27
|
|
|
protected $createUpdateMessage; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var MockObject|ContactInterface |
31
|
|
|
*/ |
32
|
|
|
protected $contact; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var MockObject|Customer |
36
|
|
|
*/ |
37
|
|
|
protected $customer; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var MockObject|Subscriber |
41
|
|
|
*/ |
42
|
|
|
protected $subscriber; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var CreateUpdateMessageBuilder |
46
|
|
|
*/ |
47
|
|
|
protected $createUpdateMessageBuilder; |
48
|
|
|
|
49
|
|
|
protected function setUp() |
50
|
|
|
{ |
51
|
|
|
$this->createUpdateMessageFactory = $this->getMockBuilder(CreateUpdateMessageFactory::class) |
52
|
|
|
->setMethods(['create']) |
53
|
|
|
->disableOriginalConstructor() |
54
|
|
|
->getMock(); |
55
|
|
|
|
56
|
|
|
$this->createUpdateMessage = $this->createMock(CreateUpdateMessage::class); |
57
|
|
|
$this->contact = $this->createMock(ContactInterface::class); |
58
|
|
|
$this->customer = $this->createMock(Customer::class); |
59
|
|
|
$this->subscriber = $this->createMock(Subscriber::class); |
60
|
|
|
|
61
|
|
|
$this->createUpdateMessageBuilder = new CreateUpdateMessageBuilder( |
62
|
|
|
$this->createUpdateMessageFactory |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testBuildWithCustomer() |
67
|
|
|
{ |
68
|
|
|
$email = '[email protected]'; |
69
|
|
|
$firstName = 'firstName'; |
70
|
|
|
$lastName = 'lastName'; |
71
|
|
|
|
72
|
|
|
$this->customer->expects($this->at(0)) |
73
|
|
|
->method('getData') |
|
|
|
|
74
|
|
|
->with('email') |
|
|
|
|
75
|
|
|
->willReturn($email); |
|
|
|
|
76
|
|
|
|
77
|
|
|
$this->customer->expects($this->at(1)) |
78
|
|
|
->method('getData') |
79
|
|
|
->with('firstname') |
80
|
|
|
->willReturn($firstName); |
81
|
|
|
|
82
|
|
|
$this->customer->expects($this->at(2)) |
83
|
|
|
->method('getData') |
84
|
|
|
->with('lastname') |
85
|
|
|
->willReturn($lastName); |
86
|
|
|
|
87
|
|
|
$this->createUpdateMessageFactory->expects($this->once()) |
88
|
|
|
->method('create') |
89
|
|
|
->willReturn($this->createUpdateMessage); |
90
|
|
|
|
91
|
|
|
$this->contact->expects($this->once()) |
|
|
|
|
92
|
|
|
->method('getId') |
93
|
|
|
->willReturn('123'); |
94
|
|
|
|
95
|
|
|
$this->createUpdateMessage->expects($this->once()) |
|
|
|
|
96
|
|
|
->method('setContactId') |
97
|
|
|
->with(123) |
98
|
|
|
->willReturnSelf(); |
99
|
|
|
|
100
|
|
|
$request = [ |
101
|
|
|
'email' => $email, |
102
|
|
|
'firstName' => $firstName, |
103
|
|
|
'lastName' => $lastName |
104
|
|
|
]; |
105
|
|
|
|
106
|
|
|
$this->createUpdateMessage->expects($this->once()) |
107
|
|
|
->method('setSerializedRequest') |
108
|
|
|
->with(json_encode($request)); |
109
|
|
|
|
110
|
|
|
$this->assertSame( |
111
|
|
|
$this->createUpdateMessage, |
112
|
|
|
$this->createUpdateMessageBuilder->buildWithCustomer($this->contact, $this->customer) |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testBuildWithSubscriber() |
117
|
|
|
{ |
118
|
|
|
$email = '[email protected]'; |
119
|
|
|
|
120
|
|
|
$this->createUpdateMessageFactory->expects($this->once()) |
121
|
|
|
->method('create') |
122
|
|
|
->willReturn($this->createUpdateMessage); |
123
|
|
|
|
124
|
|
|
$this->subscriber->expects($this->at(0)) |
125
|
|
|
->method('getEmail') |
126
|
|
|
->willReturn($email); |
127
|
|
|
|
128
|
|
|
$this->contact->expects($this->once()) |
129
|
|
|
->method('getId') |
130
|
|
|
->willReturn('123'); |
131
|
|
|
|
132
|
|
|
$this->createUpdateMessage->expects($this->once()) |
133
|
|
|
->method('setContactId') |
134
|
|
|
->with(123) |
135
|
|
|
->willReturnSelf(); |
136
|
|
|
|
137
|
|
|
$request = [ |
138
|
|
|
'email' => $email |
139
|
|
|
]; |
140
|
|
|
|
141
|
|
|
$this->createUpdateMessage->expects($this->once()) |
142
|
|
|
->method('setSerializedRequest') |
143
|
|
|
->with(json_encode($request)); |
144
|
|
|
|
145
|
|
|
$this->assertSame( |
146
|
|
|
$this->createUpdateMessage, |
147
|
|
|
$this->createUpdateMessageBuilder->buildWithSubscriber($this->contact, $this->subscriber) |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
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