1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Unit\Service\Contact; |
6
|
|
|
|
7
|
|
|
use CommerceLeague\ActiveCampaign\Api\ContactRepositoryInterface; |
8
|
|
|
use CommerceLeague\ActiveCampaign\Api\Data\ContactInterface; |
9
|
|
|
use CommerceLeague\ActiveCampaign\Gateway\Request\ContactRequestBuilder; |
10
|
|
|
use CommerceLeague\ActiveCampaign\Logger\Logger; |
11
|
|
|
use CommerceLeague\ActiveCampaign\MessageQueue\Contact\CreateUpdateMessage; |
12
|
|
|
use CommerceLeague\ActiveCampaign\MessageQueue\Contact\CreateUpdatePublisher; |
13
|
|
|
use CommerceLeague\ActiveCampaign\Service\Contact\CreateUpdateContactService; |
14
|
|
|
use Magento\Customer\Model\Customer; |
15
|
|
|
use Magento\Framework\Exception\CouldNotSaveException; |
16
|
|
|
use Magento\Framework\Phrase; |
17
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
|
20
|
|
|
class CreateUpdateContactServiceTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var MockObject|ContactRepositoryInterface |
24
|
|
|
*/ |
25
|
|
|
protected $contactRepository; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var MockObject|Logger |
29
|
|
|
*/ |
30
|
|
|
protected $logger; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var MockObject|ContactRequestBuilder |
34
|
|
|
*/ |
35
|
|
|
protected $contactRequestBuilder; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var MockObject|CreateUpdatePublisher |
39
|
|
|
*/ |
40
|
|
|
protected $createUpdatePublisher; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var MockObject|Customer |
44
|
|
|
*/ |
45
|
|
|
protected $customer; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var MockObject|ContactInterface |
49
|
|
|
*/ |
50
|
|
|
protected $contact; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var CreateUpdateContactService |
54
|
|
|
*/ |
55
|
|
|
protected $createUpdateContactService; |
56
|
|
|
|
57
|
|
|
protected function setUp() |
58
|
|
|
{ |
59
|
|
|
$this->contactRepository = $this->createMock(ContactRepositoryInterface::class); |
60
|
|
|
$this->logger = $this->createMock(Logger::class); |
61
|
|
|
$this->contactRequestBuilder = $this->createMock(ContactRequestBuilder::class); |
62
|
|
|
$this->createUpdatePublisher = $this->createMock(CreateUpdatePublisher::class); |
63
|
|
|
$this->customer = $this->createMock(Customer::class); |
64
|
|
|
$this->contact = $this->createMock(ContactInterface::class); |
65
|
|
|
|
66
|
|
|
$this->createUpdateContactService = new CreateUpdateContactService( |
67
|
|
|
$this->contactRepository, |
68
|
|
|
$this->logger, |
69
|
|
|
$this->contactRequestBuilder, |
70
|
|
|
$this->createUpdatePublisher |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testExecuteContactCouldNotSave() |
75
|
|
|
{ |
76
|
|
|
$exception = new CouldNotSaveException(new Phrase('an exception')); |
77
|
|
|
|
78
|
|
|
$this->contactRepository->expects($this->once()) |
|
|
|
|
79
|
|
|
->method('getOrCreateByCustomer') |
80
|
|
|
->willThrowException($exception); |
81
|
|
|
|
82
|
|
|
$this->logger->expects($this->once()) |
|
|
|
|
83
|
|
|
->method('critical') |
84
|
|
|
->with($exception); |
85
|
|
|
|
86
|
|
|
$this->contactRequestBuilder->expects($this->never()) |
|
|
|
|
87
|
|
|
->method('build'); |
88
|
|
|
|
89
|
|
|
$this->createUpdatePublisher->expects($this->never()) |
|
|
|
|
90
|
|
|
->method('publish'); |
91
|
|
|
|
92
|
|
|
$this->createUpdateContactService->execute($this->customer); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testExecute() |
96
|
|
|
{ |
97
|
|
|
$contactId = 123; |
98
|
|
|
|
99
|
|
|
$this->contactRepository->expects($this->once()) |
100
|
|
|
->method('getOrCreateByCustomer') |
101
|
|
|
->willReturn($this->contact); |
102
|
|
|
|
103
|
|
|
$this->contact->expects($this->once()) |
|
|
|
|
104
|
|
|
->method('getId') |
105
|
|
|
->willReturn($contactId); |
106
|
|
|
|
107
|
|
|
$this->contactRequestBuilder->expects($this->once()) |
108
|
|
|
->method('build') |
109
|
|
|
->with($this->customer) |
110
|
|
|
->willReturn(['request']); |
111
|
|
|
|
112
|
|
|
$this->createUpdatePublisher->expects($this->once()) |
113
|
|
|
->method('publish') |
114
|
|
|
->with($this->isInstanceOf(CreateUpdateMessage::class)); |
115
|
|
|
|
116
|
|
|
$this->createUpdateContactService->execute($this->customer); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
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.