27 private $indexScopeResolver;
37 private $indexSwitcher;
46 $this->resource = $this->getMockBuilder(ResourceConnection::class)
47 ->setMethods([
'getConnection'])
48 ->disableOriginalConstructor()
50 $this->connection = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\AdapterInterface::class)
51 ->setMethods([
'isTableExists',
'dropTable',
'renameTable'])
52 ->getMockForAbstractClass();
53 $this->resource->expects($this->any())
54 ->method(
'getConnection')
55 ->willReturn($this->connection);
56 $this->indexScopeResolver = $this->getMockBuilder(
57 \
Magento\Framework\Search\Request\IndexScopeResolverInterface::class
59 ->setMethods([
'resolve'])
60 ->getMockForAbstractClass();
61 $this->scopeState = $this->getMockBuilder(State::class)
62 ->setMethods([
'getState',
'useRegularIndex',
'useTemporaryIndex'])
63 ->disableOriginalConstructor()
66 $objectManagerHelper =
new ObjectManagerHelper($this);
67 $this->indexSwitcher = $objectManagerHelper->getObject(
68 \
Magento\CatalogSearch\Model\Indexer\Scope\IndexSwitcher::class,
70 'resource' => $this->resource,
71 'indexScopeResolver' => $this->indexScopeResolver,
72 'state' => $this->scopeState,
79 $dimensions = [$this->getMockBuilder(Dimension::class)->setConstructorArgs([
'scope',
'1'])];
81 $this->scopeState->expects($this->once())
85 $this->indexScopeResolver->expects($this->never())->method(
'resolve');
86 $this->connection->expects($this->never())->method(
'renameTable');
88 $this->indexSwitcher->switchIndex($dimensions);
93 $dimensions = [$this->getMockBuilder(Dimension::class)->setConstructorArgs([
'scope',
'1'])];
95 $this->scopeState->expects($this->once())
97 ->willReturn(
'unknown_state');
99 $this->indexScopeResolver->expects($this->never())->method(
'resolve');
100 $this->connection->expects($this->never())->method(
'renameTable');
102 $this->indexSwitcher->switchIndex($dimensions);
107 $dimensions = [$this->getMockBuilder(Dimension::class)->setConstructorArgs([
'scope',
'1'])];
109 $this->scopeState->expects($this->once())
113 $this->scopeState->expects($this->at(1))->method(
'useRegularIndex');
114 $this->scopeState->expects($this->at(2))->method(
'useTemporaryIndex');
116 $this->indexScopeResolver->expects($this->exactly(2))->method(
'resolve')
118 [$this->equalTo(FulltextIndexer::INDEXER_ID), $this->equalTo($dimensions)],
119 [$this->equalTo(FulltextIndexer::INDEXER_ID), $this->equalTo($dimensions)]
121 ->willReturnOnConsecutiveCalls(
122 'catalogsearch_fulltext_scope1_tmp1',
123 'catalogsearch_fulltext_scope1' 126 $this->connection->expects($this->exactly(2))->method(
'isTableExists')
128 [$this->equalTo(
'catalogsearch_fulltext_scope1_tmp1'), $this->equalTo(
null)],
129 [$this->equalTo(
'catalogsearch_fulltext_scope1'), $this->equalTo(
null)]
131 ->willReturnOnConsecutiveCalls(
136 $this->connection->expects($this->once())->method(
'dropTable')->with(
'catalogsearch_fulltext_scope1',
null);
137 $this->connection->expects($this->once())
138 ->method(
'renameTable')
139 ->with(
'catalogsearch_fulltext_scope1_tmp1',
'catalogsearch_fulltext_scope1');
141 $this->indexSwitcher->switchIndex($dimensions);
146 $dimensions = [$this->getMockBuilder(Dimension::class)->setConstructorArgs([
'scope',
'1'])];
148 $this->scopeState->expects($this->once())
152 $this->scopeState->expects($this->at(1))->method(
'useRegularIndex');
153 $this->scopeState->expects($this->at(2))->method(
'useTemporaryIndex');
155 $this->indexScopeResolver->expects($this->exactly(2))->method(
'resolve')
157 [$this->equalTo(FulltextIndexer::INDEXER_ID), $this->equalTo($dimensions)],
158 [$this->equalTo(FulltextIndexer::INDEXER_ID), $this->equalTo($dimensions)]
160 ->willReturnOnConsecutiveCalls(
161 'catalogsearch_fulltext_scope1_tmp1',
162 'catalogsearch_fulltext_scope1' 165 $this->connection->expects($this->exactly(2))->method(
'isTableExists')
167 [$this->equalTo(
'catalogsearch_fulltext_scope1_tmp1'), $this->equalTo(
null)],
168 [$this->equalTo(
'catalogsearch_fulltext_scope1'), $this->equalTo(
null)]
170 ->willReturnOnConsecutiveCalls(
175 $this->connection->expects($this->never())->method(
'dropTable')->with(
'catalogsearch_fulltext_scope1',
null);
176 $this->connection->expects($this->once())
177 ->method(
'renameTable')
178 ->with(
'catalogsearch_fulltext_scope1_tmp1',
'catalogsearch_fulltext_scope1');
180 $this->indexSwitcher->switchIndex($dimensions);
189 $dimensions = [$this->getMockBuilder(Dimension::class)->setConstructorArgs([
'scope',
'1'])];
191 $this->scopeState->expects($this->once())
195 $this->scopeState->expects($this->never())->method(
'useRegularIndex');
196 $this->scopeState->expects($this->never())->method(
'useTemporaryIndex');
198 $this->indexScopeResolver->expects($this->once())->method(
'resolve')
199 ->with(FulltextIndexer::INDEXER_ID, $dimensions)
200 ->willReturn(
'catalogsearch_fulltext_scope1_tmp1');
202 $this->connection->expects($this->once())
203 ->method(
'isTableExists')
204 ->with(
'catalogsearch_fulltext_scope1_tmp1',
null)
207 $this->connection->expects($this->never())->method(
'dropTable')->with(
'catalogsearch_fulltext_scope1',
null);
208 $this->connection->expects($this->never())->method(
'renameTable');
210 $this->indexSwitcher->switchIndex($dimensions);
testSwitchIndexWithUnknownState()
testSwitchTemporaryIndexWhenRegularIndexExist()
const USE_TEMPORARY_INDEX
testSwitchWhenTemporaryIndexNotExist()
testSwitchTemporaryIndexWhenRegularIndexNotExist()