|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2023 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Framework\Api\SearchCriteria\CollectionProcessor; |
| 9 | + |
| 10 | +use Magento\Framework\Api\SearchCriteria\CollectionProcessor\JoinProcessor\CustomJoinInterface; |
| 11 | +use Magento\Framework\Api\SearchCriteriaBuilder; |
| 12 | +use Magento\Framework\Data\Collection\AbstractDb; |
| 13 | +use Magento\Framework\ObjectManagerInterface; |
| 14 | +use Magento\TestFramework\Helper\Bootstrap; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +class JoinProcessorTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var ObjectManagerInterface |
| 21 | + */ |
| 22 | + private $objectManager; |
| 23 | + |
| 24 | + protected function setUp(): void |
| 25 | + { |
| 26 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Test proper application of the join processor for consecutive calls with different collections. |
| 31 | + * |
| 32 | + * @return void |
| 33 | + */ |
| 34 | + public function testMultipleCollections(): void |
| 35 | + { |
| 36 | + $customJoinMock = $this->getMockBuilder(CustomJoinInterface::class) |
| 37 | + ->getMock(); |
| 38 | + |
| 39 | + $customJoinMock->expects($this->exactly(2)) |
| 40 | + ->method('apply'); |
| 41 | + |
| 42 | + $joinProcessor = $this->objectManager->create(JoinProcessor::class, [ |
| 43 | + 'customJoins' => [ |
| 44 | + 'test_join' => $customJoinMock, |
| 45 | + ], |
| 46 | + 'fieldMapping' => [ |
| 47 | + 'test_field' => 'test_join', |
| 48 | + ], |
| 49 | + ]); |
| 50 | + |
| 51 | + $searchCriteria = $this->objectManager->create(SearchCriteriaBuilder::class) |
| 52 | + ->addFilter('test_field', 'test') |
| 53 | + ->create(); |
| 54 | + |
| 55 | + $collection1 = $this->getMockBuilder(AbstractDb::class) |
| 56 | + ->disableOriginalConstructor() |
| 57 | + ->getMock(); |
| 58 | + |
| 59 | + $collection2 = $this->getMockBuilder(AbstractDb::class) |
| 60 | + ->disableOriginalConstructor() |
| 61 | + ->getMock(); |
| 62 | + |
| 63 | + $joinProcessor->process($searchCriteria, $collection1); |
| 64 | + $joinProcessor->process($searchCriteria, $collection2); |
| 65 | + } |
| 66 | +} |
0 commit comments