1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Observer\Newsletter; |
7
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper; |
9
|
|
|
use CommerceLeague\ActiveCampaign\Observer\Newsletter\SyncContactObserver; |
10
|
|
|
use CommerceLeague\ActiveCampaign\Service\Contact\SyncContactService; |
11
|
|
|
use Magento\Framework\Event; |
12
|
|
|
use Magento\Framework\Event\Observer; |
13
|
|
|
use Magento\Newsletter\Model\Subscriber; |
14
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
class SyncContactObserverTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var MockObject|ConfigHelper |
21
|
|
|
*/ |
22
|
|
|
protected $configHelper; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var MockObject|SyncContactService |
26
|
|
|
*/ |
27
|
|
|
protected $syncContactService; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var MockObject|Observer |
31
|
|
|
*/ |
32
|
|
|
protected $observer; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var MockObject|Event |
36
|
|
|
*/ |
37
|
|
|
protected $event; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var MockObject|Subscriber |
41
|
|
|
*/ |
42
|
|
|
protected $subscriber; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var SyncContactObserver |
46
|
|
|
*/ |
47
|
|
|
protected $syncContactObserver; |
48
|
|
|
|
49
|
|
|
protected function setUp() |
50
|
|
|
{ |
51
|
|
|
$this->configHelper = $this->createMock(ConfigHelper::class); |
52
|
|
|
$this->syncContactService = $this->createMock(SyncContactService::class); |
53
|
|
|
$this->observer = $this->createMock(Observer::class); |
54
|
|
|
$this->event = $this->createMock(Event::class); |
55
|
|
|
$this->subscriber = $this->createMock(Subscriber::class); |
56
|
|
|
|
57
|
|
|
$this->syncContactObserver = new SyncContactObserver( |
58
|
|
|
$this->configHelper, |
59
|
|
|
$this->syncContactService |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testExecuteApiDisabled() |
64
|
|
|
{ |
65
|
|
|
$this->configHelper->expects($this->once()) |
|
|
|
|
66
|
|
|
->method('isApiEnabled') |
67
|
|
|
->willReturn(false); |
68
|
|
|
|
69
|
|
|
$this->observer->expects($this->never()) |
70
|
|
|
->method('getEvent'); |
|
|
|
|
71
|
|
|
|
72
|
|
|
$this->syncContactObserver->execute($this->observer); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testExecuteWithSubscriberAsCustomer() |
76
|
|
|
{ |
77
|
|
|
$this->configHelper->expects($this->once()) |
78
|
|
|
->method('isApiEnabled') |
79
|
|
|
->willReturn(true); |
80
|
|
|
|
81
|
|
|
$this->observer->expects($this->once()) |
82
|
|
|
->method('getEvent') |
83
|
|
|
->willReturn($this->event); |
|
|
|
|
84
|
|
|
|
85
|
|
|
$this->event->expects($this->once()) |
86
|
|
|
->method('getData') |
87
|
|
|
->with('subscriber') |
|
|
|
|
88
|
|
|
->willReturn($this->subscriber); |
89
|
|
|
|
90
|
|
|
$this->subscriber->expects($this->once()) |
91
|
|
|
->method('getData') |
92
|
|
|
->with('customer_id') |
93
|
|
|
->willReturn(123); |
94
|
|
|
|
95
|
|
|
$this->syncContactService->expects($this->never()) |
|
|
|
|
96
|
|
|
->method('syncWithSubscriber'); |
97
|
|
|
|
98
|
|
|
$this->syncContactObserver->execute($this->observer); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testExecute() |
102
|
|
|
{ |
103
|
|
|
$this->configHelper->expects($this->once()) |
104
|
|
|
->method('isApiEnabled') |
105
|
|
|
->willReturn(true); |
106
|
|
|
|
107
|
|
|
$this->observer->expects($this->once()) |
108
|
|
|
->method('getEvent') |
109
|
|
|
->willReturn($this->event); |
110
|
|
|
|
111
|
|
|
$this->event->expects($this->once()) |
112
|
|
|
->method('getData') |
113
|
|
|
->with('subscriber') |
114
|
|
|
->willReturn($this->subscriber); |
115
|
|
|
|
116
|
|
|
$this->subscriber->expects($this->once()) |
117
|
|
|
->method('getData') |
118
|
|
|
->with('customer_id') |
119
|
|
|
->willReturn(null); |
120
|
|
|
|
121
|
|
|
$this->syncContactService->expects($this->once()) |
122
|
|
|
->method('syncWithSubscriber') |
123
|
|
|
->with($this->subscriber); |
124
|
|
|
|
125
|
|
|
$this->syncContactObserver->execute($this->observer); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
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.