1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Test\Unit\Model; |
7
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Api\Data\AbandonedInterface; |
9
|
|
|
use CommerceLeague\ActiveCampaign\Model\AbandonedRepository; |
10
|
|
|
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Abandoned as AbandonedResource; |
11
|
|
|
use CommerceLeague\ActiveCampaign\Model\AbandonedFactory as AbandonedFactory; |
|
|
|
|
12
|
|
|
use CommerceLeague\ActiveCampaign\Model\Abandoned; |
13
|
|
|
use Magento\Framework\Exception\CouldNotDeleteException; |
14
|
|
|
use Magento\Framework\Exception\CouldNotSaveException; |
15
|
|
|
use Magento\Framework\Exception\NoSuchEntityException; |
16
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
class AbandonedRepositoryTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var MockObject|AbandonedResource |
23
|
|
|
*/ |
24
|
|
|
protected $abandonedResource; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var MockObject|AbandonedFactory |
28
|
|
|
*/ |
29
|
|
|
protected $abandonedFactory; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var MockObject|Abandoned |
33
|
|
|
*/ |
34
|
|
|
protected $abandoned; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var AbandonedRepository |
38
|
|
|
*/ |
39
|
|
|
protected $abandonedRepository; |
40
|
|
|
|
41
|
|
|
protected function setUp() |
42
|
|
|
{ |
43
|
|
|
$this->abandonedResource = $this->getMockBuilder(AbandonedResource::class) |
44
|
|
|
->disableOriginalConstructor() |
45
|
|
|
->getMock(); |
46
|
|
|
|
47
|
|
|
$this->abandonedFactory = $this->getMockBuilder(AbandonedFactory::class) |
48
|
|
|
->disableOriginalConstructor() |
49
|
|
|
->setMethods(['create']) |
50
|
|
|
->getMock(); |
51
|
|
|
|
52
|
|
|
$this->abandoned = $this->getMockBuilder(Abandoned::class) |
53
|
|
|
->disableOriginalConstructor() |
54
|
|
|
->getMock(); |
55
|
|
|
|
56
|
|
|
$this->abandonedFactory->expects($this->any()) |
57
|
|
|
->method('create') |
58
|
|
|
->willReturn($this->abandoned); |
59
|
|
|
|
60
|
|
|
$this->abandonedRepository = new AbandonedRepository( |
61
|
|
|
$this->abandonedResource, |
62
|
|
|
$this->abandonedFactory |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testSaveThrowsException() |
67
|
|
|
{ |
68
|
|
|
$this->abandonedResource->expects($this->once()) |
|
|
|
|
69
|
|
|
->method('save') |
70
|
|
|
->with($this->abandoned) |
71
|
|
|
->willThrowException(new \Exception('an exception message')); |
72
|
|
|
|
73
|
|
|
$this->expectException(CouldNotSaveException::class); |
74
|
|
|
$this->expectExceptionMessage('an exception message'); |
75
|
|
|
|
76
|
|
|
$this->abandonedRepository->save($this->abandoned); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testSave() |
80
|
|
|
{ |
81
|
|
|
$this->abandonedResource->expects($this->once()) |
82
|
|
|
->method('save') |
83
|
|
|
->with($this->abandoned) |
84
|
|
|
->willReturnSelf(); |
85
|
|
|
|
86
|
|
|
$this->assertSame($this->abandoned, $this->abandonedRepository->save($this->abandoned)); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testGetById() |
90
|
|
|
{ |
91
|
|
|
$entityId = 123; |
92
|
|
|
|
93
|
|
|
$this->abandonedResource->expects($this->once()) |
94
|
|
|
->method('load') |
95
|
|
|
->with($this->abandoned, $entityId) |
96
|
|
|
->willReturn($this->abandoned); |
97
|
|
|
|
98
|
|
|
$this->assertSame($this->abandoned, $this->abandonedRepository->getById($entityId)); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testGetByQuoteId() |
102
|
|
|
{ |
103
|
|
|
$quoteId = 123; |
104
|
|
|
|
105
|
|
|
$this->abandonedResource->expects($this->once()) |
106
|
|
|
->method('load') |
107
|
|
|
->with($this->abandoned, $quoteId, AbandonedInterface::QUOTE_ID) |
108
|
|
|
->willReturn($this->abandoned); |
109
|
|
|
|
110
|
|
|
$this->assertSame($this->abandoned, $this->abandonedRepository->getByQuoteId($quoteId)); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testGetOrCreateByQuoteIdWithKnownQuote() |
114
|
|
|
{ |
115
|
|
|
$quoteId = 123; |
116
|
|
|
|
117
|
|
|
$this->abandonedResource->expects($this->once()) |
118
|
|
|
->method('load') |
119
|
|
|
->with($this->abandoned, $quoteId, AbandonedInterface::QUOTE_ID) |
120
|
|
|
->willReturn($this->abandoned); |
121
|
|
|
|
122
|
|
|
$this->abandoned->expects($this->once()) |
|
|
|
|
123
|
|
|
->method('getId') |
|
|
|
|
124
|
|
|
->willReturn(123); |
|
|
|
|
125
|
|
|
|
126
|
|
|
$this->abandoned->expects($this->never()) |
127
|
|
|
->method('setQuoteId'); |
128
|
|
|
|
129
|
|
|
$this->assertSame($this->abandoned, $this->abandonedRepository->getOrCreateByQuoteId($quoteId)); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testGetOrCreateByQuoteId() |
133
|
|
|
{ |
134
|
|
|
$quoteId = 123; |
135
|
|
|
|
136
|
|
|
$this->abandonedResource->expects($this->once()) |
137
|
|
|
->method('load') |
138
|
|
|
->with($this->abandoned, $quoteId, AbandonedInterface::QUOTE_ID) |
139
|
|
|
->willReturn($this->abandoned); |
140
|
|
|
|
141
|
|
|
$this->abandoned->expects($this->once()) |
142
|
|
|
->method('getId') |
143
|
|
|
->willReturn(null); |
144
|
|
|
|
145
|
|
|
$this->abandoned->expects($this->once()) |
146
|
|
|
->method('setQuoteId') |
147
|
|
|
->with($quoteId) |
|
|
|
|
148
|
|
|
->willReturnSelf(); |
|
|
|
|
149
|
|
|
|
150
|
|
|
$this->abandonedResource->expects($this->once()) |
151
|
|
|
->method('save') |
152
|
|
|
->with($this->abandoned) |
153
|
|
|
->willReturn($this->abandoned); |
154
|
|
|
|
155
|
|
|
$this->assertSame($this->abandoned, $this->abandonedRepository->getOrCreateByQuoteId($quoteId)); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function testDeleteThrowsException() |
159
|
|
|
{ |
160
|
|
|
$this->abandonedResource->expects($this->once()) |
161
|
|
|
->method('delete') |
162
|
|
|
->with($this->abandoned) |
163
|
|
|
->willThrowException(new \Exception('an exception message')); |
164
|
|
|
|
165
|
|
|
$this->expectException(CouldNotDeleteException::class); |
166
|
|
|
$this->expectExceptionMessage('an exception message'); |
167
|
|
|
|
168
|
|
|
$this->abandonedRepository->delete($this->abandoned); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function testDelete() |
172
|
|
|
{ |
173
|
|
|
$this->abandonedResource->expects($this->once()) |
174
|
|
|
->method('delete') |
175
|
|
|
->with($this->abandoned) |
176
|
|
|
->willReturnSelf(); |
177
|
|
|
|
178
|
|
|
$this->assertTrue($this->abandonedRepository->delete($this->abandoned)); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
public function testDeleteByIdThrowsException() |
183
|
|
|
{ |
184
|
|
|
$entityId = 123; |
185
|
|
|
|
186
|
|
|
$this->abandoned->expects($this->once()) |
187
|
|
|
->method('getId') |
188
|
|
|
->willReturn(null); |
189
|
|
|
|
190
|
|
|
$this->abandonedResource->expects($this->once()) |
191
|
|
|
->method('load') |
192
|
|
|
->with($this->abandoned, $entityId) |
193
|
|
|
->willReturn($this->abandoned); |
194
|
|
|
|
195
|
|
|
$this->abandonedResource->expects($this->never()) |
196
|
|
|
->method('delete'); |
197
|
|
|
|
198
|
|
|
$this->expectException(NoSuchEntityException::class); |
199
|
|
|
$this->expectExceptionMessage('The Abandoned Cart with the "123" ID doesn\'t exist'); |
200
|
|
|
|
201
|
|
|
$this->abandonedRepository->deleteById($entityId); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function testDeleteById() |
205
|
|
|
{ |
206
|
|
|
$entityId = 123; |
207
|
|
|
|
208
|
|
|
$this->abandoned->expects($this->once()) |
209
|
|
|
->method('getId') |
210
|
|
|
->willReturn($entityId); |
211
|
|
|
|
212
|
|
|
$this->abandonedResource->expects($this->once()) |
213
|
|
|
->method('load') |
214
|
|
|
->with($this->abandoned, $entityId) |
215
|
|
|
->willReturn($this->abandoned); |
216
|
|
|
|
217
|
|
|
$this->abandonedResource->expects($this->once()) |
218
|
|
|
->method('delete') |
219
|
|
|
->with($this->abandoned) |
220
|
|
|
->willReturnSelf(); |
221
|
|
|
|
222
|
|
|
$this->assertTrue($this->abandonedRepository->deleteById($entityId)); |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|
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