|
12 | 12 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverFactory;
|
13 | 13 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierInterface;
|
14 | 14 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverInterface;
|
15 |
| -use Magento\CatalogSearch\Test\Unit\Model\ResourceModel\BaseCollection; |
16 | 15 | use PHPUnit\Framework\MockObject\MockObject;
|
| 16 | +use PHPUnit\Framework\TestCase; |
17 | 17 |
|
18 | 18 | /**
|
19 | 19 | * Test class for Fulltext Collection
|
20 | 20 | *
|
21 | 21 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
22 | 22 | */
|
23 |
| -class CollectionTest extends BaseCollection |
| 23 | +class CollectionTest extends TestCase |
24 | 24 | {
|
25 | 25 | /**
|
26 | 26 | * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
|
@@ -75,9 +75,8 @@ class CollectionTest extends BaseCollection
|
75 | 75 | /**
|
76 | 76 | * @inheritdoc
|
77 | 77 | */
|
78 |
| - protected function setUp() |
| 78 | + protected function setUp(): void |
79 | 79 | {
|
80 |
| - $this->markTestSkipped("MC-18332: Mysql Search Engine is deprecated and will be removed"); |
81 | 80 | $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
|
82 | 81 | $this->storeManager = $this->getStoreManager();
|
83 | 82 | $this->universalFactory = $this->getUniversalFactory();
|
@@ -148,7 +147,7 @@ protected function setUp()
|
148 | 147 | /**
|
149 | 148 | * @inheritdoc
|
150 | 149 | */
|
151 |
| - protected function tearDown() |
| 150 | + protected function tearDown(): void |
152 | 151 | {
|
153 | 152 | $reflectionProperty = new \ReflectionProperty(\Magento\Framework\App\ObjectManager::class, '_instance');
|
154 | 153 | $reflectionProperty->setAccessible(true);
|
@@ -277,4 +276,74 @@ protected function createFilter()
|
277 | 276 |
|
278 | 277 | return $filter;
|
279 | 278 | }
|
| 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 | + } |
280 | 349 | }
|
0 commit comments