1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Unit\Gateway\Request; |
7
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Gateway\Request\CustomerBuilder; |
9
|
|
|
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper; |
10
|
|
|
use Magento\Customer\Api\Data\CustomerInterface as MagentoCustomerInterface; |
11
|
|
|
use Magento\Framework\Api\ExtensionAttributesInterface; |
12
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
class CustomerBuilderTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var MockObject|ConfigHelper |
19
|
|
|
*/ |
20
|
|
|
protected $configHelper; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var MockObject|MagentoCustomerInterface |
24
|
|
|
*/ |
25
|
|
|
protected $magentoCustomer; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var MockObject|ExtensionAttributesInterface |
29
|
|
|
*/ |
30
|
|
|
protected $extensionAttributes; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var CustomerBuilder |
34
|
|
|
*/ |
35
|
|
|
protected $customerBuilder; |
36
|
|
|
|
37
|
|
|
protected function setUp() |
38
|
|
|
{ |
39
|
|
|
$this->configHelper = $this->createMock(ConfigHelper::class); |
40
|
|
|
$this->magentoCustomer = $this->createMock(MagentoCustomerInterface::class); |
41
|
|
|
$this->extensionAttributes = $this->getMockBuilder(ExtensionAttributesInterface::class) |
42
|
|
|
->setMethods(['getIsSubscribed']) |
43
|
|
|
->getMockForAbstractClass(); |
44
|
|
|
|
45
|
|
|
$this->customerBuilder = new CustomerBuilder( |
46
|
|
|
$this->configHelper |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testBuildUnsubscribed() |
51
|
|
|
{ |
52
|
|
|
$connectionId = 123; |
53
|
|
|
$magentoCustomerId = 456; |
54
|
|
|
$email = '[email protected]'; |
55
|
|
|
|
56
|
|
|
$this->magentoCustomer->expects($this->once()) |
|
|
|
|
57
|
|
|
->method('getExtensionAttributes') |
58
|
|
|
->willReturn($this->extensionAttributes); |
59
|
|
|
|
60
|
|
|
$this->extensionAttributes->expects($this->once()) |
|
|
|
|
61
|
|
|
->method('getIsSubscribed') |
62
|
|
|
->willReturn(false); |
63
|
|
|
|
64
|
|
|
$this->configHelper->expects($this->once()) |
|
|
|
|
65
|
|
|
->method('getConnectionId') |
66
|
|
|
->willReturn($connectionId); |
67
|
|
|
|
68
|
|
|
$this->magentoCustomer->expects($this->once()) |
69
|
|
|
->method('getId') |
70
|
|
|
->willReturn($magentoCustomerId); |
71
|
|
|
|
72
|
|
|
$this->magentoCustomer->expects($this->once()) |
73
|
|
|
->method('getEmail') |
74
|
|
|
->willReturn($email); |
75
|
|
|
|
76
|
|
|
$expected = [ |
77
|
|
|
'connectionid' => $connectionId, |
78
|
|
|
'externalid' => $magentoCustomerId, |
79
|
|
|
'email' => $email, |
80
|
|
|
'acceptsMarketing' => 0 |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
$this->assertEquals( |
84
|
|
|
$expected, |
85
|
|
|
$this->customerBuilder->build($this->magentoCustomer) |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testBuildSubscribed() |
90
|
|
|
{ |
91
|
|
|
$connectionId = 123; |
92
|
|
|
$magentoCustomerId = 456; |
93
|
|
|
$email = '[email protected]'; |
94
|
|
|
|
95
|
|
|
$this->magentoCustomer->expects($this->once()) |
96
|
|
|
->method('getExtensionAttributes') |
97
|
|
|
->willReturn($this->extensionAttributes); |
98
|
|
|
|
99
|
|
|
$this->extensionAttributes->expects($this->once()) |
100
|
|
|
->method('getIsSubscribed') |
101
|
|
|
->willReturn(true); |
102
|
|
|
|
103
|
|
|
$this->configHelper->expects($this->once()) |
104
|
|
|
->method('getConnectionId') |
105
|
|
|
->willReturn($connectionId); |
106
|
|
|
|
107
|
|
|
$this->magentoCustomer->expects($this->once()) |
108
|
|
|
->method('getId') |
109
|
|
|
->willReturn($magentoCustomerId); |
110
|
|
|
|
111
|
|
|
$this->magentoCustomer->expects($this->once()) |
112
|
|
|
->method('getEmail') |
113
|
|
|
->willReturn($email); |
114
|
|
|
|
115
|
|
|
$expected = [ |
116
|
|
|
'connectionid' => $connectionId, |
117
|
|
|
'externalid' => $magentoCustomerId, |
118
|
|
|
'email' => $email, |
119
|
|
|
'acceptsMarketing' => 1 |
120
|
|
|
]; |
121
|
|
|
|
122
|
|
|
$this->assertEquals( |
123
|
|
|
$expected, |
124
|
|
|
$this->customerBuilder->build($this->magentoCustomer) |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
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.