Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RowSizeEstimatorTest.php
Go to the documentation of this file.
1 <?php
7 
12 class RowSizeEstimatorTest extends \PHPUnit\Framework\TestCase
13 {
17  private $resourceConnectionMock;
18 
22  private $model;
23 
24  protected function setUp()
25  {
26  $this->resourceConnectionMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class)
27  ->disableOriginalConstructor()
28  ->getMock();
29 
30  $this->model = new \Magento\Catalog\Model\Indexer\Category\Product\RowSizeEstimator(
31  $this->resourceConnectionMock
32  );
33  }
34 
35  public function testEstimateRowSize()
36  {
37  $connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
38  ->getMock();
39  $storeGroupCounterMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
40  ->disableOriginalConstructor()
41  ->getMock();
42  $this->resourceConnectionMock->expects($this->exactly(2))
43  ->method('getTableName')
44  ->willReturnMap([['store_group', 'storegrouptable'], ['catalog_category_product', 'ccp']]);
45 
46  $this->resourceConnectionMock->expects($this->once())
47  ->method('getConnection')
48  ->willReturn($connectionMock);
49  $connectionMock->expects($this->exactly(3))
50  ->method('select')
51  ->willReturn($storeGroupCounterMock);
52  $storeGroupCounterMock->expects($this->exactly(3))
53  ->method('from')
54  ->willReturnSelf();
55  $storeGroupCounterMock->expects($this->once())
56  ->method('where')
57  ->with('group_id > 0')
58  ->willReturnSelf();
59  $connectionMock->expects($this->exactly(2))
60  ->method('fetchOne')
61  ->willReturn(5);
62 
63  $storeGroupCounterMock->expects($this->once())
64  ->method('group')
65  ->with('product_id')
66  ->willReturnSelf();
67  $this->assertEquals(2500, $this->model->estimateRowSize());
68  }
69 }