Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/MC-36652' into 2.4-develop-pr38
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-balko committed Aug 20, 2020
2 parents b3ad364 + 597d072 commit a89f35d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Reports\Model\ResourceModel\Quote\Item;

Expand All @@ -17,6 +18,8 @@
*/
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
private const PREPARED_FLAG_NAME = 'reports_collection_prepared';

/**
* Join fields
*
Expand Down Expand Up @@ -99,6 +102,11 @@ protected function _construct()
public function prepareActiveCartItems()
{
$quoteItemsSelect = $this->getSelect();

if ($this->getFlag(self::PREPARED_FLAG_NAME)) {
return $quoteItemsSelect;
}

$quoteItemsSelect->reset()
->from(['main_table' => $this->getTable('quote_item')], '')
->columns('main_table.product_id')
Expand All @@ -114,6 +122,7 @@ public function prepareActiveCartItems()
)->group(
'main_table.product_id'
);
$this->setFlag(self::PREPARED_FLAG_NAME, true);

return $quoteItemsSelect;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Quote\Model\ResourceModel\Quote;
use Magento\Reports\Model\ResourceModel\Quote\Collection;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -42,7 +43,7 @@ protected function setUp(): void
public function testGetSelectCountSql()
{
/** @var MockObject $collection */
$collection = $this->getMockBuilder(\Magento\Reports\Model\ResourceModel\Quote\Collection::class)
$collection = $this->getMockBuilder(Collection::class)
->setMethods(['getSelect'])
->disableOriginalConstructor()
->getMock();
Expand All @@ -62,20 +63,25 @@ public function testPrepareActiveCartItems()
$constructArgs = $this->objectManager
->getConstructArguments(\Magento\Reports\Model\ResourceModel\Quote\Item\Collection::class);
$collection = $this->getMockBuilder(\Magento\Reports\Model\ResourceModel\Quote\Item\Collection::class)
->setMethods(['getSelect', 'getTable'])
->setMethods(['getSelect', 'getTable', 'getFlag', 'setFlag'])
->disableOriginalConstructor()
->setConstructorArgs($constructArgs)
->getMock();

$collection->expects($this->once())->method('getSelect')->willReturn($this->selectMock);
$collection->expects($this->exactly(2))->method('getSelect')->willReturn($this->selectMock);
$this->selectMock->expects($this->once())->method('reset')->willReturnSelf();
$this->selectMock->expects($this->once())->method('from')->willReturnSelf();
$this->selectMock->expects($this->atLeastOnce())->method('columns')->willReturnSelf();
$this->selectMock->expects($this->once())->method('joinInner')->willReturnSelf();
$this->selectMock->expects($this->once())->method('where')->willReturnSelf();
$this->selectMock->expects($this->once())->method('group')->willReturnSelf();
$collection->expects($this->exactly(2))->method('getTable')->willReturn('table');
$collection->expects($this->once())->method('setFlag')
->with('reports_collection_prepared')->willReturnSelf();
$collection->prepareActiveCartItems();
$collection->method('getFlag')
->with('reports_collection_prepared')->willReturn(true);
$this->assertEquals($this->selectMock, $collection->prepareActiveCartItems());
}

public function testLoadWithFilter()
Expand Down

0 comments on commit a89f35d

Please sign in to comment.