Skip to content

Commit 8ff3d2d

Browse files
ENGCOM-6627: Issue-25968 - Added additional checking for returning needed variable… #26313
2 parents 175eabe + 9407de5 commit 8ff3d2d

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

app/code/Magento/Sales/Model/Order/Item.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ public function getStatus()
385385
*
386386
* @param string $statusId
387387
* @return \Magento\Framework\Phrase
388+
*
389+
* phpcs:disable Magento2.Functions.StaticFunction
388390
*/
389391
public static function getStatusName($statusId)
390392
{
@@ -422,6 +424,8 @@ public function cancel()
422424
* Retrieve order item statuses array
423425
*
424426
* @return array
427+
*
428+
* phpcs:disable Magento2.Functions.StaticFunction
425429
*/
426430
public static function getStatuses()
427431
{
@@ -1319,7 +1323,13 @@ public function getParentItemId()
13191323
*/
13201324
public function getPrice()
13211325
{
1322-
return $this->getData(OrderItemInterface::PRICE);
1326+
$price = $this->getData(OrderItemInterface::PRICE);
1327+
1328+
if ($price === null) {
1329+
return $price;
1330+
}
1331+
1332+
return (float) $price;
13231333
}
13241334

13251335
/**

app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
namespace Magento\Sales\Test\Unit\Model\Order;
88

99
use Magento\Framework\Serialize\Serializer\Json;
10+
use Magento\Sales\Api\Data\OrderItemInterface;
1011
use Magento\Sales\Model\ResourceModel\OrderFactory;
11-
use \Magento\Sales\Model\Order;
1212

1313
/**
14-
* Class ItemTest
15-
*
16-
* @package Magento\Sales\Model\Order
14+
* Unit test for order item class.
1715
*/
1816
class ItemTest extends \PHPUnit\Framework\TestCase
1917
{
@@ -72,7 +70,7 @@ public function testSetParentItem()
7270
public function testGetPatentItem()
7371
{
7472
$item = $this->objectManager->getObject(\Magento\Sales\Model\Order\Item::class, []);
75-
$this->model->setData(\Magento\Sales\Api\Data\OrderItemInterface::PARENT_ITEM, $item);
73+
$this->model->setData(OrderItemInterface::PARENT_ITEM, $item);
7674
$this->assertEquals($item, $this->model->getParentItem());
7775
}
7876

@@ -184,7 +182,7 @@ public function testGetOriginalPrice()
184182
$this->assertEquals($price, $this->model->getOriginalPrice());
185183

186184
$originalPrice = 5.55;
187-
$this->model->setData(\Magento\Sales\Api\Data\OrderItemInterface::ORIGINAL_PRICE, $originalPrice);
185+
$this->model->setData(OrderItemInterface::ORIGINAL_PRICE, $originalPrice);
188186
$this->assertEquals($originalPrice, $this->model->getOriginalPrice());
189187
}
190188

@@ -348,4 +346,24 @@ public function getItemQtyVariants()
348346
]
349347
];
350348
}
349+
350+
/**
351+
* Test getPrice() method returns float
352+
*/
353+
public function testGetPriceReturnsFloat()
354+
{
355+
$price = 9.99;
356+
$this->model->setPrice($price);
357+
$this->assertEquals($price, $this->model->getPrice());
358+
}
359+
360+
/**
361+
* Test getPrice() method returns null
362+
*/
363+
public function testGetPriceReturnsNull()
364+
{
365+
$nullablePrice = null;
366+
$this->model->setData(OrderItemInterface::PRICE, $nullablePrice);
367+
$this->assertEquals($nullablePrice, $this->model->getPrice());
368+
}
351369
}

0 commit comments

Comments
 (0)