Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LinkedProductSelectBuilderByIndexPriceTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class LinkedProductSelectBuilderByIndexPriceTest extends \PHPUnit\Framework\TestCase
14 {
18  private $storeManagerMock;
19 
23  private $resourceMock;
24 
28  private $customerSessionMock;
29 
33  private $metadataPoolMock;
34 
38  private $baseSelectProcessorMock;
39 
43  private $model;
44 
45  protected function setUp()
46  {
47  $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
48  ->disableOriginalConstructor()
49  ->getMockForAbstractClass();
50  $this->resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class)
51  ->disableOriginalConstructor()->getMock();
52  $this->customerSessionMock = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55  $this->metadataPoolMock = $this->getMockBuilder(\Magento\Framework\EntityManager\MetadataPool::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58  $this->baseSelectProcessorMock =
59  $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface::class)
60  ->disableOriginalConstructor()
61  ->getMockForAbstractClass();
62 
63  $this->indexScopeResolverMock = $this->createMock(
64  \Magento\Framework\Search\Request\IndexScopeResolverInterface::class
65  );
66  $this->dimensionMock = $this->createMock(\Magento\Framework\Indexer\Dimension::class);
67  $this->dimensionFactoryMock = $this->createMock(\Magento\Framework\Indexer\DimensionFactory::class);
68  $this->dimensionFactoryMock->method('create')->willReturn($this->dimensionMock);
69  $storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
70  $storeMock->method('getId')->willReturn(1);
71  $storeMock->method('getWebsiteId')->willReturn(1);
72  $this->storeManagerMock->method('getStore')->willReturn($storeMock);
73 
74  $this->model = new \Magento\Catalog\Model\ResourceModel\Product\Indexer\LinkedProductSelectBuilderByIndexPrice(
75  $this->storeManagerMock,
76  $this->resourceMock,
77  $this->customerSessionMock,
78  $this->metadataPoolMock,
79  $this->baseSelectProcessorMock,
80  $this->indexScopeResolverMock,
81  $this->dimensionFactoryMock
82  );
83  }
84 
85  public function testBuild()
86  {
87  $productId = 10;
88  $metadata = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadataInterface::class)
89  ->disableOriginalConstructor()
90  ->getMockForAbstractClass();
91  $connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
92  ->getMockForAbstractClass();
93  $select = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
94  ->disableOriginalConstructor()
95  ->getMock();
96  $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
97  ->getMockForAbstractClass();
98  $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
99  $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->willReturn(1);
100  $connection->expects($this->any())->method('select')->willReturn($select);
101  $select->expects($this->any())->method('from')->willReturnSelf();
102  $select->expects($this->any())->method('joinInner')->willReturnSelf();
103  $select->expects($this->any())->method('where')->willReturnSelf();
104  $select->expects($this->exactly(2))->method('order')->willReturnSelf();
105  $select->expects($this->once())->method('limit')->willReturnSelf();
106  $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($connection);
107  $this->metadataPoolMock->expects($this->once())->method('getMetadata')->willReturn($metadata);
108  $metadata->expects($this->once())->method('getLinkField')->willReturn('row_id');
109  $this->resourceMock->expects($this->any())->method('getTableName');
110  $this->baseSelectProcessorMock->expects($this->once())->method('process')->willReturnSelf();
111  $this->model->build($productId);
112  }
113 }
$connection
Definition: bulk.php:13