|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Customer\Test\Unit\Model\ResourceModel\Group\Grid; |
| 7 | + |
| 8 | +use Magento\Customer\Model\ResourceModel\Group\Grid\Collection; |
| 9 | +use Magento\Framework\Api\Search\AggregationInterface; |
| 10 | +use Magento\Framework\Data\Collection\Db\FetchStrategyInterface; |
| 11 | +use Magento\Framework\Data\Collection\EntityFactoryInterface; |
| 12 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 13 | +use Magento\Framework\Event\ManagerInterface; |
| 14 | +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; |
| 15 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 16 | +use Psr\Log\LoggerInterface; |
| 17 | +use Magento\Framework\DB\Select; |
| 18 | + |
| 19 | +/** |
| 20 | + * CollectionTest contains unit tests for \Magento\Customer\Model\ResourceModel\Group\Grid\Collection class |
| 21 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 22 | + */ |
| 23 | +class CollectionTest extends \PHPUnit\Framework\TestCase |
| 24 | +{ |
| 25 | + /** |
| 26 | + * @var EntityFactoryInterface|\PHPUnit_Framework_MockObject_MockObject |
| 27 | + */ |
| 28 | + protected $entityFactoryMock; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject |
| 32 | + */ |
| 33 | + protected $loggerMock; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var FetchStrategyInterface|\PHPUnit_Framework_MockObject_MockObject |
| 37 | + */ |
| 38 | + protected $fetchStrategyMock; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject |
| 42 | + */ |
| 43 | + protected $eventManagerMock; |
| 44 | + |
| 45 | + /** |
| 46 | + * @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject |
| 47 | + */ |
| 48 | + protected $connectionMock; |
| 49 | + |
| 50 | + /** |
| 51 | + * @var AbstractDb|\PHPUnit_Framework_MockObject_MockObject |
| 52 | + */ |
| 53 | + protected $resourceMock; |
| 54 | + |
| 55 | + /** |
| 56 | + * @var AggregationInterface|\PHPUnit_Framework_MockObject_MockObject |
| 57 | + */ |
| 58 | + protected $aggregationsMock; |
| 59 | + |
| 60 | + /** |
| 61 | + * @var Select |
| 62 | + */ |
| 63 | + protected $selectMock; |
| 64 | + |
| 65 | + /** |
| 66 | + * @var Collection |
| 67 | + */ |
| 68 | + protected $model; |
| 69 | + |
| 70 | + protected function setUp() |
| 71 | + { |
| 72 | + $this->entityFactoryMock = $this->getMockBuilder(EntityFactoryInterface::class) |
| 73 | + ->getMockForAbstractClass(); |
| 74 | + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) |
| 75 | + ->getMockForAbstractClass(); |
| 76 | + $this->fetchStrategyMock = $this->getMockBuilder(FetchStrategyInterface::class) |
| 77 | + ->getMockForAbstractClass(); |
| 78 | + $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class) |
| 79 | + ->getMockForAbstractClass(); |
| 80 | + $this->resourceMock = $this->getMockBuilder(AbstractDb::class) |
| 81 | + ->disableOriginalConstructor() |
| 82 | + ->getMock(); |
| 83 | + $this->aggregationsMock = $this->getMockBuilder(AggregationInterface::class) |
| 84 | + ->getMockForAbstractClass(); |
| 85 | + $this->connectionMock = $this->getMockBuilder(AdapterInterface::class) |
| 86 | + ->getMockForAbstractClass(); |
| 87 | + $this->selectMock = $this->getMockBuilder(Select::class) |
| 88 | + ->disableOriginalConstructor() |
| 89 | + ->getMock(); |
| 90 | + |
| 91 | + $this->resourceMock->expects($this->any()) |
| 92 | + ->method('getConnection') |
| 93 | + ->willReturn($this->connectionMock); |
| 94 | + $this->connectionMock->expects($this->once()) |
| 95 | + ->method('select') |
| 96 | + ->willReturn($this->selectMock); |
| 97 | + |
| 98 | + $this->model = (new ObjectManager($this))->getObject(Collection::class, [ |
| 99 | + 'entityFactory' => $this->entityFactoryMock, |
| 100 | + 'logger' => $this->loggerMock, |
| 101 | + 'fetchStrategy' => $this->fetchStrategyMock, |
| 102 | + 'eventManager' => $this->eventManagerMock, |
| 103 | + 'mainTable' => null, |
| 104 | + 'eventPrefix' => 'test_event_prefix', |
| 105 | + 'eventObject' => 'test_event_object', |
| 106 | + 'resourceModel' => null, |
| 107 | + 'resource' => $this->resourceMock, |
| 108 | + ]); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::setSearchCriteria |
| 113 | + * @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::getAggregations |
| 114 | + */ |
| 115 | + public function testSetGetAggregations() |
| 116 | + { |
| 117 | + $this->model->setAggregations($this->aggregationsMock); |
| 118 | + $this->assertInstanceOf(AggregationInterface::class, $this->model->getAggregations()); |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * @covers \Magento\Customer\Model\ResourceModel\Group\Grid\Collection::setSearchCriteria |
| 123 | + */ |
| 124 | + public function testSetSearchCriteria() |
| 125 | + { |
| 126 | + $this->assertEquals($this->model, $this->model->setSearchCriteria()); |
| 127 | + } |
| 128 | +} |
0 commit comments