Skip to content

Commit

Permalink
#21853: Allow mview indexers to use different entity columns - unit &…
Browse files Browse the repository at this point in the history
… static tests fix.
  • Loading branch information
engcom-Foxtrot committed Sep 28, 2020
1 parent 392dbf6 commit ff56be5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SubscriptionTest extends TestCase
protected $viewMock;

/** @var string */
private $tableName;
private $tableName = 'thisTableName';

protected function setUp(): void
{
Expand Down Expand Up @@ -210,9 +210,14 @@ public function testCreate()
$otherViewMock->expects($this->exactly(1))
->method('getId')
->willReturn('other_id');
$otherViewMock->expects($this->exactly(1))
$otherViewMock->expects($this->exactly(4))
->method('getSubscriptions')
->willReturn([['name' => $this->tableName], ['name' => 'otherTableName']]);
->willReturn(
[
$this->tableName => ['name' => $this->tableName, 'column' => 'columnName'],
'otherTableName' => ['name' => 'otherTableName', 'column' => 'columnName']
]
);
$otherViewMock->expects($this->exactly(3))
->method('getChangelog')
->willReturn($otherChangelogMock);
Expand All @@ -234,6 +239,17 @@ public function testCreate()
->method('createTrigger')
->with($triggerMock);

$this->tableName = 'thisTableName';

$this->viewMock->expects($this->exactly(3))
->method('getSubscriptions')
->willReturn(
[
$this->tableName => ['name' => $this->tableName, 'column' => 'columnName'],
'otherTableName' => ['name' => 'otherTableName', 'column' => 'columnName']
]
);

$this->model->create();
}

Expand Down Expand Up @@ -285,6 +301,7 @@ public function testRemove()
true,
[]
);

$otherViewMock->expects($this->exactly(1))
->method('getId')
->willReturn('other_id');
Expand All @@ -293,6 +310,15 @@ public function testRemove()
->method('getChangelog')
->willReturn($otherChangelogMock);

$otherViewMock->expects($this->any())
->method('getSubscriptions')
->willReturn(
[
$this->tableName => ['name' => $this->tableName, 'column' => 'columnName'],
'otherTableName' => ['name' => 'otherTableName', 'column' => 'columnName']
]
);

$this->viewMock->expects($this->exactly(3))
->method('getId')
->willReturn('this_id');
Expand Down
6 changes: 2 additions & 4 deletions lib/internal/Magento/Framework/Mview/View/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
use Magento\Framework\Mview\View\StateInterface;

/**
* Class Subscription
*
* @package Magento\Framework\Mview\View
* Mview subscription.
*/
class Subscription implements SubscriptionInterface
{
Expand Down Expand Up @@ -202,7 +200,7 @@ protected function buildStatement($event, $view)
// We will use column name from it.
$subscriptions = $view->getSubscriptions() ?? [];
if (empty($subscriptions[$this->getTableName()])) {
return '';
return '';
}

$subscription = $subscriptions[$this->getTableName()];
Expand Down

0 comments on commit ff56be5

Please sign in to comment.