Skip to content

Commit 0d7d5b9

Browse files
committed
Merge branch 'ACP2E-2692' of https://github.com/magento-l3/magento2ce into L3-PR-2024-02-16
2 parents 0d7d3c8 + c64c473 commit 0d7d5b9

File tree

4 files changed

+274
-10
lines changed

4 files changed

+274
-10
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: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,34 @@
2424
class ChangelogBatchWalker implements ChangelogBatchWalkerInterface
2525
{
2626
/**
27-
* @var \Magento\Framework\App\ResourceConnection
27+
* @var ResourceConnection
2828
*/
2929
private ResourceConnection $resourceConnection;
30+
3031
/**
31-
* @var \Magento\Framework\DB\Query\Generator
32+
* @var Generator
3233
*/
3334
private Generator $generator;
35+
3436
/**
35-
* @var \Magento\Framework\Mview\View\ChangelogBatchWalker\IdsTableBuilderInterface
37+
* @var IdsTableBuilderInterface
3638
*/
3739
private IdsTableBuilderInterface $idsTableBuilder;
40+
3841
/**
39-
* @var \Magento\Framework\Mview\View\ChangelogBatchWalker\IdsSelectBuilderInterface
42+
* @var IdsSelectBuilderInterface
4043
*/
4144
private IdsSelectBuilderInterface $idsSelectBuilder;
45+
4246
/**
43-
* @var \Magento\Framework\Mview\View\ChangelogBatchWalker\IdsFetcherInterface
47+
* @var IdsFetcherInterface
4448
*/
4549
private IdsFetcherInterface $idsFetcher;
4650

4751
/**
4852
* @param ResourceConnection $resourceConnection
49-
* @param \Magento\Framework\DB\Query\Generator $generator
50-
* @param \Magento\Framework\Mview\View\ChangelogBatchWalker\IdsContext $idsContext
53+
* @param Generator $generator
54+
* @param IdsContext $idsContext
5155
*/
5256
public function __construct(
5357
ResourceConnection $resourceConnection,
@@ -80,7 +84,7 @@ public function walk(
8084
$idsTable = $this->idsTableBuilder->build($changelog);
8185

8286
try {
83-
$connection->createTemporaryTable($idsTable);
87+
$connection->createTable($idsTable);
8488

8589
$columns = $this->getIdsColumns($idsTable);
8690

@@ -122,7 +126,7 @@ public function walk(
122126
yield $ids;
123127
}
124128
} finally {
125-
$connection->dropTemporaryTable($idsTable->getName());
129+
$connection->dropTable($idsTable->getName());
126130
}
127131
}
128132

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public function build(ChangelogInterface $changelog): Table
5050
['unsigned' => true, 'nullable' => false],
5151
'Entity ID'
5252
);
53-
$table->setOption('type', 'memory');
5453
$table->addIndex(
5554
self::INDEX_NAME_UNIQUE,
5655
[
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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\Test\Unit\Mview\View\ChangelogBatchWalker;
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\Mview\View\ChangelogBatchWalker\IdsTableBuilder;
25+
use Magento\Framework\Mview\View\ChangelogInterface;
26+
use PHPUnit\Framework\MockObject\MockObject;
27+
use PHPUnit\Framework\TestCase;
28+
29+
class IdsTableBuilderTest extends TestCase
30+
{
31+
/**
32+
* @var ResourceConnection|MockObject
33+
*/
34+
private $resourceConnection;
35+
36+
/**
37+
* @var ChangelogInterface|MockObject
38+
*/
39+
private $changeLog;
40+
41+
/**
42+
* @var AdapterInterface|MockObject
43+
*/
44+
private $connection;
45+
46+
/**
47+
* @var Table|MockObject
48+
*/
49+
private $table;
50+
51+
/**
52+
* @var IdsTableBuilder
53+
*/
54+
private $model;
55+
56+
protected function setUp(): void
57+
{
58+
$this->changeLog = $this->getMockBuilder(ChangelogInterface::class)
59+
->getMockForAbstractClass();
60+
$this->connection = $this->getMockBuilder(AdapterInterface::class)
61+
->getMockForAbstractClass();
62+
$this->table = $this->getMockBuilder(Table::class)
63+
->disableOriginalConstructor()
64+
->getMock();
65+
66+
$this->resourceConnection = $this->getMockBuilder(ResourceConnection::class)
67+
->disableOriginalConstructor()
68+
->getMock();
69+
$this->resourceConnection->expects($this->any())
70+
->method('getConnection')
71+
->willReturn($this->connection);
72+
$this->connection->expects($this->any())
73+
->method('newTable')
74+
->willReturn($this->table);
75+
76+
$this->model = new IdsTableBuilder($this->resourceConnection);
77+
}
78+
79+
public function testBuildDoNotCreateMemoryTable() : void
80+
{
81+
$this->table->expects($this->never())
82+
->method('setOption')
83+
->with('type', 'memory');
84+
85+
$this->model->build($this->changeLog);
86+
}
87+
}

0 commit comments

Comments
 (0)