Skip to content

Commit

Permalink
fixing conflict merge; fixed unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Charlie committed Dec 28, 2020
1 parent 094decc commit 910eb41
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function testCreate()
->method('getColumnName')
->willReturn('entity_id');

$this->viewMock->expects($this->exactly(3))
$this->viewMock->expects($this->atLeastOnce())
->method('getChangelog')
->willReturn($changelogMock);

Expand Down Expand Up @@ -251,17 +251,15 @@ public function testCreate()
'otherTableName' => ['name' => 'otherTableName', 'column' => 'columnName']
]
);
$otherViewMock->expects($this->exactly(3))
$otherViewMock->expects($this->atLeastOnce())
->method('getChangelog')
->willReturn($otherChangelogMock);

$this->viewMock->expects($this->any())
->method('getId')
->willReturn('this_id');
$this->viewMock->expects($this->never())
->method('getSubscriptions');

$this->viewCollectionMock->expects($this->exactly(1))
$this->viewCollectionMock->expects($this->once())
->method('getViewsByStateMode')
->with(StateInterface::MODE_ENABLED)
->willReturn([$this->viewMock, $otherViewMock]);
Expand All @@ -274,8 +272,6 @@ public function testCreate()
->method('createTrigger')
->with($triggerMock);

$this->tableName = 'thisTableName';

$this->viewMock->expects($this->exactly(3))
->method('getSubscriptions')
->willReturn(
Expand All @@ -293,7 +289,7 @@ public function testRemove()
$triggerMock = $this->createMock(Trigger::class);
$triggerMock->expects($this->exactly(3))
->method('setName')->willReturnSelf();
$triggerMock->expects($this->exactly(3))
$triggerMock->expects($this->any())
->method('getName')
->willReturn('triggerName');
$triggerMock->expects($this->exactly(3))
Expand All @@ -320,7 +316,7 @@ public function testRemove()
true,
[]
);
$otherChangelogMock->expects($this->exactly(3))
$otherChangelogMock->expects($this->any())
->method('getName')
->willReturn('other_test_view_cl');
$otherChangelogMock->expects($this->exactly(3))
Expand All @@ -336,17 +332,17 @@ public function testRemove()
true,
[]
);

$otherViewMock->expects($this->exactly(1))
$otherViewMock->expects($this->atLeastOnce())
->method('getId')
->willReturn('other_id');

$otherViewMock->expects($this->exactly(3))
$otherViewMock->expects($this->atLeastOnce())
->method('getChangelog')
->willReturn($otherChangelogMock);

$this->viewMock->expects($this->any())
$otherViewMock->expects($this->any())
$this->viewMock->expects($this->atLeastOnce())
->method('getId')
->willReturn('this_id');
$otherViewMock->expects($this->atLeastOnce())
->method('getSubscriptions')
->willReturn(
[
Expand All @@ -355,10 +351,6 @@ public function testRemove()
]
);

$this->viewMock->expects($this->exactly(3))
->method('getId')
->willReturn('this_id');

$this->viewCollectionMock->expects($this->exactly(1))
->method('getViewsByStateMode')
->with(StateInterface::MODE_ENABLED)
Expand Down Expand Up @@ -443,7 +435,7 @@ public function testBuildStatementIgnoredColumnSubscriptionLevel(): void
'cataloginventory_stock_item' => ['name' => 'otherTableName', 'column' => 'columnName']
]
);
$this->viewMock->expects($this->once())
$this->viewMock->expects($this->atLeastOnce())
->method('getChangeLog')
->willReturn($otherChangelogMock);

Expand Down
23 changes: 12 additions & 11 deletions lib/internal/Magento/Framework/Mview/View/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\DB\Ddl\Trigger;
use Magento\Framework\Mview\Config;
use Magento\Framework\Mview\View\StateInterface;
use Magento\Framework\DB\Ddl\TriggerFactory;
use Magento\Framework\Mview\Config;
use Magento\Framework\Mview\ViewInterface;

/**
Expand Down Expand Up @@ -212,21 +211,22 @@ protected function getLinkedViews()
/**
* Prepare columns for trigger statement. Should be protected in order to serve new approach
*
* @param ChangelogInterface $changelog
* @param ViewInterface $view
* @param string $event
* @return array
* @throws \Exception
*/
protected function prepareColumns(ChangelogInterface $changelog, string $event): array
protected function prepareColumns(ViewInterface $view, string $event): array
{
$changelog = $view->getChangelog();
$prefix = $event === Trigger::EVENT_DELETE ? 'OLD.' : 'NEW.';
$subscriptionData = $this->mviewConfig->getView($changelog->getViewId())['subscriptions'][$this->getTableName()];
$columns = [
'column_names' => [
'entity_id' => $this->connection->quoteIdentifier($changelog->getColumnName())
],
'column_values' => [
'entity_id' => $this->getEntityColumn($prefix)
'entity_id' => $this->getEntityColumn($prefix, $view)
]
];

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

switch ($event) {
Expand Down Expand Up @@ -286,13 +285,14 @@ protected function buildStatement(string $event, ViewInterface $view): string
}
break;
}
$columns = $this->prepareColumns($changelog, $event);
$columns = $this->prepareColumns($view, $event);

return sprintf(
$trigger,
$this->getProcessor()->getPreStatements(),
$this->connection->quoteIdentifier($this->resource->getTableName($changelog->getName())),
implode(", " , $columns['column_names']),
implode(", ", $columns['column_values'])
implode(', ', $columns['column_names']),
implode(', ', $columns['column_values'])
);
}

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

/**
* @param string $prefix
* @param ViewInterface $view
* @return string
*/
public function getEntityColumn(string $prefix): string
public function getEntityColumn(string $prefix, ViewInterface $view): string
{
return $prefix . $this->connection->quoteIdentifier($this->getColumnName());
return $prefix . $this->connection->quoteIdentifier($this->getSubscriptionColumn($view));
}

/**
Expand Down

0 comments on commit 910eb41

Please sign in to comment.