1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Unit\Service; |
7
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\MessageQueue\Topics; |
9
|
|
|
use CommerceLeague\ActiveCampaign\Service\ExportContactService; |
10
|
|
|
use Magento\Customer\Model\Customer; |
11
|
|
|
use Magento\Framework\MessageQueue\PublisherInterface; |
12
|
|
|
use Magento\Newsletter\Model\Subscriber; |
13
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use CommerceLeague\ActiveCampaign\Gateway\Request\ContactBuilder as ContactRequestBuilder; |
16
|
|
|
|
17
|
|
|
class ExportContactServiceTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var MockObject|ContactRequestBuilder |
21
|
|
|
*/ |
22
|
|
|
protected $contactRequestBuilder; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var MockObject|PublisherInterface |
26
|
|
|
*/ |
27
|
|
|
protected $publisher; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ExportContactService |
31
|
|
|
*/ |
32
|
|
|
protected $exportContactService; |
33
|
|
|
|
34
|
|
|
protected function setUp() |
35
|
|
|
{ |
36
|
|
|
$this->contactRequestBuilder = $this->createMock(ContactRequestBuilder::class); |
37
|
|
|
$this->publisher = $this->createMock(PublisherInterface::class); |
38
|
|
|
$this->exportContactService = new ExportContactService( |
39
|
|
|
$this->contactRequestBuilder, |
40
|
|
|
$this->publisher |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testExportWithMagentoCustomer() |
45
|
|
|
{ |
46
|
|
|
/** @var MockObject|Customer $magentoCustomer */ |
47
|
|
|
$magentoCustomer = $this->createMock(Customer::class); |
48
|
|
|
|
49
|
|
|
$email = '[email protected]'; |
50
|
|
|
$request = ['request']; |
51
|
|
|
|
52
|
|
|
$magentoCustomer->expects($this->once()) |
53
|
|
|
->method('getData') |
54
|
|
|
->with('email') |
55
|
|
|
->willReturn($email); |
56
|
|
|
|
57
|
|
|
$this->contactRequestBuilder->expects($this->once()) |
|
|
|
|
58
|
|
|
->method('buildWithMagentoCustomer') |
59
|
|
|
->with($magentoCustomer) |
60
|
|
|
->willReturn($request); |
61
|
|
|
|
62
|
|
|
$this->publisher->expects($this->once()) |
|
|
|
|
63
|
|
|
->method('publish') |
64
|
|
|
->with( |
65
|
|
|
Topics::CONTACT_EXPORT, |
66
|
|
|
json_encode(['email' => $email, 'request' => $request])); |
67
|
|
|
|
68
|
|
|
$this->exportContactService->exportWithMagentoCustomer($magentoCustomer); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testExportWithSubscriber() |
72
|
|
|
{ |
73
|
|
|
/** @var MockObject|Subscriber $subscriber */ |
74
|
|
|
$subscriber = $this->createMock(Subscriber::class); |
75
|
|
|
|
76
|
|
|
$email = '[email protected]'; |
77
|
|
|
$request = ['request']; |
78
|
|
|
|
79
|
|
|
$subscriber->expects($this->once()) |
80
|
|
|
->method('getEmail') |
81
|
|
|
->willReturn($email); |
82
|
|
|
|
83
|
|
|
$this->contactRequestBuilder->expects($this->once()) |
84
|
|
|
->method('buildWithSubscriber') |
85
|
|
|
->with($subscriber) |
86
|
|
|
->willReturn($request); |
87
|
|
|
|
88
|
|
|
$this->publisher->expects($this->once()) |
89
|
|
|
->method('publish') |
90
|
|
|
->with( |
91
|
|
|
Topics::CONTACT_EXPORT, |
92
|
|
|
json_encode(['email' => $email, 'request' => $request]) |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$this->exportContactService->exportWithSubscriber($subscriber); |
96
|
|
|
} |
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.