Skip to content

Commit c30e6de

Browse files
committed
MAGETWO-36382: Magento\Quote\Api\GuestBillingAddressManagement
- replaced inheritance with composition
1 parent 70282e6 commit c30e6de

File tree

2 files changed

+32
-66
lines changed

2 files changed

+32
-66
lines changed

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,36 @@
88

99
use Magento\Quote\Api\GuestBillingAddressManagementInterface;
1010
use Magento\Quote\Model\BillingAddressManagement;
11-
use Magento\Quote\Model\QuoteAddressValidator;
1211
use Magento\Quote\Model\QuoteIdMask;
1312
use Magento\Quote\Model\QuoteIdMaskFactory;
14-
use Magento\Quote\Model\QuoteRepository;
15-
use Psr\Log\LoggerInterface as Logger;
1613

1714
/**
1815
* Billing address management service for guest carts.
1916
*/
20-
class GuestBillingAddressManagement extends BillingAddressManagement implements GuestBillingAddressManagementInterface
17+
class GuestBillingAddressManagement implements GuestBillingAddressManagementInterface
2118
{
2219
/**
2320
* @var QuoteIdMaskFactory
2421
*/
2522
private $quoteIdMaskFactory;
2623

24+
/**
25+
* @var BillingAddressManagement
26+
*/
27+
private $billingAddressManagement;
28+
2729
/**
2830
* Constructs a quote billing address service object.
2931
*
30-
* @param QuoteRepository $quoteRepository Quote repository.
31-
* @param QuoteAddressValidator $addressValidator Address validator.
32-
* @param Logger $logger Logger.
32+
* @param BillingAddressManagement $billingAddressManagement
3333
* @param QuoteIdMaskFactory $quoteIdMaskFactory
3434
*/
3535
public function __construct(
36-
QuoteRepository $quoteRepository,
37-
QuoteAddressValidator $addressValidator,
38-
Logger $logger,
36+
BillingAddressManagement $billingAddressManagement,
3937
QuoteIdMaskFactory $quoteIdMaskFactory
4038
) {
4139
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
42-
parent::__construct(
43-
$quoteRepository,
44-
$addressValidator,
45-
$logger
46-
);
40+
$this->billingAddressManagement = $billingAddressManagement;
4741
}
4842

4943
/**
@@ -53,8 +47,7 @@ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $addres
5347
{
5448
/** @var $quoteIdMask QuoteIdMask */
5549
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
56-
57-
return parent::assign($quoteIdMask->getId(), $address);
50+
return $this->billingAddressManagement->assign($quoteIdMask->getId(), $address);
5851
}
5952

6053
/**
@@ -64,7 +57,6 @@ public function get($cartId)
6457
{
6558
/** @var $quoteIdMask QuoteIdMask */
6659
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
67-
68-
return parent::get($quoteIdMask->getId());
60+
return $this->billingAddressManagement->get($quoteIdMask->getId());
6961
}
7062
}

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

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
*/
77
namespace Magento\Quote\Test\Unit\Model\GuestCart;
88

