Skip to content

Commit c64c473

Browse files
committed
ACP2E-2692: "Base table or view not found" error occurs when partial reindex
1 parent 045267c commit c64c473

File tree

2 files changed

+174
-2
lines changed

2 files changed

+174
-2
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\Framework\Mview\Test\Unit\View;
20+
21+
use Magento\Framework\App\ResourceConnection;
22+
use Magento\Framework\DB\Adapter\AdapterInterface;
23+
use Magento\Framework\DB\Ddl\Table;
24+
use Magento\Framework\DB\Query\Generator;
25+
use Magento\Framework\DB\Select;
26+
use Magento\Framework\Mview\View\ChangelogInterface;
27+
use Magento\Framework\Mview\View\ChangelogBatchWalker;
28+
use Magento\Framework\Mview\View\ChangelogBatchWalker\IdsContext;
29+
use Magento\Framework\Mview\View\ChangelogBatchWalker\IdsSelectBuilderInterface;
30+
use Magento\Framework\Mview\View\ChangelogBatchWalker\IdsTableBuilderInterface;
31+
use PHPUnit\Framework\MockObject\MockObject;
32+
use PHPUnit\Framework\TestCase;
33+
34+
/**
35+
* Test Coverage for Changelog View.
36+
*
37+
* @see \Magento\Framework\Mview\View\Changelog
38+
*/
39+
class ChangelogBatchWalkerTest extends TestCase
40+
{
41+
/**
42+
* @var ChangelogBatchWalker
43+
*/
44+
protected $model;
45+
46+
/**
47+
* @var ResourceConnection|MockObject
48+
*/
49+
private $resourceConnection;
50+
51+
/**
52+
* @var Generator|MockObject
53+
*/
54+
private $generator;
55+
56+
/**
57+
* @var IdsTableBuilderInterface|MockObject
58+
*/
59+
private $idsTableBuilder;
60+
61+
/**
62+
* @var IdsSelectBuilderInterface|MockObject
63+
*/
64+
private $idsSelectBuilder;
65+
66+
/**
67+
* @var IdsContext|MockObject
68+
*/
69+
private $idsContext;
70+
71+
/**
72+
* @var ChangelogInterface
73+
*/
74+
private $changeLog;
75+
76+
/**
77+
* @var AdapterInterface|MockObject
78+
*/
79+
private $connection;
80+
81+
/**
82+
* @var Table|MockObject
83+
*/
84+
private $table;
85+
86+
/**
87+
* @var Select|MockObject
88+
*/
89+
private $select;
90+
91+
protected function setUp(): void
92+
{
93+
$this->resourceConnection = $this->getMockBuilder(ResourceConnection::class)
94+
->disableOriginalConstructor()
95+
->getMock();
96+
$this->generator = $this->getMockBuilder(Generator::class)
97+
->disableOriginalConstructor()
98+
->getMock();
99+
$this->idsTableBuilder = $this->getMockBuilder(IdsTableBuilderInterface::class)
100+
->getMockForAbstractClass();
101+
$this->idsSelectBuilder = $this->getMockBuilder(IdsSelectBuilderInterface::class)
102+
->getMockForAbstractClass();
103+
$this->idsContext = $this->getMockBuilder(IdsContext::class)
104+
->disableOriginalConstructor()
105+
->getMock();
106+
107+
$this->idsContext->expects($this->any())
108+
->method('getSelectBuilder')
109+
->willReturn($this->idsSelectBuilder);
110+
$this->idsContext->expects($this->any())
111+
->method('getTableBuilder')
112+
->willReturn($this->idsTableBuilder);
113+
114+
$this->changeLog = $this->getMockBuilder(ChangelogInterface::class)
115+
->getMockForAbstractClass();
116+
$this->connection = $this->getMockBuilder(AdapterInterface::class)
117+
->getMockForAbstractClass();
118+
$this->table = $this->getMockBuilder(Table::class)
119+
->disableOriginalConstructor()
120+
->getMock();
121+
$this->resourceConnection->expects($this->any())
122+
->method('getConnection')
123+
->willReturn($this->connection);
124+
125+
$this->select = $this->getMockBuilder(Select::class)
126+
->disableOriginalConstructor()
127+
->getMock();
128+
$this->select->expects($this->any())
129+
->method('from')
130+
->willReturnSelf();
131+
$this->select->expects($this->any())
132+
->method('where')
133+
->willReturnSelf();
134+
$this->select->expects($this->any())
135+
->method('distinct')
136+
->willReturnSelf();
137+
$this->connection->expects($this->any())
138+
->method('select')
139+
->willReturn($this->select);
140+
141+
$this->model = new ChangelogBatchWalker(
142+
$this->resourceConnection,
143+
$this->generator,
144+
$this->idsContext
145+
);
146+
}
147+
148+
public function testNoTemporaryTablesUsed()
149+
{
150+
$this->connection->expects($this->once())
151+
->method('isTableExists')
152+
->willReturn(true);
153+
$this->table->expects($this->any())
154+
->method('getColumns')
155+
->willReturn([]);
156+
$this->idsTableBuilder->expects($this->any())
157+
->method('build')
158+
->willReturn($this->table);
159+
$this->idsSelectBuilder->expects($this->any())
160+
->method('build')
161+
->willReturn($this->select);
162+
$this->generator->expects($this->any())
163+
->method('generate')
164+
->willReturn([]);
165+
166+
foreach ($this->model->walk($this->changeLog, 1, 2, 1) as $iteration) {
167+
$this->assertEmpty($iteration);
168+
$this->connection->expects($this->once())
169+
->method('createTable');
170+
$this->connection->expects($this->never())
171+
->method('createTemporaryTableTable');
172+
}
173+
}
174+
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,9 @@ public function walk(
7474
int $lastVersionId,
7575
int $batchSize
7676
): iterable {
77-
echo '0';
7877
$connection = $this->resourceConnection->getConnection();
7978
$changelogTableName = $this->resourceConnection->getTableName($changelog->getName());
8079

81-
8280
if (!$connection->isTableExists($changelogTableName)) {
8381
throw new ChangelogTableNotExistsException(new Phrase("Table %1 does not exist", [$changelogTableName]));
8482
}

0 commit comments

Comments
 (0)