Skip to content

Commit 3faa3ef

Browse files
committed
AC-3486::Fixed Unit test cases for Quote.php and added depracation motivation for \Magento\Quote\Model\Quote::loadByCustomer
1 parent 5b536fa commit 3faa3ef

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Quote\Model;
77

8+
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
89
use Magento\Customer\Api\Data\CustomerInterface;
910
use Magento\Customer\Api\Data\GroupInterface;
1011
use Magento\Directory\Model\AllowedCountries;
@@ -18,7 +19,6 @@
1819
use Magento\Quote\Model\Quote\Address\Total as AddressTotal;
1920
use Magento\Sales\Model\Status;
2021
use Magento\Store\Model\ScopeInterface;
21-
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
2222

2323
/**
2424
* Quote model
@@ -875,7 +875,7 @@ public function beforeSave()
875875
* Loading quote data by customer
876876
*
877877
* @param \Magento\Customer\Model\Customer|int $customer
878-
* @deprecated 101.0.0
878+
* @deprecated 101.0.0 Deprecated to handle external usages of customer methods
879879
* @return $this
880880
*/
881881
public function loadByCustomer($customer)
@@ -1428,12 +1428,14 @@ public function getItemsCollection($useCache = true)
14281428
public function getAllItems()
14291429
{
14301430
$items = [];
1431+
/** @var \Magento\Quote\Model\Quote\Item $item */
14311432
foreach ($this->getItemsCollection() as $item) {
1432-
/** @var \Magento\Quote\Model\Quote\Item $item */
1433-
if (!$item->isDeleted() && (int)$item->getProduct()->getStatus() !== ProductStatus::STATUS_DISABLED) {
1433+
$product = $item->getProduct();
1434+
if (!$item->isDeleted() && ($product && (int)$product->getStatus() !== ProductStatus::STATUS_DISABLED)) {
14341435
$items[] = $item;
14351436
}
14361437
}
1438+
14371439
return $items;
14381440
}
14391441

app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,9 @@ public function testAddProductItemPreparation(): void
10341034
$itemMock->expects($this->any())
10351035
->method('representProduct')
10361036
->willReturn(true);
1037+
$itemMock->expects($this->any())
1038+
->method('getProduct')
1039+
->willReturn($this->productMock);
10371040

10381041
$iterator = new \ArrayIterator([$itemMock]);
10391042
$collectionMock->expects($this->any())
@@ -1402,20 +1405,26 @@ public function testGetItemsCollection(): void
14021405
public function testGetAllItems(): void
14031406
{
14041407
$itemOneMock = $this->getMockBuilder(\Magento\Quote\Model\ResourceModel\Quote\Item::class)
1405-
->addMethods(['isDeleted'])
1408+
->addMethods(['isDeleted', 'getProduct'])
14061409
->disableOriginalConstructor()
14071410
->getMock();
14081411
$itemOneMock->expects($this->once())
14091412
->method('isDeleted')
14101413
->willReturn(false);
1414+
$itemOneMock->expects($this->once())
1415+
->method('getProduct')
1416+
->willReturn($this->productMock);
14111417

14121418
$itemTwoMock = $this->getMockBuilder(\Magento\Quote\Model\ResourceModel\Quote\Item::class)
1413-
->addMethods(['isDeleted'])
1419+
->addMethods(['isDeleted', 'getProduct'])
14141420
->disableOriginalConstructor()
14151421
->getMock();
14161422
$itemTwoMock->expects($this->once())
14171423
->method('isDeleted')
14181424
->willReturn(true);
1425+
$itemTwoMock->expects($this->once())
1426+
->method('getProduct')
1427+
->willReturn($this->productMock);
14191428

14201429
$items = [$itemOneMock, $itemTwoMock];
14211430
$itemResult = [$itemOneMock];

0 commit comments

Comments
 (0)