Skip to content

Commit bf3965c

Browse files
committed
MC-18332: Remove MySQL Search Engine
- fix tests - fix constructors
1 parent a599a77 commit bf3965c

File tree

4 files changed

+88
-68
lines changed

4 files changed

+88
-68
lines changed

app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced/Collection.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierFactory;
2828
use Magento\Framework\App\ObjectManager;
2929
use Magento\Framework\Api\Search\SearchResultInterface;
30-
use Magento\Search\Model\EngineResolver;
3130

3231
/**
3332
* Advanced search collection
@@ -41,11 +40,6 @@
4140
*/
4241
class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
4342
{
44-
/**
45-
* Config search engine path.
46-
*/
47-
private const SEARCH_ENGINE_VALUE_PATH = 'catalog/search/engine';
48-
4943
/**
5044
* List Of filters
5145
* @var array

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020
use Magento\CatalogSearch\Model\Search\RequestGenerator;
2121
use Magento\Framework\EntityManager\MetadataPool;
2222
use Magento\Framework\Exception\StateException;
23-
use Magento\Framework\Search\Response\QueryResponse;
2423
use Magento\Framework\Search\Request\EmptyRequestDataException;
2524
use Magento\Framework\Search\Request\NonExistingRequestNameException;
2625
use Magento\Framework\Api\Search\SearchResultFactory;
2726
use Magento\Framework\Exception\LocalizedException;
2827
use Magento\Framework\App\ObjectManager;
2928
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
30-
use Magento\Search\Model\EngineResolver;
3129

3230
/**
3331
* Fulltext Collection
@@ -42,37 +40,6 @@
4240
*/
4341
class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
4442
{
45-
/**
46-
* Config search engine path.
47-
*/
48-
private const SEARCH_ENGINE_VALUE_PATH = 'catalog/search/engine';
49-
50-
/**
51-
* @var QueryResponse
52-
* @deprecated 100.1.0
53-
*/
54-
protected $queryResponse;
55-
56-
/**
57-
* Catalog search data
58-
*
59-
* @var \Magento\Search\Model\QueryFactory
60-
* @deprecated 100.1.0
61-
*/
62-
protected $queryFactory = null;
63-
64-
/**
65-
* @var \Magento\Framework\Search\Request\Builder
66-
* @deprecated 100.1.0
67-
*/
68-
private $requestBuilder;
69-
70-
/**
71-
* @var \Magento\Search\Model\SearchEngine
72-
* @deprecated 100.1.0
73-
*/
74-
private $searchEngine;
75-
7643
/**
7744
* @var string
7845
*/
@@ -134,8 +101,6 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
134101
private $defaultFilterStrategyApplyChecker;
135102

136103
/**
137-
* Collection constructor
138-
*
139104
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
140105
* @param \Psr\Log\LoggerInterface $logger
141106
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
@@ -155,9 +120,6 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
155120
* @param \Magento\Customer\Model\Session $customerSession
156121
* @param \Magento\Framework\Stdlib\DateTime $dateTime
157122
* @param \Magento\Customer\Api\GroupManagementInterface $groupManagement
158-
* @param \Magento\Search\Model\QueryFactory $catalogSearchData
159-
* @param \Magento\Framework\Search\Request\Builder $requestBuilder
160-
* @param \Magento\Search\Model\SearchEngine $searchEngine
161123
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
162124
* @param string $searchRequestName
163125
* @param SearchResultFactory|null $searchResultFactory
@@ -193,9 +155,6 @@ public function __construct(
193155
\Magento\Customer\Model\Session $customerSession,
194156
\Magento\Framework\Stdlib\DateTime $dateTime,
195157
\Magento\Customer\Api\GroupManagementInterface $groupManagement,
196-
\Magento\Search\Model\QueryFactory $catalogSearchData,
197-
\Magento\Framework\Search\Request\Builder $requestBuilder,
198-
\Magento\Search\Model\SearchEngine $searchEngine,
199158
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
200159
$searchRequestName = 'catalog_view_container',
201160
SearchResultFactory $searchResultFactory = null,
@@ -209,7 +168,6 @@ public function __construct(
209168
TotalRecordsResolverFactory $totalRecordsResolverFactory = null,
210169
DefaultFilterStrategyApplyCheckerInterface $defaultFilterStrategyApplyChecker = null
211170
) {
212-
$this->queryFactory = $catalogSearchData;
213171
$this->searchResultFactory = $searchResultFactory ?? \Magento\Framework\App\ObjectManager::getInstance()
214172
->get(\Magento\Framework\Api\Search\SearchResultFactory::class);
215173
parent::__construct(
@@ -236,8 +194,6 @@ public function __construct(
236194
$productLimitationFactory,
237195
$metadataPool
238196
);
239-
$this->requestBuilder = $requestBuilder;
240-
$this->searchEngine = $searchEngine;
241197
$this->searchRequestName = $searchRequestName;
242198
$this->search = $search ?: ObjectManager::getInstance()->get(\Magento\Search\Api\SearchInterface::class);
243199
$this->searchCriteriaBuilder = $searchCriteriaBuilder ?: ObjectManager::getInstance()

app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Advanced/CollectionTest.php

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@
1818
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierInterface;
1919
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverFactory;
2020
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverInterface;
21-
use Magento\CatalogSearch\Test\Unit\Model\ResourceModel\BaseCollection;
2221
use Magento\Eav\Model\Config;
22+
use Magento\Eav\Model\Entity\AbstractEntity;
2323
use Magento\Framework\Api\Filter;
2424
use Magento\Framework\Api\FilterBuilder;
2525
use Magento\Framework\Api\Search\SearchCriteriaBuilder;
2626
use Magento\Framework\Api\Search\SearchResultInterface;
27-
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory;
27+
use Magento\Framework\DB\Adapter\Pdo\Mysql;
28+
use Magento\Framework\DB\Select;
2829
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
30+
use Magento\Framework\Validator\UniversalFactory;
2931
use Magento\Search\Api\SearchInterface;
32+
use Magento\Store\Model\Store;
33+
use Magento\Store\Model\StoreManagerInterface;
3034
use PHPUnit\Framework\MockObject\MockObject;
35+
use PHPUnit\Framework\TestCase;
3136

3237
/**
3338
* Tests Magento\CatalogSearch\Model\ResourceModel\Advanced\Collection
@@ -36,7 +41,7 @@
3641
* @deprecated Implementation class was replaced
3742
* @see \Magento\ElasticSearch
3843
*/
39-
class CollectionTest extends BaseCollection
44+
class CollectionTest extends TestCase
4045
{
4146
/**
4247
* @var ObjectManager
@@ -58,11 +63,6 @@ class CollectionTest extends BaseCollection
5863
*/
5964
private $criteriaBuilder;
6065

61-
/**
62-
* @var TemporaryStorageFactory|MockObject
63-
*/
64-
private $temporaryStorageFactory;
65-
6666
/**
6767
* @var SearchInterface|MockObject
6868
*/
@@ -89,9 +89,6 @@ protected function setUp(): void
8989
$universalFactory = $this->getUniversalFactory();
9090
$this->criteriaBuilder = $this->getCriteriaBuilder();
9191
$this->filterBuilder = $this->createMock(FilterBuilder::class);
92-
$this->temporaryStorageFactory = $this->createMock(
93-
TemporaryStorageFactory::class
94-
);
9592
$this->search = $this->getMockForAbstractClass(SearchInterface::class);
9693

9794
$productLimitationMock = $this->createMock(
@@ -141,7 +138,6 @@ protected function setUp(): void
141138
'universalFactory' => $universalFactory,
142139
'searchCriteriaBuilder' => $this->criteriaBuilder,
143140
'filterBuilder' => $this->filterBuilder,
144-
'temporaryStorageFactory' => $this->temporaryStorageFactory,
145141
'search' => $this->search,
146142
'productLimitationFactory' => $productLimitationFactoryMock,
147143
'collectionProvider' => null,
@@ -221,4 +217,74 @@ protected function getCriteriaBuilder()
221217

222218
return $criteriaBuilder;
223219
}
220+
221+
/**
222+
* Get Mocks for StoreManager so Collection can be used.
223+
*
224+
* @return MockObject
225+
*/
226+
protected function getStoreManager()
227+
{
228+
$store = $this->getMockBuilder(Store::class)
229+
->setMethods(['getId'])
230+
->disableOriginalConstructor()
231+
->getMock();
232+
$store->expects($this->once())
233+
->method('getId')
234+
->willReturn(1);
235+
236+
$storeManager = $this->getMockBuilder(StoreManagerInterface::class)
237+
->setMethods(['getStore'])
238+
->disableOriginalConstructor()
239+
->getMockForAbstractClass();
240+
$storeManager->expects($this->once())
241+
->method('getStore')
242+
->willReturn($store);
243+
244+
return $storeManager;
245+
}
246+
247+
/**
248+
* Get mock for UniversalFactory so Collection can be used.
249+
*
250+
* @return MockObject
251+
*/
252+
protected function getUniversalFactory()
253+
{
254+
$connection = $this->getMockBuilder(Mysql::class)
255+
->disableOriginalConstructor()
256+
->setMethods(['select'])
257+
->getMockForAbstractClass();
258+
$select = $this->getMockBuilder(Select::class)
259+
->disableOriginalConstructor()
260+
->getMock();
261+
$connection->expects($this->any())->method('select')->willReturn($select);
262+
263+
$entity = $this->getMockBuilder(AbstractEntity::class)
264+
->setMethods(['getConnection', 'getTable', 'getDefaultAttributes', 'getEntityTable'])
265+
->disableOriginalConstructor()
266+
->getMock();
267+
$entity->expects($this->once())
268+
->method('getConnection')
269+
->willReturn($connection);
270+
$entity->expects($this->exactly(2))
271+
->method('getTable')
272+
->willReturnArgument(0);
273+
$entity->expects($this->once())
274+
->method('getDefaultAttributes')
275+
->willReturn(['attr1', 'attr2']);
276+
$entity->expects($this->once())
277+
->method('getEntityTable')
278+
->willReturn('table');
279+
280+
$universalFactory = $this->getMockBuilder(UniversalFactory::class)
281+
->setMethods(['create'])
282+
->disableOriginalConstructor()
283+
->getMock();
284+
$universalFactory->expects($this->once())
285+
->method('create')
286+
->willReturn($entity);
287+
288+
return $universalFactory;
289+
}
224290
}

lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Aggregation/AggregationResolverTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Framework\Search\Test\Unit\Adapter\Aggregation;
79

810
use Magento\Framework\Search\Adapter\Aggregation\AggregationResolver;
911
use Magento\Framework\Search\Adapter\Aggregation\AggregationResolverInterface;
1012
use Magento\Framework\Search\RequestInterface;
1113
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
1216

13-
class AggregationResolverTest extends \PHPUnit\Framework\TestCase
17+
class AggregationResolverTest extends TestCase
1418
{
1519
/**
16-
* @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
20+
* @var RequestInterface|MockObject
1721
*/
1822
private $request;
1923

2024
/**
21-
* @var AggregationResolverInterface|\PHPUnit_Framework_MockObject_MockObject
25+
* @var AggregationResolverInterface|MockObject
2226
*/
2327
private $specificAggregationResolver;
2428

@@ -27,10 +31,10 @@ class AggregationResolverTest extends \PHPUnit\Framework\TestCase
2731
*/
2832
private $aggregationResolver;
2933

30-
protected function setUp()
34+
protected function setUp(): void
3135
{
32-
$this->request = $this->createMock(RequestInterface::class);
33-
$this->specificAggregationResolver = $this->createMock(AggregationResolverInterface::class);
36+
$this->request = $this->getMockForAbstractClass(RequestInterface::class);
37+
$this->specificAggregationResolver = $this->getMockForAbstractClass(AggregationResolverInterface::class);
3438

3539
$this->aggregationResolver = (new ObjectManager($this))->getObject(
3640
AggregationResolver::class,

0 commit comments

Comments
 (0)