Skip to content

Commit 499dc26

Browse files
committed
ACP2E-3389: Adobe Commerce backend loads categories very slowly
1 parent 0faaa16 commit 499dc26

File tree

1 file changed

+217
-0
lines changed

1 file changed

+217
-0
lines changed
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Model\ResourceModel\Category;
9+
10+
use Magento\Framework\Data\Collection\EntityFactory;
11+
use Psr\Log\LoggerInterface;
12+
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
13+
use Magento\Framework\Event\ManagerInterface;
14+
use Magento\Eav\Model\Config;
15+
use Magento\Framework\App\ResourceConnection;
16+
use Magento\Eav\Model\EntityFactory as EavEntityFactory;
17+
use Magento\Eav\Model\ResourceModel\Helper;
18+
use Magento\Framework\Validator\UniversalFactory;
19+
use Magento\Store\Model\StoreManagerInterface;
20+
use Magento\Store\Api\Data\StoreInterface;
21+
use Magento\Framework\DB\Adapter\AdapterInterface;
22+
use Magento\Framework\DB\Select;
23+
use Magento\Framework\App\Config\ScopeConfigInterface;
24+
use Magento\Catalog\Model\Product\Visibility;
25+
use Magento\Catalog\Model\ResourceModel\Category\Collection;
26+
use Magento\Catalog\Model\ResourceModel\Category as CategoryEntity;
27+
use PHPUnit\Framework\MockObject\MockObject;
28+
use PHPUnit\Framework\TestCase;
29+
30+
class CollectionTest extends TestCase
31+
{
32+
33+
/**
34+
* @var Collection
35+
*/
36+
private $collection;
37+
38+
/**
39+
* @var EntityFactory|MockObject
40+
*/
41+
private $entityFactory;
42+
43+
/**
44+
* @var LoggerInterface|MockObject
45+
*/
46+
private $logger;
47+
48+
/**
49+
* @var FetchStrategyInterface|MockObject
50+
*/
51+
private $fetchStrategy;
52+
53+
/**
54+
* @var ManagerInterface|MockObject
55+
*/
56+
private $eventManager;
57+
58+
/**
59+
* @var Config|MockObject
60+
*/
61+
private $eavConfig;
62+
63+
/**
64+
* @var ResourceConnection|MockObject
65+
*/
66+
private $resource;
67+
68+
/**
69+
* @var EavEntityFactory|MockObject
70+
*/
71+
private $eavEntityFactory;
72+
73+
/**
74+
* @var Helper|MockObject
75+
*/
76+
private $resourceHelper;
77+
78+
/**
79+
* @var UniversalFactory|MockObject
80+
*/
81+
private $universalFactory;
82+
83+
/**
84+
* @var StoreManagerInterface|MockObject
85+
*/
86+
private $storeManager;
87+
88+
/**
89+
* @var AdapterInterface|MockObject
90+
*/
91+
private $connection;
92+
93+
/**
94+
* @var ScopeConfigInterface|MockObject
95+
*/
96+
private $scopeConfig;
97+
98+
/**
99+
* @var Visibility|MockObject
100+
*/
101+
private $catalogProductVisibility;
102+
103+
/**
104+
* @var CategoryEntity|MockObject
105+
*/
106+
private $categoryEntity;
107+
108+
/**
109+
* @var Select|MockObject
110+
*/
111+
private $select;
112+
113+
/**
114+
* @var StoreInterface|MockObject
115+
*/
116+
private $store;
117+
118+
/**
119+
* {@inheritdoc}
120+
*/
121+
public function setUp(): void
122+
{
123+
$this->entityFactory = $this->getMockBuilder(EntityFactory::class)
124+
->disableOriginalConstructor(true)
125+
->getMock();
126+
$this->logger = $this->getMockBuilder(LoggerInterface::class)
127+
->getMock();
128+
$this->fetchStrategy = $this->getMockBuilder(FetchStrategyInterface::class)
129+
->getMock();
130+
$this->eventManager = $this->getMockBuilder(ManagerInterface::class)
131+
->getMock();
132+
$this->eavConfig = $this->getMockBuilder(Config::class)
133+
->disableOriginalConstructor(true)
134+
->getMock();
135+
$this->resource = $this->getMockBuilder(ResourceConnection::class)
136+
->disableOriginalConstructor(true)
137+
->getMock();
138+
$this->eavEntityFactory = $this->getMockBuilder(EavEntityFactory::class)
139+
->disableOriginalConstructor(true)
140+
->getMock();
141+
$this->resourceHelper = $this->getMockBuilder(Helper::class)
142+
->disableOriginalConstructor(true)
143+
->getMock();
144+
$this->universalFactory = $this->getMockBuilder(UniversalFactory::class)
145+
->disableOriginalConstructor(true)
146+
->getMock();
147+
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
148+
->getMock();
149+
$this->connection = $this->getMockBuilder(AdapterInterface::class)
150+
->getMock();
151+
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
152+
->getMock();
153+
$this->catalogProductVisibility = $this->getMockBuilder(Visibility::class)
154+
->disableOriginalConstructor(true)
155+
->getMock();
156+
157+
$this->categoryEntity = $this->getMockBuilder(CategoryEntity::class)
158+
->disableOriginalConstructor()
159+
->getMock();
160+
$this->universalFactory->expects($this->any())
161+
->method('create')
162+
->willReturn($this->categoryEntity);
163+
$this->categoryEntity->expects($this->any())
164+
->method('getConnection')
165+
->willReturn($this->connection);
166+
$this->categoryEntity->expects($this->any())
167+
->method('getDefaultAttributes')
168+
->willReturn([]);
169+
170+
$this->select = $this->getMockBuilder(Select::class)
171+
->disableOriginalConstructor()
172+
->getMock();
173+
$this->connection->expects($this->any())
174+
->method('select')
175+
->willReturn($this->select);
176+
177+
$this->store = $this->getMockBuilder(StoreInterface::class)
178+
->getMock();
179+
$this->storeManager->expects($this->any())
180+
->method('getStore')
181+
->willReturn($this->store);
182+
183+
$this->collection = new Collection(
184+
$this->entityFactory,
185+
$this->logger,
186+
$this->fetchStrategy,
187+
$this->eventManager,
188+
$this->eavConfig,
189+
$this->resource,
190+
$this->eavEntityFactory,
191+
$this->resourceHelper,
192+
$this->universalFactory,
193+
$this->storeManager,
194+
$this->connection,
195+
$this->scopeConfig,
196+
$this->catalogProductVisibility
197+
);
198+
}
199+
200+
public function testLoadProductCount() : void
201+
{
202+
$this->select->expects($this->exactly(3))
203+
->method('from')
204+
->willReturnSelf();
205+
$this->select->expects($this->exactly(3))
206+
->method('where')
207+
->willReturnSelf();
208+
$this->select->expects($this->exactly(1))
209+
->method('group')
210+
->willReturnSelf();
211+
$this->connection->expects($this->exactly(2))
212+
->method('fetchPairs')
213+
->with($this->select)
214+
->willReturn([]);
215+
$this->collection->loadProductCount([]);
216+
}
217+
}

0 commit comments

Comments
 (0)