Skip to content

Commit 4a66aac

Browse files
committed
MC-18332: Remove MySQL Search Engine
- fixing unit test
1 parent 1c0887e commit 4a66aac

File tree

1 file changed

+74
-5
lines changed

1 file changed

+74
-5
lines changed

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

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverFactory;
1313
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierInterface;
1414
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverInterface;
15-
use Magento\CatalogSearch\Test\Unit\Model\ResourceModel\BaseCollection;
1615
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
1717

1818
/**
1919
* Test class for Fulltext Collection
2020
*
2121
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2222
*/
23-
class CollectionTest extends BaseCollection
23+
class CollectionTest extends TestCase
2424
{
2525
/**
2626
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
@@ -75,9 +75,8 @@ class CollectionTest extends BaseCollection
7575
/**
7676
* @inheritdoc
7777
*/
78-
protected function setUp()
78+
protected function setUp(): void
7979
{
80-
$this->markTestSkipped("MC-18332: Mysql Search Engine is deprecated and will be removed");
8180
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
8281
$this->storeManager = $this->getStoreManager();
8382
$this->universalFactory = $this->getUniversalFactory();
@@ -148,7 +147,7 @@ protected function setUp()
148147
/**
149148
* @inheritdoc
150149
*/
151-
protected function tearDown()
150+
protected function tearDown(): void
152151
{
153152
$reflectionProperty = new \ReflectionProperty(\Magento\Framework\App\ObjectManager::class, '_instance');
154153
$reflectionProperty->setAccessible(true);
@@ -277,4 +276,74 @@ protected function createFilter()
277276

278277
return $filter;
279278
}
279+
280+
/**
281+
* Get Mocks for StoreManager so Collection can be used.
282+
*
283+
* @return \PHPUnit_Framework_MockObject_MockObject
284+
*/
285+
private function getStoreManager()
286+
{
287+
$store = $this->getMockBuilder(\Magento\Store\Model\Store::class)
288+
->setMethods(['getId'])
289+
->disableOriginalConstructor()
290+
->getMock();
291+
$store->expects($this->once())
292+
->method('getId')
293+
->willReturn(1);
294+
295+
$storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
296+
->setMethods(['getStore'])
297+
->disableOriginalConstructor()
298+
->getMockForAbstractClass();
299+
$storeManager->expects($this->once())
300+
->method('getStore')
301+
->willReturn($store);
302+
303+
return $storeManager;
304+
}
305+
306+
/**
307+
* Get mock for UniversalFactory so Collection can be used.
308+
*
309+
* @return \PHPUnit_Framework_MockObject_MockObject
310+
*/
311+
private function getUniversalFactory()
312+
{
313+
$connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class)
314+
->disableOriginalConstructor()
315+
->setMethods(['select'])
316+
->getMockForAbstractClass();
317+
$select = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
318+
->disableOriginalConstructor()
319+
->getMock();
320+
$connection->expects($this->any())->method('select')->willReturn($select);
321+
322+
$entity = $this->getMockBuilder(\Magento\Eav\Model\Entity\AbstractEntity::class)
323+
->setMethods(['getConnection', 'getTable', 'getDefaultAttributes', 'getEntityTable'])
324+
->disableOriginalConstructor()
325+
->getMock();
326+
$entity->expects($this->once())
327+
->method('getConnection')
328+
->willReturn($connection);
329+
$entity->expects($this->exactly(2))
330+
->method('getTable')
331+
->willReturnArgument(0);
332+
$entity->expects($this->once())
333+
->method('getDefaultAttributes')
334+
->willReturn(['attr1', 'attr2']);
335+
$entity->expects($this->once())
336+
->method('getEntityTable')
337+
->willReturn('table');
338+
339+
$universalFactory = $this->getMockBuilder(\Magento\Framework\Validator\UniversalFactory::class)
340+
->setMethods(['create'])
341+
->disableOriginalConstructor()
342+
->getMock();
343+
$universalFactory->expects($this->once())
344+
->method('create')
345+
->willReturn($entity);
346+
347+
return $universalFactory;
348+
}
280349
}

0 commit comments

Comments
 (0)