Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TemporaryTableStrategyTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class TemporaryTableStrategyTest extends \PHPUnit\Framework\TestCase
12 {
16  private $model;
17 
21  private $tableStrategyMock;
22 
26  private $resourceMock;
27 
28  protected function setUp()
29  {
30  $this->tableStrategyMock = $this->createMock(\Magento\Framework\Indexer\Table\Strategy::class);
31  $this->resourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
32 
33  $this->model = new \Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy(
34  $this->tableStrategyMock,
35  $this->resourceMock
36  );
37  }
38 
39  public function testGetUseIdxTable()
40  {
41  $this->tableStrategyMock->expects($this->once())->method('getUseIdxTable')->willReturn(true);
42  $this->assertTrue($this->model->getUseIdxTable());
43  }
44 
45  public function testSetUseIdxTable()
46  {
47  $this->tableStrategyMock->expects($this->once())->method('setUseIdxTable')->with(true)->willReturnSelf();
48  $this->assertEquals($this->tableStrategyMock, $this->model->setUseIdxTable(true));
49  }
50 
51  public function testGetTableName()
52  {
53  $tablePrefix = 'prefix';
55  $this->tableStrategyMock->expects($this->once())->method('getUseIdxTable')->willReturn(true);
56  $this->resourceMock->expects($this->once())
57  ->method('getTableName')
58  ->with($expectedResult)
59  ->willReturn($expectedResult);
60  $this->assertEquals($expectedResult, $this->model->getTableName($tablePrefix));
61  }
62 
63  public function testPrepareTableName()
64  {
65  $tablePrefix = 'prefix';
66  $expectedResult = $tablePrefix . TemporaryTableStrategy::TEMP_SUFFIX;
68 
69  $this->tableStrategyMock->expects($this->once())->method('getUseIdxTable')->willReturn(false);
70  $connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
71 
72  $this->resourceMock->expects($this->once())
73  ->method('getConnection')
74  ->with('indexer')
75  ->willReturn($connectionMock);
76  $this->resourceMock->expects($this->at(1))
77  ->method('getTableName')
78  ->with($expectedResult)
79  ->willReturn($expectedResult);
80  $this->resourceMock->expects($this->at(2))
81  ->method('getTableName')
82  ->with($tempTableName)
83  ->willReturn($tempTableName);
84  $connectionMock->expects($this->once())
85  ->method('createTemporaryTableLike')
86  ->with($expectedResult, $tempTableName, true);
87 
88  $this->assertEquals($expectedResult, $this->model->prepareTableName($tablePrefix));
89  }
90 }