6 declare(strict_types=1);
14 use PHPUnit_Framework_MockObject_MockObject;
24 private $resourceConnectionMock;
29 private $adapterInterfaceMock;
34 private $statementInterfaceMock;
44 protected function setUp()
46 $this->resourceConnectionMock = $this->createMock(ResourceConnection::class);
48 $this->adapterInterfaceMock = $this->getMockBuilder(AdapterInterface::class)->getMockForAbstractClass();
50 $this->statementInterfaceMock = $this->getMockBuilder(\Zend_Db_Statement_Interface::class)
51 ->getMockForAbstractClass();
53 $this->tableMock = $this->createMock(Table::class);
54 $this->resourceConnectionMock->expects($this->any())
55 ->method(
'getConnection')
56 ->willReturn($this->adapterInterfaceMock);
65 $originalTableName =
'catalogrule_product';
66 $temporaryTableNames = [
'catalogrule_product' =>
'catalogrule_product__temp9604'];
67 $this->setObjectProperty(
$model,
'temporaryTables', $temporaryTableNames);
69 $this->resourceConnectionMock->expects($this->once())
70 ->method(
'getTableName')
71 ->with($originalTableName)
72 ->willReturn($originalTableName);
75 $temporaryTableNames[$originalTableName],
76 $model->getWorkingTableName($originalTableName)
86 $originalTableName =
'catalogrule_product';
87 $temporaryTableName =
'catalogrule_product__temp9604';
88 $this->setObjectProperty(
$model,
'temporaryTables', []);
90 $this->resourceConnectionMock->expects($this->at(0))
91 ->method(
'getTableName')
92 ->with($originalTableName)
93 ->willReturn($originalTableName);
94 $this->resourceConnectionMock->expects($this->at(1))
95 ->method(
'getTableName')
96 ->with($this->stringStartsWith($originalTableName .
'__temp'))
97 ->willReturn($temporaryTableName);
101 $model->getWorkingTableName($originalTableName)
114 private function setObjectProperty($object,
string $propertyName,
$value): void
118 $reflectionProperty->setAccessible(
true);
119 $reflectionProperty->setValue($object,
$value);
127 $model = $this->getMockBuilder(IndexerTableSwapper::class)
128 ->setMethods([
'getWorkingTableName'])
129 ->setConstructorArgs([$this->resourceConnectionMock])
131 $originalTableName =
'catalogrule_product';
132 $temporaryOriginalTableName =
'catalogrule_product9604';
133 $temporaryTableName =
'catalogrule_product__temp9604';
136 'oldName' => $originalTableName,
137 'newName' => $temporaryOriginalTableName,
140 'oldName' => $temporaryTableName,
141 'newName' => $originalTableName,
145 $this->resourceConnectionMock->expects($this->at(0))
146 ->method(
'getTableName')
147 ->with($originalTableName)
148 ->willReturn($originalTableName);
149 $this->resourceConnectionMock->expects($this->at(1))
150 ->method(
'getTableName')
151 ->with($this->stringStartsWith($originalTableName))
152 ->willReturn($temporaryOriginalTableName);
153 $model->expects($this->once())
154 ->method(
'getWorkingTableName')
155 ->with($originalTableName)
156 ->willReturn($temporaryTableName);
157 $this->adapterInterfaceMock->expects($this->once())
158 ->method(
'renameTablesBatch')
161 $this->adapterInterfaceMock->expects($this->once())
162 ->method(
'dropTable')
163 ->with($temporaryOriginalTableName)
166 $model->swapIndexTables([$originalTableName]);
testGetWorkingTableNameWithoutExistingTemporaryTable()
testGetWorkingTableNameWithExistingTemporaryTable()