1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||
6 | */ |
||
7 | |||
8 | namespace SprykerTest\Zed\Business\MerchantRelationship; |
||
9 | |||
10 | use Codeception\Test\Unit; |
||
11 | use Exception; |
||
12 | use Generated\Shared\Transfer\CompanyBusinessUnitCollectionTransfer; |
||
13 | use Generated\Shared\Transfer\CompanyBusinessUnitTransfer; |
||
14 | use Generated\Shared\Transfer\MerchantRelationshipConditionsTransfer; |
||
15 | use Generated\Shared\Transfer\MerchantRelationshipCriteriaTransfer; |
||
16 | use Generated\Shared\Transfer\MerchantRelationshipFilterTransfer; |
||
17 | use Generated\Shared\Transfer\MerchantRelationshipRequestTransfer; |
||
18 | use Generated\Shared\Transfer\MerchantRelationshipTransfer; |
||
19 | use Generated\Shared\Transfer\PaginationTransfer; |
||
20 | use Generated\Shared\Transfer\SortCollectionTransfer; |
||
21 | use Generated\Shared\Transfer\SortTransfer; |
||
22 | use Spryker\Zed\MerchantRelationship\Business\MerchantRelationshipBusinessFactory; |
||
23 | use Spryker\Zed\MerchantRelationship\MerchantRelationshipDependencyProvider; |
||
24 | use Spryker\Zed\MerchantRelationship\Persistence\MerchantRelationshipPersistenceFactory; |
||
25 | use Spryker\Zed\MerchantRelationship\Persistence\MerchantRelationshipRepository; |
||
26 | use Spryker\Zed\MerchantRelationshipExtension\Dependency\Plugin\MerchantRelationshipPostDeletePluginInterface; |
||
27 | |||
28 | /** |
||
29 | * Auto-generated group annotations |
||
30 | * |
||
31 | * @group SprykerTest |
||
32 | * @group Zed |
||
33 | * @group Business |
||
34 | * @group MerchantRelationship |
||
35 | * @group Facade |
||
36 | * @group MerchantRelationshipFacadeTest |
||
37 | * Add your own group annotations below this line |
||
38 | */ |
||
39 | class MerchantRelationshipFacadeTest extends Unit |
||
40 | { |
||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected const MR_KEY_1_TEST = 'mr-test-1'; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | protected const MR_KEY_2_TEST = 'mr-test-2'; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | protected const BU_OWNER_KEY_OWNER = 'unit-owner'; |
||
55 | |||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | protected const BU_KEY_UNIT_1 = 'unit-1'; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | protected const BU_KEY_UNIT_2 = 'unit-2'; |
||
65 | |||
66 | /** |
||
67 | * @uses \Spryker\Zed\MerchantRelationshipProductListGui\Communication\Mapper\ProductListUsedByTableMapper::ENTITY_TITLE |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | protected const MR_ENTITY_TITLE = 'Merchant Relationship'; |
||
72 | |||
73 | /** |
||
74 | * @var \SprykerTest\Zed\MerchantRelationship\MerchantRelationshipBusinessTester |
||
75 | */ |
||
76 | protected $tester; |
||
77 | |||
78 | /** |
||
79 | * @return void |
||
80 | */ |
||
81 | public function testCreateMerchantRelationship(): void |
||
82 | { |
||
83 | $merchantRelationship = $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST); |
||
84 | |||
85 | // Assert |
||
86 | $this->assertNotNull($merchantRelationship->getIdMerchantRelationship()); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @return void |
||
91 | */ |
||
92 | public function testCreateMerchantRelationshipForwardCompatibility(): void |
||
93 | { |
||
94 | // Arrange |
||
95 | $merchantRelationshipRequestTransfer = $this->tester->createMerchantRelationshipRequest(static::MR_KEY_1_TEST); |
||
96 | $merchantRelationshipTransfer = $merchantRelationshipRequestTransfer->getMerchantRelationship(); |
||
97 | |||
98 | // Act |
||
99 | $merchantRelationshipResponseTransfer = $this->tester->getFacade()->createMerchantRelationship( |
||
100 | $merchantRelationshipTransfer, |
||
101 | $merchantRelationshipRequestTransfer, |
||
102 | ); |
||
103 | |||
104 | // Assert |
||
105 | $this->assertNotNull($merchantRelationshipResponseTransfer->getMerchantRelationship()); |
||
106 | $this->assertNotNull($merchantRelationshipResponseTransfer->getMerchantRelationship()->getIdMerchantRelationship()); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @return void |
||
111 | */ |
||
112 | public function testCreateMerchantRelationshipWithNotUniqueKeyHasErrorsInResponse(): void |
||
113 | { |
||
114 | // Arrange |
||
115 | $merchantRelationshipRequestTransfer = $this->tester->createMerchantRelationshipRequest(static::MR_KEY_1_TEST); |
||
116 | $merchantRelationshipTransfer = $merchantRelationshipRequestTransfer->getMerchantRelationship(); |
||
117 | $merchantRelationshipTransfer = clone $merchantRelationshipTransfer; |
||
118 | $merchantRelationshipTransfer->setIdMerchantRelationship(null); |
||
119 | $merchantRelationshipRequestTransfer->setMerchantRelationship($merchantRelationshipTransfer); |
||
120 | |||
121 | // Act |
||
122 | $merchantRelationshipResponseTransfer = $this->tester->getFacade()->createMerchantRelationship( |
||
123 | new MerchantRelationshipTransfer(), |
||
124 | $merchantRelationshipRequestTransfer, |
||
125 | ); |
||
126 | |||
127 | // Assert |
||
128 | $this->assertFalse($merchantRelationshipResponseTransfer->getIsSuccessfulOrFail()); |
||
129 | $this->assertCount(1, $merchantRelationshipResponseTransfer->getErrors()); |
||
130 | |||
131 | /** @var \Generated\Shared\Transfer\MerchantRelationshipErrorTransfer $merchantRelationshipErrorTransfer */ |
||
132 | $merchantRelationshipErrorTransfer = $merchantRelationshipResponseTransfer->getErrors()->offsetGet(0); |
||
133 | $this->assertSame(MerchantRelationshipTransfer::MERCHANT_RELATIONSHIP_KEY, $merchantRelationshipErrorTransfer->getField()); |
||
134 | $this->assertSame( |
||
135 | sprintf('Merchant relationship key "%s" already exists.', $merchantRelationshipTransfer->getMerchantRelationshipKey()), |
||
136 | $merchantRelationshipErrorTransfer->getMessage(), |
||
137 | ); |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * @return void |
||
142 | */ |
||
143 | public function testCreateMerchantRelationshipWithNotUniqueKeyThrowsException(): void |
||
144 | { |
||
145 | // Arrange |
||
146 | $merchantRelationshipTransfer = $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST); |
||
147 | $newMerchantRelationshipTransfer = clone $merchantRelationshipTransfer; |
||
148 | $newMerchantRelationshipTransfer->setIdMerchantRelationship(null); |
||
149 | |||
150 | $this->expectException(Exception::class); |
||
151 | |||
152 | // Act |
||
153 | $this->tester->getFacade()->createMerchantRelationship($newMerchantRelationshipTransfer); |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @return void |
||
158 | */ |
||
159 | public function testCreateMerchantRelationshipWithOwner(): void |
||
160 | { |
||
161 | // Arrange |
||
162 | $merchantRelationship = $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST, static::BU_OWNER_KEY_OWNER); |
||
163 | |||
164 | // Assert |
||
165 | $this->assertNotNull($merchantRelationship->getIdMerchantRelationship()); |
||
166 | $this->assertSame( |
||
167 | $merchantRelationship->getOwnerCompanyBusinessUnit()->getIdCompanyBusinessUnit(), |
||
168 | $merchantRelationship->getFkCompanyBusinessUnit(), |
||
169 | ); |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * @return void |
||
174 | */ |
||
175 | public function testCreateMerchantRelationshipWithOneAssignee(): void |
||
176 | { |
||
177 | // Arrange |
||
178 | $companyBusinessUnitTransfer = $this->tester->haveCompanyBusinessUnit([ |
||
179 | CompanyBusinessUnitTransfer::FK_COMPANY => $this->tester->haveCompany()->getIdCompany(), |
||
180 | CompanyBusinessUnitTransfer::KEY => static::BU_OWNER_KEY_OWNER, |
||
181 | ]); |
||
182 | $merchantTransfer = $this->tester->haveMerchant(); |
||
183 | $merchantRelationshipTransfer = (new MerchantRelationshipTransfer()) |
||
184 | ->setMerchantRelationshipKey(static::MR_KEY_1_TEST) |
||
185 | ->setOwnerCompanyBusinessUnit($companyBusinessUnitTransfer) |
||
186 | ->setFkCompanyBusinessUnit($companyBusinessUnitTransfer->getIdCompanyBusinessUnit()) |
||
187 | ->setFkMerchant($merchantTransfer->getIdMerchant()) |
||
188 | ->setAssigneeCompanyBusinessUnits( |
||
189 | (new CompanyBusinessUnitCollectionTransfer()) |
||
190 | ->addCompanyBusinessUnit($companyBusinessUnitTransfer), |
||
191 | ); |
||
192 | |||
193 | // Act |
||
194 | $this->tester->getFacade() |
||
195 | ->createMerchantRelationship($merchantRelationshipTransfer); |
||
196 | |||
197 | // Assert |
||
198 | $this->assertNotNull($merchantRelationshipTransfer->getIdMerchantRelationship()); |
||
199 | $this->assertNotNull($merchantRelationshipTransfer->getAssigneeCompanyBusinessUnits()); |
||
200 | $this->assertCount(1, $merchantRelationshipTransfer->getAssigneeCompanyBusinessUnits()->getCompanyBusinessUnits()); |
||
201 | $this->assertSame(static::BU_OWNER_KEY_OWNER, $merchantRelationshipTransfer->getAssigneeCompanyBusinessUnits()->getCompanyBusinessUnits()[0]->getKey()); |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * @return void |
||
206 | */ |
||
207 | public function testCreateMerchantRelationshipWithFewAssignee(): void |
||
208 | { |
||
209 | // Arrange |
||
210 | $merchantRelationship = $this->tester->createMerchantRelationship( |
||
211 | static::MR_KEY_1_TEST, |
||
212 | static::BU_OWNER_KEY_OWNER, |
||
213 | [static::BU_OWNER_KEY_OWNER, static::BU_KEY_UNIT_1, static::BU_KEY_UNIT_2], |
||
214 | ); |
||
215 | |||
216 | // Assert |
||
217 | $this->assertNotNull($merchantRelationship->getIdMerchantRelationship()); |
||
218 | $this->assertNotNull($merchantRelationship->getAssigneeCompanyBusinessUnits()); |
||
219 | $this->assertCount(3, $merchantRelationship->getAssigneeCompanyBusinessUnits()->getCompanyBusinessUnits()); |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * @return void |
||
224 | */ |
||
225 | public function testUpdateMerchantRelationship(): void |
||
226 | { |
||
227 | // Arrange |
||
228 | $merchantRelationship = $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST); |
||
229 | $idMerchantRelationship = $merchantRelationship->getIdMerchantRelationship(); |
||
230 | |||
231 | $newMerchant = $this->tester->haveMerchant(); |
||
232 | $newCompanyBusinessUnit = $this->tester->haveCompanyBusinessUnit([ |
||
233 | CompanyBusinessUnitTransfer::FK_COMPANY => $this->tester->haveCompany()->getIdCompany(), |
||
234 | ]); |
||
235 | $newKey = 'mr-test-1'; |
||
236 | |||
237 | $merchantRelationship |
||
238 | ->setFkMerchant($newMerchant->getIdMerchant()) |
||
239 | ->setFkCompanyBusinessUnit($newCompanyBusinessUnit->getIdCompanyBusinessUnit()) |
||
240 | ->setMerchantRelationshipKey($newKey); |
||
241 | |||
242 | // Act |
||
243 | $updatedMerchantRelationship = $this->tester->getFacade() |
||
244 | ->updateMerchantRelationship($merchantRelationship); |
||
245 | |||
246 | // Assert |
||
247 | $this->assertSame($idMerchantRelationship, $updatedMerchantRelationship->getIdMerchantRelationship()); |
||
248 | $this->assertSame($newMerchant->getIdMerchant(), $updatedMerchantRelationship->getFkMerchant()); |
||
249 | $this->assertSame($newCompanyBusinessUnit->getIdCompanyBusinessUnit(), $updatedMerchantRelationship->getFkCompanyBusinessUnit()); |
||
250 | $this->assertSame($newKey, $updatedMerchantRelationship->getMerchantRelationshipKey()); |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * @return void |
||
255 | */ |
||
256 | public function testUpdateMerchantRelationshipWithForwardCompatibility(): void |
||
257 | { |
||
258 | // Arrange |
||
259 | $merchantRelationship = $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST); |
||
260 | $idMerchantRelationship = $merchantRelationship->getIdMerchantRelationship(); |
||
261 | |||
262 | $newMerchant = $this->tester->haveMerchant(); |
||
263 | $newCompanyBusinessUnit = $this->tester->haveCompanyBusinessUnit([ |
||
264 | CompanyBusinessUnitTransfer::FK_COMPANY => $this->tester->haveCompany()->getIdCompany(), |
||
265 | ]); |
||
266 | $newKey = 'mr-test-1'; |
||
267 | |||
268 | $merchantRelationship |
||
269 | ->setIdMerchantRelationship($idMerchantRelationship) |
||
270 | ->setFkMerchant($newMerchant->getIdMerchant()) |
||
271 | ->setFkCompanyBusinessUnit($newCompanyBusinessUnit->getIdCompanyBusinessUnit()) |
||
272 | ->setMerchantRelationshipKey($newKey); |
||
273 | |||
274 | $merchantRelationshipRequestTransfer = new MerchantRelationshipRequestTransfer(); |
||
275 | $merchantRelationshipRequestTransfer->setMerchantRelationship($merchantRelationship); |
||
276 | |||
277 | // Act |
||
278 | $updatedMerchantRelationship = $this->tester->getFacade() |
||
279 | ->updateMerchantRelationship( |
||
280 | $merchantRelationship, |
||
281 | $merchantRelationshipRequestTransfer, |
||
282 | ) |
||
283 | ->getMerchantRelationship(); |
||
284 | |||
285 | // Assert |
||
286 | $this->assertSame($idMerchantRelationship, $updatedMerchantRelationship->getIdMerchantRelationship()); |
||
287 | $this->assertSame($newMerchant->getIdMerchant(), $updatedMerchantRelationship->getFkMerchant()); |
||
288 | $this->assertSame($newCompanyBusinessUnit->getIdCompanyBusinessUnit(), $updatedMerchantRelationship->getFkCompanyBusinessUnit()); |
||
289 | $this->assertSame($newKey, $updatedMerchantRelationship->getMerchantRelationshipKey()); |
||
290 | } |
||
291 | |||
292 | /** |
||
293 | * @return void |
||
294 | */ |
||
295 | public function testGetMerchantRelationshipById(): void |
||
296 | { |
||
297 | // Arrange |
||
298 | $expectedMerchantRelationship = $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST); |
||
299 | $expectedMerchantRelationship->setName( |
||
300 | sprintf('%s - %s', $expectedMerchantRelationship->getIdMerchantRelationship(), $expectedMerchantRelationship->getOwnerCompanyBusinessUnit()->getName()), |
||
301 | ); |
||
302 | |||
303 | $merchantRelationship = (new MerchantRelationshipTransfer()) |
||
304 | ->setIdMerchantRelationship( |
||
305 | $expectedMerchantRelationship->getIdMerchantRelationship(), |
||
306 | ); |
||
307 | |||
308 | // Act |
||
309 | $actualMerchantRelationship = $this->tester->getFacade() |
||
310 | ->getMerchantRelationshipById($merchantRelationship); |
||
311 | |||
312 | // Assert |
||
313 | $this->assertSame($expectedMerchantRelationship->getIdMerchantRelationship(), $actualMerchantRelationship->getIdMerchantRelationship()); |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * @return void |
||
318 | */ |
||
319 | public function testDeleteMerchantRelationship(): void |
||
320 | { |
||
321 | // Arrange |
||
322 | $merchantRelationship = $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST); |
||
323 | $idMerchantRelationship = $merchantRelationship->getIdMerchantRelationship(); |
||
324 | |||
325 | // Act |
||
326 | $this->tester->getFacade() |
||
327 | ->deleteMerchantRelationship($merchantRelationship); |
||
328 | |||
329 | // Assert |
||
330 | $this->tester->assertMerchantRelationshipDoesNotExist($idMerchantRelationship); |
||
331 | } |
||
332 | |||
333 | /** |
||
334 | * @return void |
||
335 | */ |
||
336 | public function testDeleteMerchantRelationshipForwardCompatible(): void |
||
337 | { |
||
338 | // Arrange |
||
339 | $merchantRelationship = $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST); |
||
340 | $idMerchantRelationship = $merchantRelationship->getIdMerchantRelationship(); |
||
341 | $merchantRelationshipRequestTransfer = (new MerchantRelationshipRequestTransfer()) |
||
342 | ->setMerchantRelationship($merchantRelationship); |
||
343 | |||
344 | // Act |
||
345 | $this->tester->getFacade() |
||
346 | ->deleteMerchantRelationship($merchantRelationship, $merchantRelationshipRequestTransfer); |
||
347 | |||
348 | // Assert |
||
349 | $this->tester->assertMerchantRelationshipDoesNotExist($idMerchantRelationship); |
||
350 | } |
||
351 | |||
352 | /** |
||
353 | * @return void |
||
354 | */ |
||
355 | public function testDeleteMerchantRelationshipWithAssigneeDeletesAssignee(): void |
||
356 | { |
||
357 | // Arrange |
||
358 | $merchantRelationship = $this->tester->createMerchantRelationship( |
||
359 | static::MR_KEY_1_TEST, |
||
360 | static::BU_OWNER_KEY_OWNER, |
||
361 | [static::BU_OWNER_KEY_OWNER, static::BU_KEY_UNIT_1, static::BU_KEY_UNIT_2], |
||
362 | ); |
||
363 | $idMerchantRelationship = $merchantRelationship->getIdMerchantRelationship(); |
||
364 | |||
365 | // Act |
||
366 | $this->tester->getFacade()->deleteMerchantRelationship( |
||
367 | (new MerchantRelationshipTransfer())->setIdMerchantRelationship($idMerchantRelationship), |
||
368 | ); |
||
369 | |||
370 | // Assert |
||
371 | $this->tester->assertMerchantRelationshipToCompanyBusinessUnitDoesNotExist($idMerchantRelationship); |
||
372 | } |
||
373 | |||
374 | /** |
||
375 | * @return void |
||
376 | */ |
||
377 | public function testDeleteMerchantRelationshipExecutesAStackOfPostDeletePlugins(): void |
||
378 | { |
||
379 | // Assert |
||
380 | $merchantRelationshipPostDeletePluginMock = $this->getMockBuilder(MerchantRelationshipPostDeletePluginInterface::class) |
||
381 | ->getMock(); |
||
382 | $merchantRelationshipPostDeletePluginMock |
||
383 | ->expects($this->once()) |
||
384 | ->method('execute'); |
||
385 | |||
386 | $this->tester->setDependency(MerchantRelationshipDependencyProvider::PLUGINS_MERCHANT_RELATIONSHIP_POST_DELETE, [ |
||
387 | $merchantRelationshipPostDeletePluginMock, |
||
388 | ]); |
||
389 | |||
390 | // Arrange |
||
391 | $merchantRelationshipTransfer = $this->tester->createMerchantRelationship( |
||
392 | static::MR_KEY_1_TEST, |
||
393 | static::BU_OWNER_KEY_OWNER, |
||
394 | [static::BU_OWNER_KEY_OWNER, static::BU_KEY_UNIT_1, static::BU_KEY_UNIT_2], |
||
395 | ); |
||
396 | $merchantRelationshipRequestTransfer = (new MerchantRelationshipRequestTransfer()) |
||
397 | ->setMerchantRelationship($merchantRelationshipTransfer); |
||
398 | |||
399 | // Act |
||
400 | $this->tester->getFacade()->deleteMerchantRelationship( |
||
401 | $merchantRelationshipTransfer, |
||
402 | $merchantRelationshipRequestTransfer, |
||
403 | ); |
||
404 | } |
||
405 | |||
406 | /** |
||
407 | * @return void |
||
408 | */ |
||
409 | public function testGetMerchantRelationshipCollectionWillReturnAllAvailableRelationships(): void |
||
410 | { |
||
411 | // Arrange |
||
412 | $merchantRelationshipConfigMock = $this->tester->mockConfigMethod('getDefaultPaginationLimit', 1000); |
||
413 | |||
414 | $merchantRelationshipPersistenceFactory = (new MerchantRelationshipPersistenceFactory())->setConfig($merchantRelationshipConfigMock); |
||
415 | $merchantRelationshipRepository = (new MerchantRelationshipRepository())->setFactory($merchantRelationshipPersistenceFactory); |
||
416 | $merchantRelationshipBusinessFactory = (new MerchantRelationshipBusinessFactory())->setRepository($merchantRelationshipRepository); |
||
417 | $merchantRelationshipFacade = $this->tester->getFacade()->setFactory($merchantRelationshipBusinessFactory); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
418 | |||
419 | $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST); |
||
420 | |||
421 | // Act |
||
422 | $merchantRelationTransfers = $merchantRelationshipFacade->getMerchantRelationshipCollection(); |
||
423 | |||
424 | // Assert |
||
425 | $this->assertCount($this->tester->getMerchantRelationsCount(), $merchantRelationTransfers); |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * @return void |
||
430 | */ |
||
431 | public function testGetMerchantRelationshipCollectionWillReturnRelationshipsFilteredByIds(): void |
||
432 | { |
||
433 | // Arrange |
||
434 | $merchantRelationshipTransfer = $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST); |
||
435 | $merchantRelationshipFilterTransfer = (new MerchantRelationshipFilterTransfer())->setMerchantRelationshipIds( |
||
436 | [$merchantRelationshipTransfer->getIdMerchantRelationship()], |
||
437 | ); |
||
438 | |||
439 | // Act |
||
440 | $merchantRelationTransfers = $this->tester |
||
441 | ->getFacade() |
||
442 | ->getMerchantRelationshipCollection($merchantRelationshipFilterTransfer); |
||
443 | |||
444 | // Assert |
||
445 | $this->assertCount(1, $merchantRelationTransfers); |
||
446 | } |
||
447 | |||
448 | /** |
||
449 | * @return void |
||
450 | */ |
||
451 | public function testGetFilteredMerchantRelationshipCollection(): void |
||
452 | { |
||
453 | // Arrange |
||
454 | $this->tester->createMerchantRelationships(30); |
||
455 | $merchantRelationshipFilterTransfer = (new MerchantRelationshipFilterTransfer()) |
||
456 | ->setLimit(10); |
||
457 | |||
458 | // Act |
||
459 | $merchantRelationshipTransfers = $this->tester->getFacade() |
||
460 | ->getMerchantRelationshipCollection($merchantRelationshipFilterTransfer); |
||
461 | |||
462 | // Assert |
||
463 | $this->assertNotEmpty($merchantRelationshipTransfers); |
||
464 | $this->assertCount(10, $merchantRelationshipTransfers); |
||
465 | } |
||
466 | |||
467 | /** |
||
468 | * @return void |
||
469 | */ |
||
470 | public function testGetFilteredMerchantRelationshipCollectionShouldReturnEmptyCollectionWhenOutOfBounds(): void |
||
471 | { |
||
472 | // Arrange |
||
473 | $merchantRelationshipFilterTransfer = (new MerchantRelationshipFilterTransfer()) |
||
474 | ->setOffset(100000) |
||
475 | ->setLimit(10); |
||
476 | |||
477 | // Act |
||
478 | $merchantRelationshipTransfers = $this->tester->getFacade() |
||
479 | ->getMerchantRelationshipCollection($merchantRelationshipFilterTransfer); |
||
480 | |||
481 | // Assert |
||
482 | $this->assertCount(0, $merchantRelationshipTransfers, 'The collection should be empty'); |
||
483 | } |
||
484 | |||
485 | /** |
||
486 | * @return void |
||
487 | */ |
||
488 | public function testGetFilteredMerchantRelationshipCollectionFilteredByIdMerchantRelationship(): void |
||
489 | { |
||
490 | // Arrange |
||
491 | $merchantRelationshipTransfer = $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST); |
||
492 | |||
493 | $merchantRelationshipFilterTransfer = (new MerchantRelationshipFilterTransfer()) |
||
494 | ->setLimit(10) |
||
495 | ->setMerchantRelationshipIds( |
||
496 | [$merchantRelationshipTransfer->getIdMerchantRelationship()], |
||
497 | ); |
||
498 | |||
499 | // Act |
||
500 | $merchantRelationshipTransfers = $this->tester->getFacade()->getMerchantRelationshipCollection($merchantRelationshipFilterTransfer); |
||
501 | |||
502 | // Assert |
||
503 | $this->assertCount(1, $merchantRelationshipTransfers); |
||
504 | $this->assertSame( |
||
505 | $merchantRelationshipTransfer->getIdMerchantRelationship(), |
||
506 | $merchantRelationshipTransfers[0]->getIdMerchantRelationship(), |
||
507 | ); |
||
508 | } |
||
509 | |||
510 | /** |
||
511 | * @return void |
||
512 | */ |
||
513 | public function testGetFilteredMerchantRelationshipCollectionWithSortingAsc(): void |
||
514 | { |
||
515 | // Arrange |
||
516 | $this->tester->createMerchantRelationshipsForSorting(5); |
||
517 | $merchantRelationshipFilterTransfer = (new MerchantRelationshipFilterTransfer()) |
||
518 | ->setLimit(5) |
||
519 | ->setSortBy([ |
||
520 | 'Merchant.name' => 'ASC', |
||
521 | 'Merchant.status' => 'ASC', |
||
522 | ]); |
||
523 | |||
524 | // Act |
||
525 | $merchantRelationshipTransfers = $this->tester->getFacade()->getMerchantRelationshipCollection($merchantRelationshipFilterTransfer); |
||
526 | |||
527 | // Assert |
||
528 | $this->assertCount(5, $merchantRelationshipTransfers); |
||
529 | $this->assertSame('AAA-1', $merchantRelationshipTransfers[0]->getMerchantRelationshipKey()); |
||
530 | $this->assertSame('AAA-2', $merchantRelationshipTransfers[1]->getMerchantRelationshipKey()); |
||
531 | $this->assertSame('AAA-3', $merchantRelationshipTransfers[2]->getMerchantRelationshipKey()); |
||
532 | $this->assertSame('AAA-4', $merchantRelationshipTransfers[3]->getMerchantRelationshipKey()); |
||
533 | $this->assertSame('AAA-5', $merchantRelationshipTransfers[4]->getMerchantRelationshipKey()); |
||
534 | } |
||
535 | |||
536 | /** |
||
537 | * @return void |
||
538 | */ |
||
539 | public function testGetFilteredMerchantRelationshipCollectionWithSortingDesc(): void |
||
540 | { |
||
541 | // Arrange |
||
542 | $this->tester->createMerchantRelationshipsForSorting(5, 'DESC'); |
||
543 | $merchantRelationshipFilterTransfer = (new MerchantRelationshipFilterTransfer()) |
||
544 | ->setLimit(5) |
||
545 | ->setSortBy([ |
||
546 | 'Merchant.name' => 'DESC', |
||
547 | 'Merchant.status' => 'DESC', |
||
548 | ]); |
||
549 | |||
550 | // Act |
||
551 | $merchantRelationshipTransfers = $this->tester->getFacade()->getMerchantRelationshipCollection($merchantRelationshipFilterTransfer); |
||
552 | |||
553 | // Assert |
||
554 | $this->assertCount(5, $merchantRelationshipTransfers); |
||
555 | $this->assertSame('ZZZ-5', $merchantRelationshipTransfers[0]->getMerchantRelationshipKey()); |
||
556 | $this->assertSame('ZZZ-4', $merchantRelationshipTransfers[1]->getMerchantRelationshipKey()); |
||
557 | $this->assertSame('ZZZ-3', $merchantRelationshipTransfers[2]->getMerchantRelationshipKey()); |
||
558 | $this->assertSame('ZZZ-2', $merchantRelationshipTransfers[3]->getMerchantRelationshipKey()); |
||
559 | $this->assertSame('ZZZ-1', $merchantRelationshipTransfers[4]->getMerchantRelationshipKey()); |
||
560 | } |
||
561 | |||
562 | /** |
||
563 | * @return void |
||
564 | */ |
||
565 | public function testGetMerchantRelationshipCollectionByCriteriaTransfer(): void |
||
566 | { |
||
567 | // Arrange |
||
568 | $this->tester->createMerchantRelationships(30); |
||
569 | $paginationTransfer = (new PaginationTransfer()) |
||
570 | ->setFirstIndex(10) |
||
571 | ->setMaxPerPage(10); |
||
572 | $merchantRelationshipCriteriaTransfer = (new MerchantRelationshipCriteriaTransfer()) |
||
573 | ->setPagination($paginationTransfer); |
||
574 | |||
575 | // Act |
||
576 | $merchantRelationshipCollectionTransfer = $this->tester->getFacade() |
||
577 | ->getMerchantRelationshipCollection( |
||
578 | null, |
||
579 | $merchantRelationshipCriteriaTransfer, |
||
580 | ); |
||
581 | |||
582 | // Assert |
||
583 | $this->assertGreaterThan(0, $merchantRelationshipCollectionTransfer->getMerchantRelationships()->count()); |
||
584 | $paginationTransfer = $merchantRelationshipCollectionTransfer->getPagination(); |
||
585 | $this->assertNotEmpty($paginationTransfer); |
||
586 | $this->assertSame(2, $paginationTransfer->getPage()); |
||
587 | $this->assertSame(10, $paginationTransfer->getMaxPerPage()); |
||
588 | $this->assertSame($this->tester->getMerchantRelationsCount(), $paginationTransfer->getNbResults()); |
||
589 | } |
||
590 | |||
591 | /** |
||
592 | * @return void |
||
593 | */ |
||
594 | public function testGetMerchantRelationshipCollectionByCriteriaShouldReturnEmptyCollectionWhenOutOfBounds(): void |
||
595 | { |
||
596 | // Arrange |
||
597 | $paginationTransfer = (new PaginationTransfer()) |
||
598 | ->setFirstIndex(10000) |
||
599 | ->setMaxPerPage(10); |
||
600 | $merchantRelationshipCriteriaTransfer = (new MerchantRelationshipCriteriaTransfer()) |
||
601 | ->setPagination($paginationTransfer); |
||
602 | |||
603 | // Act |
||
604 | $merchantRelationshipCollectionTransfer = $this->tester->getFacade() |
||
605 | ->getMerchantRelationshipCollection(null, $merchantRelationshipCriteriaTransfer); |
||
606 | |||
607 | // Assert |
||
608 | $this->assertCount(0, $merchantRelationshipCollectionTransfer->getMerchantRelationships(), 'The collection should be empty'); |
||
609 | } |
||
610 | |||
611 | /** |
||
612 | * @return void |
||
613 | */ |
||
614 | public function testGetMerchantRelationshipCollectionByCriteriaFilteredByIdMerchantRelationship(): void |
||
615 | { |
||
616 | // Arrange |
||
617 | $merchantRelationshipTransfer = $this->tester->createMerchantRelationship(static::MR_KEY_1_TEST); |
||
618 | |||
619 | $paginationTransfer = (new PaginationTransfer()) |
||
620 | ->setMaxPerPage(10); |
||
621 | $merchantRelationshipConditionsTransfer = (new MerchantRelationshipConditionsTransfer()) |
||
622 | ->setMerchantRelationshipIds([$merchantRelationshipTransfer->getIdMerchantRelationship()]); |
||
623 | $merchantRelationshipCriteriaTransfer = (new MerchantRelationshipCriteriaTransfer()) |
||
624 | ->setMerchantRelationshipConditions($merchantRelationshipConditionsTransfer) |
||
625 | ->setPagination($paginationTransfer); |
||
626 | |||
627 | // Act |
||
628 | $merchantRelationshipCollectionTransfer = $this->tester->getFacade() |
||
629 | ->getMerchantRelationshipCollection(null, $merchantRelationshipCriteriaTransfer); |
||
630 | |||
631 | // Assert |
||
632 | $this->assertCount(1, $merchantRelationshipCollectionTransfer->getMerchantRelationships()); |
||
633 | $this->assertSame( |
||
634 | $merchantRelationshipTransfer->getIdMerchantRelationship(), |
||
635 | $merchantRelationshipCollectionTransfer->getMerchantRelationships()[0]->getIdMerchantRelationship(), |
||
636 | ); |
||
637 | } |
||
638 | |||
639 | /** |
||
640 | * @return void |
||
641 | */ |
||
642 | public function testGetMerchantRelationshipCollectionByCriteriaWithSortingAsc(): void |
||
643 | { |
||
644 | // Arrange |
||
645 | $this->tester->createMerchantRelationshipsForSorting(5); |
||
646 | |||
647 | $paginationTransfer = (new PaginationTransfer()) |
||
648 | ->setMaxPerPage(5); |
||
649 | $sortCollectionTransfer = (new SortCollectionTransfer()) |
||
650 | ->addSort((new SortTransfer()) |
||
651 | ->setField('Merchant.name') |
||
652 | ->setIsAscending(true)) |
||
653 | ->addSort((new SortTransfer()) |
||
654 | ->setField('Merchant.status') |
||
655 | ->setIsAscending(true)); |
||
656 | |||
657 | $merchantRelationshipCriteriaTransfer = (new MerchantRelationshipCriteriaTransfer()) |
||
658 | ->setPagination($paginationTransfer) |
||
659 | ->setSortCollection($sortCollectionTransfer); |
||
660 | |||
661 | // Act |
||
662 | $merchantRelationshipCollectionTransfer = $this->tester->getFacade() |
||
663 | ->getMerchantRelationshipCollection(null, $merchantRelationshipCriteriaTransfer); |
||
664 | |||
665 | // Assert |
||
666 | $this->assertCount(5, $merchantRelationshipCollectionTransfer->getMerchantRelationships()); |
||
667 | $merchantRelationships = $merchantRelationshipCollectionTransfer->getMerchantRelationships(); |
||
668 | |||
669 | $this->assertSame('AAA-1', $merchantRelationships[0]->getMerchantRelationshipKey()); |
||
670 | $this->assertSame('AAA-2', $merchantRelationships[1]->getMerchantRelationshipKey()); |
||
671 | $this->assertSame('AAA-3', $merchantRelationships[2]->getMerchantRelationshipKey()); |
||
672 | $this->assertSame('AAA-4', $merchantRelationships[3]->getMerchantRelationshipKey()); |
||
673 | $this->assertSame('AAA-5', $merchantRelationships[4]->getMerchantRelationshipKey()); |
||
674 | } |
||
675 | |||
676 | /** |
||
677 | * @return void |
||
678 | */ |
||
679 | public function testGetMerchantRelationshipCollectionByCriteriaWithSortingDesc(): void |
||
680 | { |
||
681 | // Arrange |
||
682 | $this->tester->createMerchantRelationshipsForSorting(5, 'DESC'); |
||
683 | |||
684 | $paginationTransfer = (new PaginationTransfer()) |
||
685 | ->setMaxPerPage(5); |
||
686 | $sortCollectionTransfer = (new SortCollectionTransfer()) |
||
687 | ->addSort((new SortTransfer()) |
||
688 | ->setField('Merchant.name') |
||
689 | ->setIsAscending(false)) |
||
690 | ->addSort((new SortTransfer()) |
||
691 | ->setField('Merchant.status') |
||
692 | ->setIsAscending(false)); |
||
693 | |||
694 | $merchantRelationshipCriteriaTransfer = (new MerchantRelationshipCriteriaTransfer()) |
||
695 | ->setPagination($paginationTransfer) |
||
696 | ->setSortCollection($sortCollectionTransfer); |
||
697 | |||
698 | // Act |
||
699 | $merchantRelationshipCollectionTransfer = $this->tester->getFacade() |
||
700 | ->getMerchantRelationshipCollection(null, $merchantRelationshipCriteriaTransfer); |
||
701 | |||
702 | // Assert |
||
703 | $this->assertCount(5, $merchantRelationshipCollectionTransfer->getMerchantRelationships()); |
||
704 | $merchantRelationships = $merchantRelationshipCollectionTransfer->getMerchantRelationships(); |
||
705 | |||
706 | $this->assertSame('ZZZ-5', $merchantRelationships[0]->getMerchantRelationshipKey()); |
||
707 | $this->assertSame('ZZZ-4', $merchantRelationships[1]->getMerchantRelationshipKey()); |
||
708 | $this->assertSame('ZZZ-3', $merchantRelationships[2]->getMerchantRelationshipKey()); |
||
709 | $this->assertSame('ZZZ-2', $merchantRelationships[3]->getMerchantRelationshipKey()); |
||
710 | $this->assertSame('ZZZ-1', $merchantRelationships[4]->getMerchantRelationshipKey()); |
||
711 | } |
||
712 | } |
||
713 |