Skip to content

Commit 910eb41

Browse files
fixing conflict merge; fixed unit test
1 parent 094decc commit 910eb41

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

lib/internal/Magento/Framework/Mview/Test/Unit/View/SubscriptionTest.php

+12-20
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function testCreate()
207207
->method('getColumnName')
208208
->willReturn('entity_id');
209209

210-
$this->viewMock->expects($this->exactly(3))
210+
$this->viewMock->expects($this->atLeastOnce())
211211
->method('getChangelog')
212212
->willReturn($changelogMock);
213213

@@ -251,17 +251,15 @@ public function testCreate()
251251
'otherTableName' => ['name' => 'otherTableName', 'column' => 'columnName']
252252
]
253253
);
254-
$otherViewMock->expects($this->exactly(3))
254+
$otherViewMock->expects($this->atLeastOnce())
255255
->method('getChangelog')
256256
->willReturn($otherChangelogMock);
257257

258258
$this->viewMock->expects($this->any())
259259
->method('getId')
260260
->willReturn('this_id');
261-
$this->viewMock->expects($this->never())
262-
->method('getSubscriptions');
263261

264-
$this->viewCollectionMock->expects($this->exactly(1))
262+
$this->viewCollectionMock->expects($this->once())
265263
->method('getViewsByStateMode')
266264
->with(StateInterface::MODE_ENABLED)
267265
->willReturn([$this->viewMock, $otherViewMock]);
@@ -274,8 +272,6 @@ public function testCreate()
274272
->method('createTrigger')
275273
->with($triggerMock);
276274

277-
$this->tableName = 'thisTableName';
278-
279275
$this->viewMock->expects($this->exactly(3))
280276
->method('getSubscriptions')
281277
->willReturn(
@@ -293,7 +289,7 @@ public function testRemove()
293289
$triggerMock = $this->createMock(Trigger::class);
294290
$triggerMock->expects($this->exactly(3))
295291
->method('setName')->willReturnSelf();
296-
$triggerMock->expects($this->exactly(3))
292+
$triggerMock->expects($this->any())
297293
->method('getName')
298294
->willReturn('triggerName');
299295
$triggerMock->expects($this->exactly(3))
@@ -320,7 +316,7 @@ public function testRemove()
320316
true,
321317
[]
322318
);
323-
$otherChangelogMock->expects($this->exactly(3))
319+
$otherChangelogMock->expects($this->any())
324320
->method('getName')
325321
->willReturn('other_test_view_cl');
326322
$otherChangelogMock->expects($this->exactly(3))
@@ -336,17 +332,17 @@ public function testRemove()
336332
true,
337333
[]
338334
);
339-
340-
$otherViewMock->expects($this->exactly(1))
335+
$otherViewMock->expects($this->atLeastOnce())
341336
->method('getId')
342337
->willReturn('other_id');
343-
344-
$otherViewMock->expects($this->exactly(3))
338+
$otherViewMock->expects($this->atLeastOnce())
345339
->method('getChangelog')
346340
->willReturn($otherChangelogMock);
347341

348-
$this->viewMock->expects($this->any())
349-
$otherViewMock->expects($this->any())
342+
$this->viewMock->expects($this->atLeastOnce())
343+
->method('getId')
344+
->willReturn('this_id');
345+
$otherViewMock->expects($this->atLeastOnce())
350346
->method('getSubscriptions')
351347
->willReturn(
352348
[
@@ -355,10 +351,6 @@ public function testRemove()
355351
]
356352
);
357353

358-
$this->viewMock->expects($this->exactly(3))
359-
->method('getId')
360-
->willReturn('this_id');
361-
362354
$this->viewCollectionMock->expects($this->exactly(1))
363355
->method('getViewsByStateMode')
364356
->with(StateInterface::MODE_ENABLED)
@@ -443,7 +435,7 @@ public function testBuildStatementIgnoredColumnSubscriptionLevel(): void
443435
'cataloginventory_stock_item' => ['name' => 'otherTableName', 'column' => 'columnName']
444436
]
445437
);
446-
$this->viewMock->expects($this->once())
438+
$this->viewMock->expects($this->atLeastOnce())
447439
->method('getChangeLog')
448440
->willReturn($otherChangelogMock);
449441

lib/internal/Magento/Framework/Mview/View/Subscription.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Framework\DB\Adapter\AdapterInterface;
1212
use Magento\Framework\DB\Ddl\Trigger;
13-
use Magento\Framework\Mview\Config;
14-
use Magento\Framework\Mview\View\StateInterface;
1513
use Magento\Framework\DB\Ddl\TriggerFactory;
14+
use Magento\Framework\Mview\Config;
1615
use Magento\Framework\Mview\ViewInterface;
1716

1817
/**
@@ -212,21 +211,22 @@ protected function getLinkedViews()
212211
/**
213212
* Prepare columns for trigger statement. Should be protected in order to serve new approach
214213
*
215-
* @param ChangelogInterface $changelog
214+
* @param ViewInterface $view
216215
* @param string $event
217216
* @return array
218217
* @throws \Exception
219218
*/
220-
protected function prepareColumns(ChangelogInterface $changelog, string $event): array
219+
protected function prepareColumns(ViewInterface $view, string $event): array
221220
{
221+
$changelog = $view->getChangelog();
222222
$prefix = $event === Trigger::EVENT_DELETE ? 'OLD.' : 'NEW.';
223223
$subscriptionData = $this->mviewConfig->getView($changelog->getViewId())['subscriptions'][$this->getTableName()];
224224
$columns = [
225225
'column_names' => [
226226
'entity_id' => $this->connection->quoteIdentifier($changelog->getColumnName())
227227
],
228228
'column_values' => [
229-
'entity_id' => $this->getEntityColumn($prefix)
229+
'entity_id' => $this->getEntityColumn($prefix, $view)
230230
]
231231
];
232232

@@ -251,7 +251,6 @@ protected function prepareColumns(ChangelogInterface $changelog, string $event):
251251
protected function buildStatement(string $event, ViewInterface $view): string
252252
{
253253
$trigger = "%sINSERT IGNORE INTO %s (%s) VALUES (%s);";
254-
$column = $this->getSubscriptionColumn($view);
255254
$changelog = $view->getChangelog();
256255

257256
switch ($event) {
@@ -286,13 +285,14 @@ protected function buildStatement(string $event, ViewInterface $view): string
286285
}
287286
break;
288287
}
289-
$columns = $this->prepareColumns($changelog, $event);
288+
$columns = $this->prepareColumns($view, $event);
289+
290290
return sprintf(
291291
$trigger,
292292
$this->getProcessor()->getPreStatements(),
293293
$this->connection->quoteIdentifier($this->resource->getTableName($changelog->getName())),
294-
implode(", " , $columns['column_names']),
295-
implode(", ", $columns['column_values'])
294+
implode(', ', $columns['column_names']),
295+
implode(', ', $columns['column_values'])
296296
);
297297
}
298298

@@ -319,11 +319,12 @@ private function getProcessor(): AdditionalColumnProcessorInterface
319319

320320
/**
321321
* @param string $prefix
322+
* @param ViewInterface $view
322323
* @return string
323324
*/
324-
public function getEntityColumn(string $prefix): string
325+
public function getEntityColumn(string $prefix, ViewInterface $view): string
325326
{
326-
return $prefix . $this->connection->quoteIdentifier($this->getColumnName());
327+
return $prefix . $this->connection->quoteIdentifier($this->getSubscriptionColumn($view));
327328
}
328329

329330
/**

0 commit comments

Comments
 (0)