Skip to content

Commit 178b484

Browse files
author
Robert He
committed
MAGETWO-33665 : Refactor Quote module to use mutable data object interfaces
-- fixes from code review -- fixes to testcases
1 parent 3434898 commit 178b484

File tree

7 files changed

+89
-42
lines changed

7 files changed

+89
-42
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/**
1212
* Cart Totals
1313
*
14+
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
1415
* @codeCoverageIgnore
1516
*/
1617
class Totals extends AbstractExtensibleModel implements TotalsInterface

app/code/Magento/Quote/Model/Quote/Item.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@
9696
* @method \Magento\Quote\Model\Quote\Item setHasConfigurationUnavailableError(bool $value)
9797
* @method \Magento\Quote\Model\Quote\Item unsHasConfigurationUnavailableError()
9898
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
99+
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
100+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
99101
*/
100102
class Item extends \Magento\Quote\Model\Quote\Item\AbstractItem implements \Magento\Quote\Api\Data\CartItemInterface
101103
{

app/code/Magento/Quote/Model/Quote/Payment.php

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -232,88 +232,117 @@ public function getMethodInstance()
232232

233233
/**
234234
* @codeCoverageIgnoreStart
235+
*/
236+
237+
/**
238+
* Get purchase order number
235239
*
236-
* {@inheritdoc}
240+
* @return string|null
237241
*/
238242
public function getPoNumber()
239243
{
240244
return $this->getData(self::KEY_PO_NUMBER);
241245
}
242246

243-
/*
244-
* {@inheritdoc}
247+
/**
248+
* Set purchase order number
249+
*
250+
* @param string $poNumber
251+
* @return $this
245252
*/
246253
public function setPoNumber($poNumber)
247254
{
248255
return $this->setData(self::KEY_PO_NUMBER, $poNumber);
249256
}
250257

251258
/**
252-
* {@inheritdoc}
259+
* Get payment method code
260+
*
261+
* @return string
253262
*/
254263
public function getMethod()
255264
{
256265
return $this->getData(self::KEY_METHOD);
257266
}
258267

259268
/**
260-
* {@inheritdoc}
269+
* Set payment method code
270+
*
271+
* @param string $method
272+
* @return $this
261273
*/
262274
public function setMethod($method)
263275
{
264276
return $this->setData(self::KEY_METHOD, $method);
265277
}
266278

267279
/**
268-
* {@inheritdoc}
280+
* Get credit card owner
281+
*
282+
* @return string|null
269283
*/
270284
public function getCcOwner()
271285
{
272286
return $this->getData(self::KEY_CC_OWNER);
273287
}
274288

275289
/**
276-
* {@inheritdoc}
290+
* Set credit card owner
291+
*
292+
* @param string $ccOwner
293+
* @return $this
277294
*/
278295
public function setCcOwner($ccOwner)
279296
{
280297
return $this->setData(self::KEY_CC_OWNER, $ccOwner);
281298
}
282299

283300
/**
284-
* {@inheritdoc}
301+
* Get credit card number
302+
*
303+
* @return string|null
285304
*/
286305
public function getCcNumber()
287306
{
288307
return $this->getData(self::KEY_CC_NUMBER);
289308
}
290309

291310
/**
292-
* {@inheritdoc}
311+
* Set credit card number
312+
*
313+
* @param string $ccNumber
314+
* @return $this
293315
*/
294316
public function setCcNumber($ccNumber)
295317
{
296318
return $this->setData(self::KEY_CC_NUMBER, $ccNumber);
297319
}
298320

299321
/**
300-
* {@inheritdoc}
322+
* Get credit card type
323+
*
324+
* @return string|null
301325
*/
302326
public function getCcType()
303327
{
304328
return $this->getData(self::KEY_CC_TYPE);
305329
}
306330

307331
/**
308-
* {@inheritdoc}
332+
* Set credit card type
333+
*
334+
* @param string $ccType
335+
* @return $this
309336
*/
310337
public function setCcType($ccType)
311338
{
312-
return $this->setData(self::KEY_CC_TYPE,$ccType);
339+
return $this->setData(self::KEY_CC_TYPE, $ccType);
313340
}
314341

315342
/**
316-
* {@inheritdoc}
343+
* Get credit card expiration year
344+
*
345+
* @return string|null
317346
*/
318347
public function getCcExpYear()
319348
{
@@ -322,31 +351,41 @@ public function getCcExpYear()
322351
}
323352

324353
/**
325-
* {@inheritdoc}
354+
* Set credit card expiration year
355+
*
356+
* @param string $ccExpYear
357+
* @return $this
326358
*/
327359
public function setCcExpYear($ccExpYear)
328360
{
329361
return $this->setData(self::KEY_CC_EXP_YEAR, $ccExpYear);
330362
}
331363

332364
/**
333-
* {@inheritdoc}
365+
* Get credit card expiration month
366+
*
367+
* @return string|null
334368
*/
335369
public function getCcExpMonth()
336370
{
337371
return $this->getData(self::KEY_CC_EXP_MONTH);
338372
}
339373

340374
/**
341-
* {@inheritdoc}
375+
* Set credit card expiration month
376+
*
377+
* @param string $ccExpMonth
378+
* @return $this
342379
*/
343380
public function setCcExpMonth($ccExpMonth)
344381
{
345-
return $this->setData(self::KEY_CC_EXP_MONTH,$ccExpMonth);
382+
return $this->setData(self::KEY_CC_EXP_MONTH, $ccExpMonth);
346383
}
347384

348385
/**
349-
* {@inheritdoc}
386+
* Get payment additional details
387+
*
388+
* @return string[]|null
350389
*/
351390
public function getAdditionalData()
352391
{
@@ -363,7 +402,10 @@ public function getAdditionalData()
363402
}
364403

365404
/**
366-
* {@inheritdoc}
405+
* Set payment additional details
406+
*
407+
* @param string[] $additionalData
408+
* @return $this
367409
*/
368410
public function setAdditionalData(array $additionalData = null)
369411
{

dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ public function testGetMethod()
125125
list($carrierCode, $methodCode) = explode('_', $shippingAddress->getShippingMethod());
126126
list($carrierTitle, $methodTitle) = explode(' - ', $shippingAddress->getShippingDescription());
127127
$data = [
128-
ShippingMethodInterface::CARRIER_CODE => $carrierCode,
129-
ShippingMethodInterface::METHOD_CODE => $methodCode,
130-
ShippingMethodInterface::CARRIER_TITLE => $carrierTitle,
131-
ShippingMethodInterface::METHOD_TITLE => $methodTitle,
132-
ShippingMethodInterface::SHIPPING_AMOUNT => $shippingAddress->getShippingAmount(),
133-
ShippingMethodInterface::BASE_SHIPPING_AMOUNT => $shippingAddress->getBaseShippingAmount(),
134-
ShippingMethodInterface::AVAILABLE => true,
128+
ShippingMethodInterface::KEY_CARRIER_CODE => $carrierCode,
129+
ShippingMethodInterface::KEY_METHOD_CODE => $methodCode,
130+
ShippingMethodInterface::KEY_CARRIER_TITLE => $carrierTitle,
131+
ShippingMethodInterface::KEY_METHOD_TITLE => $methodTitle,
132+
ShippingMethodInterface::KEY_SHIPPING_AMOUNT => $shippingAddress->getShippingAmount(),
133+
ShippingMethodInterface::KEY_BASE_SHIPPING_AMOUNT => $shippingAddress->getBaseShippingAmount(),
134+
ShippingMethodInterface::KEY_AVAILABLE => true,
135135
];
136136

137137
$requestData = ["cartId" => $cartId];

dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderCreateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function prepareOrder()
5757
$orderItem->setSku('sku#1');
5858
if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
5959
$orderItem->setData('parent_item', $orderItem->getData() + ['parent_item' => null]);
60-
$orderItem->setAdditionalData('test');
60+
$orderItem->setAdditionalData(['test']);
6161
} else {
6262
$orderItem->setData('parent_item', ['weight' => 1]);
6363
}

dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
->setCcType('visa')
2323
->setCcExpYear(2014)
2424
->setCcExpMonth(1)
25-
->setAdditionalData(serialize($paymentDetails));
25+
->setAdditionalData($paymentDetails);
2626

2727
$quote->collectTotals()->save();

dev/tests/unit/testsuite/Magento/Quote/Model/Quote/Item/RepositoryTest.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,21 @@ public function testDeleteById()
313313
{
314314
$cartId = 11;
315315
$itemId = 5;
316-
// $this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->dataMock);
317-
// $this->itemDataFactoryMock->expects($this->once())->method('setQuoteId')->with($cartId)->willReturn($this->itemDataFactoryMock);
318-
// $this->itemDataFactoryMock->expects($this->once())->method('setItemId')->with($itemId)->willReturn($this->itemDataFactoryMock);
319-
// $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
320-
// $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId);
321-
// $this->quoteRepositoryMock->expects($this->once())
322-
// ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
323-
// $this->quoteMock->expects($this->once())
324-
// ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock));
325-
// $this->quoteMock->expects($this->once())->method('removeItem');
326-
// $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
327-
// $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
328-
//
329-
// $this->assertTrue($this->repository->deleteById($cartId, $itemId));
316+
$this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->itemDataFactoryMock);
317+
$this->itemDataFactoryMock->expects($this->once())->method('setQuoteId')
318+
->with($cartId)->willReturn($this->itemDataFactoryMock);
319+
$this->itemDataFactoryMock->expects($this->once())->method('setItemId')
320+
->with($itemId)->willReturn($this->dataMock);
321+
$this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
322+
$this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId);
323+
$this->quoteRepositoryMock->expects($this->once())
324+
->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
325+
$this->quoteMock->expects($this->once())
326+
->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock));
327+
$this->quoteMock->expects($this->once())->method('removeItem');
328+
$this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
329+
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
330+
331+
$this->assertTrue($this->repository->deleteById($cartId, $itemId));
330332
}
331333
}

0 commit comments

Comments
 (0)