Skip to content

Commit

Permalink
ENGCOM-6627: Issue-25968 - Added additional checking for returning ne…
Browse files Browse the repository at this point in the history
…eded variable… #26313
  • Loading branch information
VladimirZaets authored Jan 17, 2020
2 parents 175eabe + 9407de5 commit 8ff3d2d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
12 changes: 11 additions & 1 deletion app/code/Magento/Sales/Model/Order/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ public function getStatus()
*
* @param string $statusId
* @return \Magento\Framework\Phrase
*
* phpcs:disable Magento2.Functions.StaticFunction
*/
public static function getStatusName($statusId)
{
Expand Down Expand Up @@ -422,6 +424,8 @@ public function cancel()
* Retrieve order item statuses array
*
* @return array
*
* phpcs:disable Magento2.Functions.StaticFunction
*/
public static function getStatuses()
{
Expand Down Expand Up @@ -1319,7 +1323,13 @@ public function getParentItemId()
*/
public function getPrice()
{
return $this->getData(OrderItemInterface::PRICE);
$price = $this->getData(OrderItemInterface::PRICE);

if ($price === null) {
return $price;
}

return (float) $price;
}

/**
Expand Down
30 changes: 24 additions & 6 deletions app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
namespace Magento\Sales\Test\Unit\Model\Order;

use Magento\Framework\Serialize\Serializer\Json;
use Magento\Sales\Api\Data\OrderItemInterface;
use Magento\Sales\Model\ResourceModel\OrderFactory;
use \Magento\Sales\Model\Order;

/**
* Class ItemTest
*
* @package Magento\Sales\Model\Order
* Unit test for order item class.
*/
class ItemTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -72,7 +70,7 @@ public function testSetParentItem()
public function testGetPatentItem()
{
$item = $this->objectManager->getObject(\Magento\Sales\Model\Order\Item::class, []);
$this->model->setData(\Magento\Sales\Api\Data\OrderItemInterface::PARENT_ITEM, $item);
$this->model->setData(OrderItemInterface::PARENT_ITEM, $item);
$this->assertEquals($item, $this->model->getParentItem());
}

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

$originalPrice = 5.55;
$this->model->setData(\Magento\Sales\Api\Data\OrderItemInterface::ORIGINAL_PRICE, $originalPrice);
$this->model->setData(OrderItemInterface::ORIGINAL_PRICE, $originalPrice);
$this->assertEquals($originalPrice, $this->model->getOriginalPrice());
}

Expand Down Expand Up @@ -348,4 +346,24 @@ public function getItemQtyVariants()
]
];
}

/**
* Test getPrice() method returns float
*/
public function testGetPriceReturnsFloat()
{
$price = 9.99;
$this->model->setPrice($price);
$this->assertEquals($price, $this->model->getPrice());
}

/**
* Test getPrice() method returns null
*/
public function testGetPriceReturnsNull()
{
$nullablePrice = null;
$this->model->setData(OrderItemInterface::PRICE, $nullablePrice);
$this->assertEquals($nullablePrice, $this->model->getPrice());
}
}

0 comments on commit 8ff3d2d

Please sign in to comment.