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