Skip to content

Commit 70282e6

Browse files
committed
MAGETWO-36381: Magento\Quote\Api\GuestShippingAddressManagement
- replaced inheritance with composition
1 parent ce1f336 commit 70282e6

File tree

2 files changed

+48
-86
lines changed

2 files changed

+48
-86
lines changed

app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,36 @@
66
namespace Magento\Quote\Model\GuestCart;
77

88
use Magento\Quote\Api\GuestShippingAddressManagementInterface;
9-
use Magento\Quote\Model\QuoteAddressValidator;
109
use Magento\Quote\Model\QuoteIdMask;
1110
use Magento\Quote\Model\QuoteIdMaskFactory;
12-
use Magento\Quote\Model\QuoteRepository;
1311
use Magento\Quote\Model\ShippingAddressManagement;
14-
use Psr\Log\LoggerInterface as Logger;
1512

1613
/**
1714
* Shipping address management class for guest carts.
1815
*/
19-
class GuestShippingAddressManagement extends ShippingAddressManagement implements
20-
GuestShippingAddressManagementInterface
16+
class GuestShippingAddressManagement implements GuestShippingAddressManagementInterface
2117
{
2218
/**
2319
* @var QuoteIdMaskFactory
2420
*/
2521
protected $quoteIdMaskFactory;
2622

23+
/**
24+
* @var ShippingAddressManagement
25+
*/
26+
protected $shippingAddressManagement;
27+
2728
/**
2829
* Constructs a quote shipping address write service object.
2930
*
30-
* @param QuoteRepository $quoteRepository
31-
* @param QuoteAddressValidator $addressValidator
32-
* @param Logger $logger
31+
* @param ShippingAddressManagement $shippingAddressManagement
3332
* @param QuoteIdMaskFactory $quoteIdMaskFactory
3433
*/
3534
public function __construct(
36-
\Magento\Quote\Model\QuoteRepository $quoteRepository,
37-
QuoteAddressValidator $addressValidator,
38-
Logger $logger,
35+
ShippingAddressManagement $shippingAddressManagement,
3936
QuoteIdMaskFactory $quoteIdMaskFactory
4037
) {
41-
$this->quoteRepository = $quoteRepository;
42-
$this->addressValidator = $addressValidator;
43-
$this->logger = $logger;
38+
$this->shippingAddressManagement = $shippingAddressManagement;
4439
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
4540
}
4641

@@ -51,7 +46,7 @@ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $addres
5146
{
5247
/** @var $quoteIdMask QuoteIdMask */
5348
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
54-
return parent::assign($quoteIdMask->getId(), $address);
49+
return $this->shippingAddressManagement->assign($quoteIdMask->getId(), $address);
5550
}
5651

5752
/**
@@ -61,6 +56,6 @@ public function get($cartId)
6156
{
6257
/** @var $quoteIdMask QuoteIdMask */
6358
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
64-
return parent::get($quoteIdMask->getId());
59+
return $this->shippingAddressManagement->get($quoteIdMask->getId());
6560
}
6661
}

app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php

Lines changed: 37 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -17,109 +17,76 @@ class GuestShippingAddressManagementTest extends \PHPUnit_Framework_TestCase
1717
/**
1818
* @var \PHPUnit_Framework_MockObject_MockObject
1919
*/
20-
protected $quoteRepositoryMock;
20+
protected $quoteAddressMock;
2121

2222
/**
2323
* @var \PHPUnit_Framework_MockObject_MockObject
2424
*/
25-
protected $quoteAddressMock;
25+
protected $quoteIdMaskFactoryMock;
2626

2727
/**
2828
* @var \PHPUnit_Framework_MockObject_MockObject
2929
*/
30-
protected $validatorMock;
30+
protected $quoteIdMaskMock;
3131

3232
/**
3333
* @var \PHPUnit_Framework_MockObject_MockObject
3434
*/
35-
protected $quoteIdMaskFactoryMock;
35+
protected $shippingAddressManagementMock;
3636

3737
/**
38-
* @var \PHPUnit_Framework_MockObject_MockObject
38+
* @var string
3939
*/
40-
protected $quoteIdMaskMock;
40+
protected $maskedCartId;
41+
42+
/**
43+
* @var int
44+
*/
45+
protected $cartId;
4146