9-
use Magento\Quote\Test\Unit\Model\GuestCart\GuestCartTestHelper;
10-
119
class GuestBillingAddressManagementTest extends \PHPUnit_Framework_TestCase
1210
{
1311
/**
@@ -18,22 +16,22 @@ class GuestBillingAddressManagementTest extends \PHPUnit_Framework_TestCase
1816
/**
1917
* @var \PHPUnit_Framework_MockObject_MockObject
2018
*/
21-
protected $quoteRepositoryMock;
19+
protected $quoteIdMaskFactoryMock;
2220

2321
/**
2422
* @var \PHPUnit_Framework_MockObject_MockObject
2523
*/
26-
protected $validatorMock;
24+
protected $quoteIdMaskMock;
2725

2826
/**
2927
* @var \PHPUnit_Framework_MockObject_MockObject
3028
*/
31-
protected $quoteIdMaskFactoryMock;
29+
protected $billingAddressManagementMock;
3230

3331
/**
3432
* @var \PHPUnit_Framework_MockObject_MockObject
3533
*/
36-
protected $quoteIdMaskMock;
34+
protected $addressMock;
3735

3836
/**
3937
* @var string
@@ -51,14 +49,17 @@ class GuestBillingAddressManagementTest extends \PHPUnit_Framework_TestCase
5149
protected function setUp()
5250
{
5351
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
54-
$this->quoteRepositoryMock = $this->getMock('\Magento\Quote\Model\QuoteRepository', [], [], '', false);
55-
$this->validatorMock = $this->getMock('\Magento\Quote\Model\QuoteAddressValidator', [], [], '', false);
56-
$logger = $this->getMock('\Psr\Log\LoggerInterface');
57-
$this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false);
58-
$this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false);
52+
$this->addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false);
53+
$this->billingAddressManagementMock = $this->getMock(
54+
'Magento\Quote\Model\BillingAddressManagement',
55+
[],
56+
[],
57+
'',
58+
false
59+
);
5960

6061
$this->maskedCartId = 'f216207248d65c789b17be8545e0aa73';
61-
$this->cartId = 11;
62+
$this->cartId = 123;
6263

6364
$guestCartTestHelper = new GuestCartTestHelper($this);
6465
list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask(
@@ -69,55 +70,28 @@ protected function setUp()
6970
$this->model = $objectManager->getObject(
7071
'Magento\Quote\Model\GuestCart\GuestBillingAddressManagement',
7172
[
72-
'quoteRepository' => $this->quoteRepositoryMock,
73-
'addressValidator' => $this->validatorMock,
74-
'logger' => $logger,
75-
'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock
73+
'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock,
74+
'billingAddressManagement' => $this->billingAddressManagementMock
7675
]
7776
);
7877
}
7978

8079
/**
8180
* @return void
8281
*/
83-
public function testGetAddress()
82+
public function testGet()
8483
{
85-
$quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false);
86-
$this->quoteRepositoryMock->expects($this->once())->method('getActive')
87-
->with($this->cartId )->will($this->returnValue($quoteMock));
88-
89-
$addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false);
90-
$quoteMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($addressMock));
91-
92-
$this->assertEquals($addressMock, $this->model->get($this->maskedCartId ));
84+
$this->billingAddressManagementMock->expects($this->once())->method('get')->willReturn($this->addressMock);
85+
$this->assertEquals($this->addressMock, $this->model->get($this->maskedCartId));
9386
}
9487

9588
/**
9689
* @return void
9790
*/
98-
public function testAssingAddress()
91+
public function testAssing()
9992
{
100-
$address = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false, false);
101-
102-
$quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false);
103-
$this->quoteRepositoryMock->expects($this->once())
104-
->method('getActive')
105-
->with($this->cartId )
106-
->will($this->returnValue($quoteMock));
107-
108-
$this->validatorMock->expects($this->once())->method('validate')
109-
->with($address)
110-
->will($this->returnValue(true));
111-
112-
$quoteMock->expects($this->once())->method('setBillingAddress')->with($address);
113-
$quoteMock->expects($this->once())->method('setDataChanges')->with(true);
114-
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock);
11593
$addressId = 1;
116-
$billingAddressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false);
117-
$billingAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId));
118-
$quoteMock->expects($this->once())->method('getBillingAddress')
119-
->will($this->returnValue($billingAddressMock));
120-
121-
$this->assertEquals($addressId, $this->model->assign($this->maskedCartId , $address));
94+
$this->billingAddressManagementMock->expects($this->once())->method('assign')->willReturn($addressId);
95+
$this->assertEquals($addressId, $this->model->assign($this->maskedCartId, $this->addressMock));
12296
}
12397
}

0 commit comments

Comments
 (0)