Skip to content

Commit 20d9e7f

Browse files
committed
Update after review
1 parent 1ac7a8f commit 20d9e7f

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

app/code/Magento/Quote/Model/Cart/CartTotalRepository.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ public function __construct(
8383
}
8484

8585
/**
86-
* Get cart total repository
87-
*
88-
* @param int $cartId
89-
* @return QuoteTotalsInterface
90-
* @throws \Magento\Framework\Exception\NoSuchEntityException
86+
* @inheritdoc
9187
*/
9288
public function get($cartId): QuoteTotalsInterface
9389
{
@@ -109,10 +105,7 @@ public function get($cartId): QuoteTotalsInterface
109105
$addressTotalsData,
110106
QuoteTotalsInterface::class
111107
);
112-
$items = [];
113-
foreach ($quote->getAllVisibleItems() as $index => $item) {
114-
$items[$index] = $this->itemConverter->modelToDataObject($item);
115-
}
108+
$items = array_map([$this->itemConverter, 'modelToDataObject'], $quote->getAllVisibleItems());
116109
$calculatedTotals = $this->totalsConverter->process($addressTotals);
117110
$quoteTotals->setTotalSegments($calculatedTotals);
118111

app/code/Magento/Quote/Test/Unit/Model/Cart/CartTotalRepositoryTest.php

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use Magento\Quote\Model\Quote\Address;
2121
use Magento\Quote\Model\Quote\Item as QuoteItem;
2222
use Magento\Quote\Model\Cart\TotalsConverter;
23+
use Magento\Quote\Api\Data\TotalsInterfaceFactory;
24+
use Magento\Quote\Api\Data\TotalsInterface as QuoteTotalsInterface;
2325
use PHPUnit\Framework\TestCase;
2426
use PHPUnit\Framework\MockObject\MockObject;
2527

@@ -30,24 +32,12 @@
3032
*/
3133
class CartTotalRepositoryTest extends TestCase
3234
{
33-
/**
34-
* @var int
35-
*/
3635
private const STUB_CART_ID = 12;
3736

38-
/**
39-
* @var int
40-
*/
4137
private const STUB_ITEMS_QTY = 100;
4238

43-
/**
44-
* @var string
45-
*/
4639
private const STUB_CURRENCY_CODE = 'en_US';
4740

48-
/**
49-
* @var string
50-
*/
5141
private const STUB_COUPON = 'coupon';
5242

5343
/**
@@ -76,7 +66,7 @@ class CartTotalRepositoryTest extends TestCase
7666
private $quoteMock;
7767

7868
/**
79-
* @var \Magento\Quote\Api\Data\TotalsInterfaceFactory|MockObject
69+
* @var TotalsInterfaceFactory|MockObject
8070
*/
8171
private $totalsFactoryMock;
8272

@@ -104,10 +94,14 @@ protected function setUp()
10494
{
10595
$this->objectManager = new ObjectManagerHelper($this);
10696
$this->totalsFactoryMock = $this->createPartialMock(
107-
\Magento\Quote\Api\Data\TotalsInterfaceFactory::class,
108-
['create']
97+
TotalsInterfaceFactory::class,
98+
[
99+
'create'
100+
]
109101
);
110-
$this->quoteMock = $this->createPartialMock(Quote::class, [
102+
$this->quoteMock = $this->createPartialMock(
103+
Quote::class,
104+
[
111105
'isVirtual',
112106
'getShippingAddress',
113107
'getBillingAddress',
@@ -116,19 +110,31 @@ protected function setUp()
116110
'getQuoteCurrencyCode',
117111
'getItemsQty',
118112
'collectTotals'
119-
]);
120-
$this->quoteRepositoryMock = $this->createMock(CartRepositoryInterface::class);
113+
]
114+
);
115+
$this->quoteRepositoryMock = $this->createMock(
116+
CartRepositoryInterface::class
117+
);
121118
$this->addressMock = $this->createPartialMock(
122119
Address::class,
123-
['getData', 'getTotals']
120+
[
121+
'getData',
122+
'getTotals'
123+
]
124+
);
125+
$this->dataObjectHelperMock = $this->getMockBuilder(
126+
DataObjectHelper::class
127+
)->disableOriginalConstructor()->getMock();
128+
$this->converterMock = $this->createMock(
129+
ItemConverter::class
124130
);
125-
$this->dataObjectHelperMock = $this->getMockBuilder(DataObjectHelper::class)
126-
->disableOriginalConstructor()
127-
->getMock();
128-
$this->converterMock = $this->createMock(ItemConverter::class);
129131

130-
$this->couponServiceMock = $this->createMock(CouponManagementInterface::class);
131-
$this->totalsConverterMock = $this->createMock(TotalsConverter::class);
132+
$this->couponServiceMock = $this->createMock(
133+
CouponManagementInterface::class
134+
);
135+
$this->totalsConverterMock = $this->createMock(
136+
TotalsConverter::class
137+
);
132138

133139
$this->model = new CartTotalRepository(
134140
$this->totalsFactoryMock,
@@ -189,8 +195,10 @@ public function testGetCartTotal($isVirtual, $getAddressType): void
189195
->method('getTotals')
190196
->willReturn($addressTotals);
191197

192-
$totalsMock = $this->createMock(\Magento\Quote\Api\Data\TotalsInterface::class);
193-
$this->totalsFactoryMock->expects($this->once())->method('create')->willReturn($totalsMock);
198+
$totalsMock = $this->createMock(QuoteTotalsInterface::class);
199+
$this->totalsFactoryMock->expects($this->once())
200+
->method('create')
201+
->willReturn($totalsMock);
194202
$this->dataObjectHelperMock->expects($this->once())->method('populateWithArray');
195203
$this->converterMock->expects($this->once())
196204
->method('modelToDataObject')

0 commit comments

Comments
 (0)