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