Skip to content

Commit e61d008

Browse files
committed
MC-38806: Wrong table comment after reindex
1 parent 5e11dbf commit e61d008

File tree

2 files changed

+56
-28
lines changed

2 files changed

+56
-28
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,22 @@ public function switchTable(\Magento\Framework\DB\Adapter\AdapterInterface $conn
4040
$outdatedTableName = $tableName . $this->outdatedTableSuffix;
4141
$replicaTableName = $tableName . $this->additionalTableSuffix;
4242

43-
$tableComment = $connection->showTableStatus($tableName)['Comment'];
44-
45-
$replicaComment = $connection->showTableStatus($replicaTableName)['Comment'];
43+
$tableComment = $connection->showTableStatus($tableName)['Comment'] ?? '';
44+
$replicaComment = $connection->showTableStatus($replicaTableName)['Comment'] ?? '';
4645

4746
$renameBatch = [
4847
[
4948
'oldName' => $tableName,
50-
'newName' => $outdatedTableName
49+
'newName' => $outdatedTableName,
5150
],
5251
[
5352
'oldName' => $replicaTableName,
54-
'newName' => $tableName
53+
'newName' => $tableName,
5554
],
5655
[
5756
'oldName' => $outdatedTableName,
58-
'newName' => $replicaTableName
59-
]
57+
'newName' => $replicaTableName,
58+
],
6059
];
6160

6261
$toRename[] = $renameBatch;

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,88 @@
99

1010
use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
1111
use Magento\Framework\DB\Adapter\AdapterInterface;
12+
use PHPUnit\Framework\MockObject\MockObject;
1213
use PHPUnit\Framework\TestCase;
1314

15+
/**
16+
* Unit test for \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher class.
17+
*/
1418
class ActiveTableSwitcherTest extends TestCase
1519
{
1620
/**
1721
* @var ActiveTableSwitcher
1822
*/
1923
private $model;
2024

25+
/**
26+
* @inheritdoc
27+
*/
2128
protected function setUp(): void
2229
{
2330
$this->model = new ActiveTableSwitcher();
2431
}
2532

33+
/**
34+
* @return void
35+
*/
2636
public function testSwitch()
2737
{
38+
/** @var AdapterInterface|MockObject $connectionMock */
2839
$connectionMock = $this->getMockBuilder(AdapterInterface::class)
2940
->addMethods(['changeTableComment'])
3041
->disableOriginalConstructor()
3142
->getMockForAbstractClass();
43+
$statement = $this->createMock(\Zend_Db_Statement_Interface::class);
3244
$tableName = 'tableName';
3345
$tableData = ['Comment' => 'Table comment'];
3446
$replicaName = 'tableName_replica';
3547
$replicaData = ['Comment' => 'Table comment replica'];
3648

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+
);
4059

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);
4267

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(
5571
[
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);
6187

6288
$this->model->switchTable($connectionMock, [$tableName]);
6389
}
6490

91+
/**
92+
* @return void
93+
*/
6594
public function testGetAdditionalTableName()
6695
{
6796
$tableName = 'table_name';

0 commit comments

Comments
 (0)