9 use \Magento\Framework\Mview\View\Subscription;
40 $this->connectionMock = $this->createMock(\
Magento\Framework\DB\Adapter\Pdo\Mysql::class);
41 $this->resourceMock = $this->createMock(\
Magento\Framework\
App\ResourceConnection::class);
43 $this->connectionMock->expects($this->any())
44 ->method(
'quoteIdentifier')
45 ->will($this->returnArgument(0));
47 $this->resourceMock->expects($this->atLeastOnce())
48 ->method(
'getConnection')
49 ->willReturn($this->connectionMock);
51 $this->triggerFactoryMock = $this->createMock(\
Magento\Framework\DB\Ddl\TriggerFactory::class);
52 $this->viewCollectionMock = $this->getMockForAbstractClass(
53 \
Magento\Framework\Mview\
View\CollectionInterface::class,
61 $this->viewMock = $this->getMockForAbstractClass(
62 \
Magento\Framework\Mview\ViewInterface::class,
71 $this->resourceMock->expects($this->any())
72 ->method(
'getTableName')
73 ->will($this->returnArgument(0));
77 $this->triggerFactoryMock,
78 $this->viewCollectionMock,
87 $this->assertEquals($this->viewMock, $this->model->getView());
92 $this->assertEquals($this->tableName, $this->model->getTableName());
97 $this->assertEquals(
'columnName', $this->model->getColumnName());
105 $triggerName =
'trigger_name';
106 $this->resourceMock->expects($this->atLeastOnce())->method(
'getTriggerName')->willReturn($triggerName);
107 $triggerMock = $this->getMockBuilder(\
Magento\Framework\DB\Ddl\Trigger::class)
108 ->setMethods([
'setName',
'getName',
'setTime',
'setEvent',
'setTable',
'addStatement'])
109 ->disableOriginalConstructor()
111 $triggerMock->expects($this->exactly(3))
114 ->will($this->returnSelf());
115 $triggerMock->expects($this->exactly(3))
117 ->will($this->returnValue(
'triggerName'));
118 $triggerMock->expects($this->exactly(3))
121 ->will($this->returnSelf());
122 $triggerMock->expects($this->exactly(3))
124 ->will($this->returnSelf());
125 $triggerMock->expects($this->exactly(3))
127 ->with($this->tableName)
128 ->will($this->returnSelf());
130 $triggerMock->expects($this->at(4))
131 ->method(
'addStatement')
132 ->with(
"INSERT IGNORE INTO test_view_cl (entity_id) VALUES (NEW.columnName);")
133 ->will($this->returnSelf());
135 $triggerMock->expects($this->at(5))
136 ->method(
'addStatement')
137 ->with(
"INSERT IGNORE INTO other_test_view_cl (entity_id) VALUES (NEW.columnName);")
138 ->will($this->returnSelf());
140 $triggerMock->expects($this->at(11))
141 ->method(
'addStatement')
142 ->with(
"INSERT IGNORE INTO test_view_cl (entity_id) VALUES (NEW.columnName);")
143 ->will($this->returnSelf());
145 $triggerMock->expects($this->at(12))
146 ->method(
'addStatement')
147 ->with(
"INSERT IGNORE INTO other_test_view_cl (entity_id) VALUES (NEW.columnName);")
148 ->will($this->returnSelf());
150 $triggerMock->expects($this->at(18))
151 ->method(
'addStatement')
152 ->with(
"INSERT IGNORE INTO test_view_cl (entity_id) VALUES (OLD.columnName);")
153 ->will($this->returnSelf());
155 $triggerMock->expects($this->at(19))
156 ->method(
'addStatement')
157 ->with(
"INSERT IGNORE INTO other_test_view_cl (entity_id) VALUES (OLD.columnName);")
158 ->will($this->returnSelf());
160 $changelogMock = $this->getMockForAbstractClass(
161 \
Magento\Framework\Mview\
View\ChangelogInterface::class,
169 $changelogMock->expects($this->exactly(3))
171 ->will($this->returnValue(
'test_view_cl'));
172 $changelogMock->expects($this->exactly(3))
173 ->method(
'getColumnName')
174 ->will($this->returnValue(
'entity_id'));
176 $this->viewMock->expects($this->exactly(3))
177 ->method(
'getChangelog')
178 ->will($this->returnValue($changelogMock));
180 $this->triggerFactoryMock->expects($this->exactly(3))
182 ->will($this->returnValue($triggerMock));
184 $otherChangelogMock = $this->getMockForAbstractClass(
185 \
Magento\Framework\Mview\
View\ChangelogInterface::class,
193 $otherChangelogMock->expects($this->exactly(3))
195 ->will($this->returnValue(
'other_test_view_cl'));
196 $otherChangelogMock->expects($this->exactly(3))
197 ->method(
'getColumnName')
198 ->will($this->returnValue(
'entity_id'));
200 $otherViewMock = $this->getMockForAbstractClass(
201 \
Magento\Framework\Mview\ViewInterface::class,
209 $otherViewMock->expects($this->exactly(1))
211 ->will($this->returnValue(
'other_id'));
212 $otherViewMock->expects($this->exactly(1))
213 ->method(
'getSubscriptions')
214 ->will($this->returnValue([[
'name' => $this->tableName], [
'name' =>
'otherTableName']]));
215 $otherViewMock->expects($this->exactly(3))
216 ->method(
'getChangelog')
217 ->will($this->returnValue($otherChangelogMock));
219 $this->viewMock->expects($this->exactly(3))
221 ->will($this->returnValue(
'this_id'));
222 $this->viewMock->expects($this->never())
223 ->method(
'getSubscriptions');
225 $this->viewCollectionMock->expects($this->exactly(1))
226 ->method(
'getViewsByStateMode')
228 ->will($this->returnValue([$this->viewMock, $otherViewMock]));
230 $this->connectionMock->expects($this->exactly(3))
231 ->method(
'dropTrigger')
232 ->with(
'triggerName')
233 ->will($this->returnValue(
true));
234 $this->connectionMock->expects($this->exactly(3))
235 ->method(
'createTrigger')
236 ->with($triggerMock);
238 $this->model->create();
243 $triggerMock = $this->createMock(\
Magento\Framework\DB\Ddl\Trigger::class);
244 $triggerMock->expects($this->exactly(3))
246 ->will($this->returnSelf());
247 $triggerMock->expects($this->exactly(3))
249 ->will($this->returnValue(
'triggerName'));
250 $triggerMock->expects($this->exactly(3))
253 ->will($this->returnSelf());
254 $triggerMock->expects($this->exactly(3))
256 ->will($this->returnSelf());
257 $triggerMock->expects($this->exactly(3))
259 ->with($this->tableName)
260 ->will($this->returnSelf());
261 $triggerMock->expects($this->exactly(3))
262 ->method(
'addStatement')
263 ->will($this->returnSelf());
265 $this->triggerFactoryMock->expects($this->exactly(3))
267 ->will($this->returnValue($triggerMock));
269 $otherChangelogMock = $this->getMockForAbstractClass(
270 \
Magento\Framework\Mview\
View\ChangelogInterface::class,
278 $otherChangelogMock->expects($this->exactly(3))
280 ->will($this->returnValue(
'other_test_view_cl'));
281 $otherChangelogMock->expects($this->exactly(3))
282 ->method(
'getColumnName')
283 ->will($this->returnValue(
'entity_id'));
285 $otherViewMock = $this->getMockForAbstractClass(
286 \
Magento\Framework\Mview\ViewInterface::class,
294 $otherViewMock->expects($this->exactly(1))
296 ->will($this->returnValue(
'other_id'));
297 $otherViewMock->expects($this->exactly(1))
298 ->method(
'getSubscriptions')
299 ->will($this->returnValue([[
'name' => $this->tableName], [
'name' =>
'otherTableName']]));
300 $otherViewMock->expects($this->exactly(3))
301 ->method(
'getChangelog')
302 ->will($this->returnValue($otherChangelogMock));
304 $this->viewMock->expects($this->exactly(3))
306 ->will($this->returnValue(
'this_id'));
307 $this->viewMock->expects($this->never())
308 ->method(
'getSubscriptions');
310 $this->viewCollectionMock->expects($this->exactly(1))
311 ->method(
'getViewsByStateMode')
313 ->will($this->returnValue([$this->viewMock, $otherViewMock]));
315 $this->connectionMock->expects($this->exactly(3))
316 ->method(
'dropTrigger')
317 ->with(
'triggerName')
318 ->will($this->returnValue(
true));
320 $triggerMock->expects($this->exactly(3))
321 ->method(
'getStatements')
322 ->will($this->returnValue(
true));
324 $this->connectionMock->expects($this->exactly(3))
325 ->method(
'createTrigger')
326 ->with($triggerMock);
328 $this->model->remove();