1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Unit\Model; |
6
|
|
|
|
7
|
|
|
use CommerceLeague\ActiveCampaign\Model\Customer; |
8
|
|
|
use CommerceLeague\ActiveCampaign\Model\CustomerRepository; |
9
|
|
|
use Magento\Framework\Exception\CouldNotDeleteException; |
10
|
|
|
use Magento\Framework\Exception\CouldNotSaveException; |
11
|
|
|
use Magento\Framework\Exception\NoSuchEntityException; |
12
|
|
|
use Magento\Newsletter\Model\Subscriber; |
13
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Customer as CustomerResource; |
16
|
|
|
use CommerceLeague\ActiveCampaign\Model\CustomerFactory; |
|
|
|
|
17
|
|
|
|
18
|
|
|
class CustomerRepositoryTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var MockObject|CustomerResource |
22
|
|
|
*/ |
23
|
|
|
protected $customerResource; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var MockObject|Customer |
27
|
|
|
*/ |
28
|
|
|
protected $customer; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var MockObject|CustomerFactory |
32
|
|
|
*/ |
33
|
|
|
protected $customerFactory; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var CustomerRepository |
37
|
|
|
*/ |
38
|
|
|
protected $customerRepository; |
39
|
|
|
|
40
|
|
|
protected function setUp() |
41
|
|
|
{ |
42
|
|
|
$this->customerResource = $this->getMockBuilder(CustomerResource::class) |
43
|
|
|
->disableOriginalConstructor() |
44
|
|
|
->getMock(); |
45
|
|
|
|
46
|
|
|
$this->customerFactory = $this->getMockBuilder(CustomerFactory::class) |
47
|
|
|
->disableOriginalConstructor() |
48
|
|
|
->setMethods(['create']) |
49
|
|
|
->getMock(); |
50
|
|
|
|
51
|
|
|
$this->customer = $this->getMockBuilder(Customer::class) |
52
|
|
|
->disableOriginalConstructor() |
53
|
|
|
->getMock(); |
54
|
|
|
|
55
|
|
|
$this->customerFactory->expects($this->any()) |
56
|
|
|
->method('create') |
57
|
|
|
->willReturn($this->customer); |
58
|
|
|
|
59
|
|
|
$this->customerRepository = new CustomerRepository( |
60
|
|
|
$this->customerResource, |
61
|
|
|
$this->customerFactory |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testSaveThrowsException() |
66
|
|
|
{ |
67
|
|
|
$this->customerResource->expects($this->once()) |
|
|
|
|
68
|
|
|
->method('save') |
69
|
|
|
->with($this->customer) |
70
|
|
|
->willThrowException(new \Exception('an exception message')); |
71
|
|
|
|
72
|
|
|
$this->expectException(CouldNotSaveException::class); |
73
|
|
|
$this->expectExceptionMessage('an exception message'); |
74
|
|
|
|
75
|
|
|
$this->customerRepository->save($this->customer); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testSave() |
79
|
|
|
{ |
80
|
|
|
$this->customerResource->expects($this->once()) |
81
|
|
|
->method('save') |
82
|
|
|
->with($this->customer) |
83
|
|
|
->willReturnSelf(); |
84
|
|
|
|
85
|
|
|
$this->assertEquals($this->customer, $this->customerRepository->save($this->customer)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testGetById() |
89
|
|
|
{ |
90
|
|
|
$entityId = 123; |
91
|
|
|
$this->assertEquals($this->customer, $this->customerRepository->getById($entityId)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testGetByEmail() |
95
|
|
|
{ |
96
|
|
|
$email = '[email protected]'; |
97
|
|
|
$this->assertEquals($this->customer, $this->customerRepository->getByEmail($email)); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testDeleteThrowsException() |
101
|
|
|
{ |
102
|
|
|
$this->customerResource->expects($this->once()) |
103
|
|
|
->method('delete') |
104
|
|
|
->with($this->customer) |
105
|
|
|
->willThrowException(new \Exception('an exception message')); |
106
|
|
|
|
107
|
|
|
$this->expectException(CouldNotDeleteException::class); |
108
|
|
|
$this->expectExceptionMessage('an exception message'); |
109
|
|
|
|
110
|
|
|
$this->customerRepository->delete($this->customer); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testDelete() |
114
|
|
|
{ |
115
|
|
|
$this->customerResource->expects($this->once()) |
116
|
|
|
->method('delete') |
117
|
|
|
->with($this->customer) |
118
|
|
|
->willReturnSelf(); |
119
|
|
|
|
120
|
|
|
$this->assertTrue($this->customerRepository->delete($this->customer)); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testDeleteByIdThrowsException() |
124
|
|
|
{ |
125
|
|
|
$entityId = 123; |
126
|
|
|
|
127
|
|
|
$this->customer->expects($this->once()) |
|
|
|
|
128
|
|
|
->method('getId') |
|
|
|
|
129
|
|
|
->willReturn(null); |
|
|
|
|
130
|
|
|
|
131
|
|
|
$this->customerResource->expects($this->once()) |
132
|
|
|
->method('load') |
133
|
|
|
->with($this->customer, $entityId) |
134
|
|
|
->willReturn($this->customer); |
135
|
|
|
|
136
|
|
|
$this->customerResource->expects($this->never()) |
137
|
|
|
->method('delete'); |
138
|
|
|
|
139
|
|
|
$this->expectException(NoSuchEntityException::class); |
140
|
|
|
$this->expectExceptionMessage('The Customer with the "123" ID doesn\'t exist'); |
141
|
|
|
|
142
|
|
|
$this->customerRepository->deleteById($entityId); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function testDeleteById() |
146
|
|
|
{ |
147
|
|
|
$entityId = 123; |
148
|
|
|
|
149
|
|
|
$this->customer->expects($this->once()) |
150
|
|
|
->method('getId') |
151
|
|
|
->willReturn($entityId); |
152
|
|
|
|
153
|
|
|
$this->customerResource->expects($this->once()) |
154
|
|
|
->method('load') |
155
|
|
|
->with($this->customer, $entityId) |
156
|
|
|
->willReturn($this->customer); |
157
|
|
|
|
158
|
|
|
$this->customerResource->expects($this->once()) |
159
|
|
|
->method('delete') |
160
|
|
|
->with($this->customer) |
161
|
|
|
->willReturnSelf(); |
162
|
|
|
|
163
|
|
|
$this->assertTrue($this->customerRepository->deleteById($entityId)); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths