|
9 | 9 |
|
10 | 10 | use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
|
11 | 11 | use Magento\Framework\DB\Adapter\AdapterInterface;
|
| 12 | +use PHPUnit\Framework\MockObject\MockObject; |
12 | 13 | use PHPUnit\Framework\TestCase;
|
13 | 14 |
|
| 15 | +/** |
| 16 | + * Unit test for \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher class. |
| 17 | + */ |
14 | 18 | class ActiveTableSwitcherTest extends TestCase
|
15 | 19 | {
|
16 | 20 | /**
|
17 | 21 | * @var ActiveTableSwitcher
|
18 | 22 | */
|
19 | 23 | private $model;
|
20 | 24 |
|
| 25 | + /** |
| 26 | + * @inheritdoc |
| 27 | + */ |
21 | 28 | protected function setUp(): void
|
22 | 29 | {
|
23 | 30 | $this->model = new ActiveTableSwitcher();
|
24 | 31 | }
|
25 | 32 |
|
| 33 | + /** |
| 34 | + * @return void |
| 35 | + */ |
26 | 36 | public function testSwitch()
|
27 | 37 | {
|
| 38 | + /** @var AdapterInterface|MockObject $connectionMock */ |
28 | 39 | $connectionMock = $this->getMockBuilder(AdapterInterface::class)
|
29 | 40 | ->addMethods(['changeTableComment'])
|
30 | 41 | ->disableOriginalConstructor()
|
31 | 42 | ->getMockForAbstractClass();
|
| 43 | + $statement = $this->createMock(\Zend_Db_Statement_Interface::class); |
32 | 44 | $tableName = 'tableName';
|
33 | 45 | $tableData = ['Comment' => 'Table comment'];
|
34 | 46 | $replicaName = 'tableName_replica';
|
35 | 47 | $replicaData = ['Comment' => 'Table comment replica'];
|
36 | 48 |
|
37 |
| - $connectionMock->expects($this->any())->method('showTableStatus')->willReturn($replicaData); |
38 |
| - |
39 |
| - $connectionMock->expects($this->any())->method('showTableStatus')->willReturn($tableData); |
| 49 | + $connectionMock->expects($this->exactly(2)) |
| 50 | + ->method('showTableStatus') |
| 51 | + ->withConsecutive( |
| 52 | + [$tableName], |
| 53 | + [$replicaName] |
| 54 | + ) |
| 55 | + ->willReturnOnConsecutiveCalls( |
| 56 | + $tableData, |
| 57 | + $replicaData |
| 58 | + ); |
40 | 59 |
|
41 |
| - $connectionMock->expects($this->any())->method('changeTableComment')->with($tableName, $replicaData['Comment']); |
| 60 | + $connectionMock->expects($this->exactly(2)) |
| 61 | + ->method('changeTableComment') |
| 62 | + ->withConsecutive( |
| 63 | + [$tableName, $replicaData['Comment']], |
| 64 | + [$replicaName, $tableData['Comment']] |
| 65 | + ) |
| 66 | + ->willReturn($statement); |
42 | 67 |
|
43 |
| - $connectionMock->expects($this->any())->method('changeTableComment')->with($replicaName, $tableData['Comment']); |
44 |
| - |
45 |
| - $connectionMock->expects($this->once())->method('renameTablesBatch')->with( |
46 |
| - [ |
47 |
| - [ |
48 |
| - 'oldName' => 'tableName', |
49 |
| - 'newName' => 'tableName_outdated' |
50 |
| - ], |
51 |
| - [ |
52 |
| - 'oldName' => 'tableName_replica', |
53 |
| - 'newName' => 'tableName' |
54 |
| - ], |
| 68 | + $connectionMock->expects($this->once()) |
| 69 | + ->method('renameTablesBatch') |
| 70 | + ->with( |
55 | 71 | [
|
56 |
| - 'oldName' => 'tableName_outdated', |
57 |
| - 'newName' => 'tableName_replica' |
58 |
| - ], |
59 |
| - ] |
60 |
| - ); |
| 72 | + [ |
| 73 | + 'oldName' => 'tableName', |
| 74 | + 'newName' => 'tableName_outdated' |
| 75 | + ], |
| 76 | + [ |
| 77 | + 'oldName' => 'tableName_replica', |
| 78 | + 'newName' => 'tableName' |
| 79 | + ], |
| 80 | + [ |
| 81 | + 'oldName' => 'tableName_outdated', |
| 82 | + 'newName' => 'tableName_replica' |
| 83 | + ], |
| 84 | + ] |
| 85 | + ) |
| 86 | + ->willReturn(true); |
61 | 87 |
|
62 | 88 | $this->model->switchTable($connectionMock, [$tableName]);
|
63 | 89 | }
|
64 | 90 |
|
| 91 | + /** |
| 92 | + * @return void |
| 93 | + */ |
65 | 94 | public function testGetAdditionalTableName()
|
66 | 95 | {
|
67 | 96 | $tableName = 'table_name';
|
|
0 commit comments