1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Unit\Observer\Customer; |
6
|
|
|
|
7
|
|
|
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper; |
8
|
|
|
use CommerceLeague\ActiveCampaign\Observer\CustomerSaveAfterObserver; |
9
|
|
|
use CommerceLeague\ActiveCampaign\Service\Contact\CreateUpdateContactService; |
10
|
|
|
use Magento\Customer\Model\Customer; |
11
|
|
|
use Magento\Framework\Event; |
12
|
|
|
use Magento\Framework\Event\Observer; |
13
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class CustomerSaveAfterObserverTest |
18
|
|
|
*/ |
19
|
|
|
class CustomerSaveAfterObserverTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var MockObject|ConfigHelper |
23
|
|
|
*/ |
24
|
|
|
protected $configHelper; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var MockObject|CreateUpdateContactService |
28
|
|
|
*/ |
29
|
|
|
protected $createUpdateContactService; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var MockObject|Observer |
33
|
|
|
*/ |
34
|
|
|
protected $observer; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var MockObject|Event |
38
|
|
|
*/ |
39
|
|
|
protected $event; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var MockObject|Customer |
43
|
|
|
*/ |
44
|
|
|
protected $customer; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var CustomerSaveAfterObserver |
48
|
|
|
*/ |
49
|
|
|
protected $createUpdateContactObserver; |
50
|
|
|
|
51
|
|
|
protected function setUp() |
52
|
|
|
{ |
53
|
|
|
$this->configHelper = $this->createMock(ConfigHelper::class); |
54
|
|
|
$this->createUpdateContactService = $this->createMock(CreateUpdateContactService::class); |
55
|
|
|
$this->observer = $this->createMock(Observer::class); |
56
|
|
|
$this->event = $this->createMock(Event::class); |
57
|
|
|
$this->customer = $this->createMock(Customer::class); |
58
|
|
|
|
59
|
|
|
$this->createUpdateContactObserver = new CustomerSaveAfterObserver( |
60
|
|
|
$this->configHelper, |
61
|
|
|
$this->createUpdateContactService |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testExecuteApiNotEnabled() |
66
|
|
|
{ |
67
|
|
|
$this->configHelper->expects($this->once()) |
|
|
|
|
68
|
|
|
->method('isApiEnabled') |
69
|
|
|
->willReturn(false); |
70
|
|
|
|
71
|
|
|
$this->observer->expects($this->never()) |
72
|
|
|
->method('getEvent'); |
|
|
|
|
73
|
|
|
|
74
|
|
|
$this->createUpdateContactObserver->execute($this->observer); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testExecuteApiEnabled() |
78
|
|
|
{ |
79
|
|
|
$this->configHelper->expects($this->once()) |
80
|
|
|
->method('isApiEnabled') |
81
|
|
|
->willReturn(true); |
82
|
|
|
|
83
|
|
|
$this->observer->expects($this->once()) |
84
|
|
|
->method('getEvent') |
85
|
|
|
->willReturn($this->event); |
|
|
|
|
86
|
|
|
|
87
|
|
|
$this->event->expects($this->once()) |
88
|
|
|
->method('getData') |
89
|
|
|
->with('customer') |
|
|
|
|
90
|
|
|
->willReturn($this->customer); |
91
|
|
|
|
92
|
|
|
$this->createUpdateContactService->expects($this->once()) |
|
|
|
|
93
|
|
|
->method('execute') |
94
|
|
|
->with($this->customer); |
95
|
|
|
|
96
|
|
|
$this->createUpdateContactObserver->execute($this->observer); |
97
|
|
|
} |
98
|
|
|
} |
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.