|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Magento\Reports\Test\Unit\Model\ResourceModel\Product\Sold\Collection; |
| 4 | + |
| 5 | +use Magento\Framework\DB\Select; |
| 6 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 7 | +use Magento\Reports\Model\ResourceModel\Product\Sold\Collection; |
| 8 | + |
| 9 | +/** |
| 10 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 11 | + */ |
| 12 | +class CollectionTest extends \PHPUnit_Framework_TestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var ObjectManager |
| 16 | + */ |
| 17 | + protected $objectManager; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 21 | + */ |
| 22 | + protected $selectMock; |
| 23 | + |
| 24 | + protected function setUp() |
| 25 | + { |
| 26 | + $this->objectManager = new ObjectManager($this); |
| 27 | + $this->selectMock = $this->getMock(Select::class, [], [], '', false); |
| 28 | + } |
| 29 | + |
| 30 | + public function testGetSelectCountSql() |
| 31 | + { |
| 32 | + /** @var $collection \PHPUnit_Framework_MockObject_MockObject */ |
| 33 | + $constructArgs = $this->objectManager->getConstructArguments(Collection::class); |
| 34 | + $collection = $this->getMock(Collection::class, ['getSelect'], $constructArgs, '', false); |
| 35 | + |
| 36 | + $collection->expects($this->atLeastOnce())->method('getSelect')->willReturn($this->selectMock); |
| 37 | + |
| 38 | + $this->selectMock->expects($this->atLeastOnce())->method('reset')->willReturnSelf(); |
| 39 | + $this->selectMock->expects($this->exactly(2))->method('columns')->willReturnSelf(); |
| 40 | + |
| 41 | + $this->selectMock->expects($this->at(6))->method('columns')->with('COUNT(DISTINCT main_table.entity_id)'); |
| 42 | + |
| 43 | + $this->selectMock->expects($this->at(7))->method('reset')->with(Select::COLUMNS); |
| 44 | + $this->selectMock->expects($this->at(8))->method('columns')->with('COUNT(DISTINCT order_items.item_id)'); |
| 45 | + |
| 46 | + $this->assertEquals($this->selectMock, $collection->getSelectCountSql()); |
| 47 | + } |
| 48 | +} |
0 commit comments