|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Observer\Customer; |
|
7
|
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper; |
|
9
|
|
|
use CommerceLeague\ActiveCampaign\Observer\Customer\ExportContactObserver; |
|
10
|
|
|
use CommerceLeague\ActiveCampaign\Service\ExportContactService; |
|
11
|
|
|
use Magento\Customer\Model\Customer; |
|
12
|
|
|
use Magento\Framework\Event; |
|
13
|
|
|
use Magento\Framework\Event\Observer; |
|
14
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
class ExportContactObserverTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var MockObject|ConfigHelper |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $configHelper; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var MockObject|ExportContactService |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $exportContactService; |
|
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|Customer |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $customer; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var ExportContactService |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $exportContactObserver; |
|
48
|
|
|
|
|
49
|
|
|
protected function setUp() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->configHelper = $this->createMock(ConfigHelper::class); |
|
52
|
|
|
$this->exportContactService = $this->createMock(ExportContactService::class); |
|
53
|
|
|
$this->observer = $this->createMock(Observer::class); |
|
54
|
|
|
$this->event = $this->createMock(Event::class); |
|
55
|
|
|
$this->customer = $this->createMock(Customer::class); |
|
56
|
|
|
|
|
57
|
|
|
$this->exportContactObserver = new ExportContactObserver( |
|
|
|
|
|
|
58
|
|
|
$this->configHelper, |
|
59
|
|
|
$this->exportContactService |
|
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->exportContactObserver->execute($this->observer); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testExecute() |
|
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('customer') |
|
|
|
|
|
|
88
|
|
|
->willReturn($this->customer); |
|
89
|
|
|
|
|
90
|
|
|
$this->exportContactService->expects($this->once()) |
|
|
|
|
|
|
91
|
|
|
->method('exportWithMagentoCustomer') |
|
92
|
|
|
->with($this->customer); |
|
93
|
|
|
|
|
94
|
|
|
$this->exportContactObserver->execute($this->observer); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..