4247
protected function setUp()
4348
{
4449
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
4550

46-
$this->quoteRepositoryMock = $this->getMock('\Magento\Quote\Model\QuoteRepository', [], [], '', false);
47-
$this->quoteAddressMock = $this->getMock( '\Magento\Quote\Model\Quote\Address', [], [], '', false);
48-
$this->validatorMock = $this->getMock( 'Magento\Quote\Model\QuoteAddressValidator', [], [], '', false);
49-
$this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false);
50-
$this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false);
51+
$this->shippingAddressManagementMock = $this->getMock(
52+
'Magento\Quote\Model\ShippingAddressManagement',
53+
[],
54+
[],
55+
'',
56+
false
57+
);
58+
$this->quoteAddressMock = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false);
59+
60+
$this->maskedCartId = 'f216207248d65c789b17be8545e0aa73';
61+
$this->cartId = 123;
62+
63+
$guestCartTestHelper = new GuestCartTestHelper($this);
64+
list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask(
65+
$this->maskedCartId,
66+
$this->cartId
67+
);
68+
5169
$this->model = $objectManager->getObject(
5270
'Magento\Quote\Model\GuestCart\GuestShippingAddressManagement',
5371
[
54-
'quoteRepository' => $this->quoteRepositoryMock,
55-
'addressValidator' => $this->validatorMock,
56-
'logger' => $this->getMock('\Psr\Log\LoggerInterface'),
72+
'shippingAddressManagement' => $this->shippingAddressManagementMock,
5773
'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock
5874
]
5975
);
6076
}
6177

62-
public function testAssignAddress()
78+
public function testAssign()
6379
{
64-
$maskedCartId = 'f216207248d65c789b17be8545e0aa73';
65-
$cartId = 867;
66-
67-
$this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock);
68-
$this->quoteIdMaskMock->expects($this->once())
69-
->method('load')
70-
->with($maskedCartId, 'masked_id')
71-
->willReturn($this->quoteIdMaskMock);
72-
$this->quoteIdMaskMock->expects($this->once())
73-
->method('getId')
74-
->willReturn($cartId);
75-
76-
$quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false);
77-
$this->quoteRepositoryMock->expects($this->once())
78-
->method('getActive')
79-
->with($cartId)
80-
->will($this->returnValue($quoteMock));
81-
$quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false));
82-
83-
84-
$this->validatorMock->expects($this->once())->method('validate')
85-
->with($this->quoteAddressMock)
86-
->will($this->returnValue(true));
87-
88-
$quoteMock->expects($this->once())->method('setShippingAddress')->with($this->quoteAddressMock);
89-
$quoteMock->expects($this->once())->method('setDataChanges')->with(true);
90-
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock);
91-
9280
$addressId = 1;
93-
$shippingAddressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false);
94-
$shippingAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId));
95-
$quoteMock->expects($this->once())->method('getShippingAddress')
96-
->will($this->returnValue($shippingAddressMock));
97-
98-
$this->assertEquals($addressId, $this->model->assign($maskedCartId, $this->quoteAddressMock));
81+
$this->shippingAddressManagementMock->expects($this->once())->method('assign')->willReturn($addressId);
82+
$this->assertEquals($addressId, $this->model->assign($this->maskedCartId, $this->quoteAddressMock));
9983
}
10084

101-
public function testGetAddress()
85+
public function testGet()
10286
{
103-
$maskedCartId = 'f216207248d65c789b17be8545e0aa73';
104-
$cartId = 867;
105-
106-
$this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock);
107-
$this->quoteIdMaskMock->expects($this->once())
108-
->method('load')
109-
->with($maskedCartId, 'masked_id')
110-
->willReturn($this->quoteIdMaskMock);
111-
$this->quoteIdMaskMock->expects($this->once())
112-
->method('getId')
113-
->willReturn($cartId);
114-
115-
$quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false);
116-
$this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->will(
117-
$this->returnValue($quoteMock)
87+
$this->shippingAddressManagementMock->expects($this->once())->method('get')->willReturn(
88+
$this->quoteAddressMock
11889
);
119-
120-
$addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false);
121-
$quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($addressMock));
122-
$quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue(false));
123-
$this->assertEquals($addressMock, $this->model->get($maskedCartId));
90+
$this->assertEquals($this->quoteAddressMock, $this->model->get($this->maskedCartId));
12491
}
12592
}

0 commit comments

Comments
 (0)