Skip to content
Snippets Groups Projects
Commit 9dbffdb7 authored by Yuxing Zheng's avatar Yuxing Zheng
Browse files

MAGETWO-36378: Magento\Quote\Api\GuestCartManagement

 - Remove \Magento\Quote\Model\GuestCart\GuestCartManagement::getCartForCustomer
 - Remove $quoteRepository from the parameters of GuestCartManagement::__construct
 - Update unit test accordingly
parent 300d8db0
No related merge requests found
......@@ -10,8 +10,6 @@ use Magento\Quote\Api\GuestCartManagementInterface;
use Magento\Quote\Api\CartManagementInterface;
use Magento\Quote\Model\QuoteIdMask;
use Magento\Quote\Model\QuoteIdMaskFactory;
use Magento\Quote\Model\QuoteManagement;
use Magento\Quote\Model\QuoteRepository;
/**
* Cart Management class for guest carts.
......@@ -25,11 +23,6 @@ class GuestCartManagement implements GuestCartManagementInterface
*/
protected $quoteManagement;
/**
* @var QuoteRepository
*/
protected $quoteRepository;
/**
* @var QuoteIdMaskFactory
*/
......@@ -39,17 +32,14 @@ class GuestCartManagement implements GuestCartManagementInterface
* Initialize dependencies.
*
* @param CartManagementInterface $quoteManagement
* @param QuoteRepository $quoteRepository
* @param QuoteIdMaskFactory $quoteIdMaskFactory
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
CartManagementInterface $quoteManagement,
QuoteRepository $quoteRepository,
QuoteIdMaskFactory $quoteIdMaskFactory
) {
$this->quoteManagement = $quoteManagement;
$this->quoteRepository = $quoteRepository;
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
}
......@@ -84,16 +74,4 @@ class GuestCartManagement implements GuestCartManagementInterface
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
return $this->quoteManagement->placeOrder($quoteIdMask->getId());
}
/**
* {@inheritdoc}
*/
public function getCartForCustomer($customerId)
{
$cart = $this->quoteRepository->getActiveForCustomer($customerId);
/** @var $quoteIdMask QuoteIdMask */
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cart->getId(), 'masked_id');
$cart->setId($quoteIdMask->getId());
return $cart;
}
}
......@@ -47,7 +47,6 @@ class GuestCartManagementTest extends \PHPUnit_Framework_TestCase
true,
[]
);
$this->quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false);
$this->quoteIdMaskFactoryMock = $this->getMock(
'Magento\Quote\Model\QuoteIdMaskFactory',
['create'],
......@@ -67,7 +66,6 @@ class GuestCartManagementTest extends \PHPUnit_Framework_TestCase
'Magento\Quote\Model\GuestCart\GuestCartManagement',
[
'quoteManagement' => $this->quoteManagementMock,
'quoteRepository' => $this->quoteRepositoryMock,
'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock
]
);
......@@ -115,18 +113,4 @@ class GuestCartManagementTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($orderId, $this->guestCartManagement->placeOrder($cartId));
}
public function testGetCartForCustomer()
{
$maskedCartId = 'masked1cart2id3';
$cartId = 1;
$orderId = 1;
$this->quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf();
$this->quoteIdMaskMock->expects($this->once())->method('getId')->willReturn($maskedCartId);
$this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock);
$this->quoteManagementMock->expects($this->once())->method('placeOrder')->willReturn($orderId);
$this->assertEquals($orderId, $this->guestCartManagement->placeOrder($cartId));
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment