Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TableDataTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class TableDataTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_connectionMock;
16 
20  protected $_objectManager;
21 
25  protected $_resourceMock;
26 
27  protected function setUp()
28  {
29  $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
30  $this->_connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
31  $this->_resourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
32  }
33 
42  public function testMove(
43  $flatTable,
44  $isFlatTableExists,
45  $flatDropName,
46  $temporaryFlatTableName,
47  $expectedRenameTablesArgument
48  ) {
49  $this->_connectionMock->expects($this->exactly(2))->method('dropTable')->with($flatDropName);
50  $this->_connectionMock->expects(
51  $this->once()
52  )->method(
53  'isTableExists'
54  )->with(
55  $flatTable
56  )->will(
57  $this->returnValue($isFlatTableExists)
58  );
59 
60  $this->_connectionMock->expects(
61  $this->once()
62  )->method(
63  'renameTablesBatch'
64  )->with(
65  $expectedRenameTablesArgument
66  );
67 
68  $this->_resourceMock->expects(
69  $this->any()
70  )->method(
71  'getConnection'
72  )->will(
73  $this->returnValue($this->_connectionMock)
74  );
75 
76  $model = $this->_objectManager->getObject(
77  \Magento\Catalog\Model\Indexer\Product\Flat\TableData::class,
78  ['resource' => $this->_resourceMock]
79  );
80 
81  $model->move($flatTable, $flatDropName, $temporaryFlatTableName);
82  }
83 
87  public function moveDataProvider()
88  {
89  return [
90  [
91  'flat_table',
92  true,
93  'flat_table_to_drop',
94  'flat_tmp',
95  [
96  ['oldName' => 'flat_table', 'newName' => 'flat_table_to_drop'],
97  ['oldName' => 'flat_tmp', 'newName' => 'flat_table']
98  ],
99  ],
100  [
101  'flat_table',
102  false,
103  'flat_table_to_drop',
104  'flat_tmp',
105  [['oldName' => 'flat_tmp', 'newName' => 'flat_table']]
106  ]
107  ];
108  }
109 }
testMove( $flatTable, $isFlatTableExists, $flatDropName, $temporaryFlatTableName, $expectedRenameTablesArgument)