From 910eb4101338d505fefc48b378082658fc6d7ddf Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Mon, 28 Dec 2020 13:50:49 +0200 Subject: [PATCH] fixing conflict merge; fixed unit test --- .../Mview/Test/Unit/View/SubscriptionTest.php | 32 +++++++------------ .../Framework/Mview/View/Subscription.php | 23 ++++++------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/lib/internal/Magento/Framework/Mview/Test/Unit/View/SubscriptionTest.php b/lib/internal/Magento/Framework/Mview/Test/Unit/View/SubscriptionTest.php index 256f8d0cb19c7..ef55c71b06281 100644 --- a/lib/internal/Magento/Framework/Mview/Test/Unit/View/SubscriptionTest.php +++ b/lib/internal/Magento/Framework/Mview/Test/Unit/View/SubscriptionTest.php @@ -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); @@ -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]); @@ -274,8 +272,6 @@ public function testCreate() ->method('createTrigger') ->with($triggerMock); - $this->tableName = 'thisTableName'; - $this->viewMock->expects($this->exactly(3)) ->method('getSubscriptions') ->willReturn( @@ -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)) @@ -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)) @@ -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( [ @@ -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) @@ -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); diff --git a/lib/internal/Magento/Framework/Mview/View/Subscription.php b/lib/internal/Magento/Framework/Mview/View/Subscription.php index cad9bc6675c1e..03a3bf9615ced 100644 --- a/lib/internal/Magento/Framework/Mview/View/Subscription.php +++ b/lib/internal/Magento/Framework/Mview/View/Subscription.php @@ -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; /** @@ -212,13 +211,14 @@ 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 = [ @@ -226,7 +226,7 @@ protected function prepareColumns(ChangelogInterface $changelog, string $event): 'entity_id' => $this->connection->quoteIdentifier($changelog->getColumnName()) ], 'column_values' => [ - 'entity_id' => $this->getEntityColumn($prefix) + 'entity_id' => $this->getEntityColumn($prefix, $view) ] ]; @@ -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) { @@ -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']) ); } @@ -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)); } /**