Skip to content

Commit 5bc4cdd

Browse files
committed
Replace Zend_Json from the Magento Quote module with Magento Framework json serializer
1 parent f1dc91b commit 5bc4cdd

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,34 @@ class ItemConverter
3737
*/
3838
private $dataObjectHelper;
3939

40+
/**
41+
* @var \Magento\Framework\Serialize\Serializer\Json
42+
*/
43+
private $serializer;
44+
4045
/**
4146
* Constructs a totals item converter object.
4247
*
4348
* @param ConfigurationPool $configurationPool
4449
* @param EventManager $eventManager
4550
* @param \Magento\Quote\Api\Data\TotalsItemInterfaceFactory $totalsItemFactory
4651
* @param DataObjectHelper $dataObjectHelper
52+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
53+
* @throws \RuntimeException
4754
*/
4855
public function __construct(
4956
ConfigurationPool $configurationPool,
5057
EventManager $eventManager,
5158
\Magento\Quote\Api\Data\TotalsItemInterfaceFactory $totalsItemFactory,
52-
DataObjectHelper $dataObjectHelper
59+
DataObjectHelper $dataObjectHelper,
60+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
5361
) {
5462
$this->configurationPool = $configurationPool;
5563
$this->eventManager = $eventManager;
5664
$this->totalsItemFactory = $totalsItemFactory;
5765
$this->dataObjectHelper = $dataObjectHelper;
66+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
67+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
5868
}
5969

6070
/**
@@ -103,6 +113,6 @@ private function getFormattedOptionValue($item)
103113
$optionsData[$index] = $option;
104114
$optionsData[$index]['label'] = $optionValue['label'];
105115
}
106-
return \Zend_Json::encode($optionsData);
116+
return $this->serializer->serialize($optionsData);
107117
}
108118
}

app/code/Magento/Quote/Test/Unit/Model/Cart/Totals/ItemConverterTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class ItemConverterTest extends \PHPUnit_Framework_TestCase
3333
*/
3434
private $model;
3535

36+
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
37+
private $serializerMock;
38+
3639
protected function setUp()
3740
{
3841
$this->configPoolMock = $this->getMock(
@@ -52,11 +55,14 @@ protected function setUp()
5255
false
5356
);
5457

58+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)->getMock();
59+
5560
$this->model = new \Magento\Quote\Model\Cart\Totals\ItemConverter(
5661
$this->configPoolMock,
5762
$this->eventManagerMock,
5863
$this->totalsFactoryMock,
59-
$this->dataObjectHelperMock
64+
$this->dataObjectHelperMock,
65+
$this->serializerMock
6066
);
6167
}
6268

@@ -92,6 +98,19 @@ public function testModelToDataObject()
9298
$this->dataObjectHelperMock->expects($this->once())->method('populateWithArray')
9399
->with(null, $expectedData, \Magento\Quote\Api\Data\TotalsItemInterface::class);
94100

101+
$optionData = [
102+
'1' => [
103+
'data' => 'optionsData',
104+
'label' => 'option1'
105+
],
106+
'2' => [
107+
'data' => 'optionsData',
108+
'label' => 'option2'
109+
]
110+
];
111+
$this->serializerMock->expects($this->once())->method('serialize')
112+
->will($this->returnValue(json_encode($optionData)));
113+
95114
$this->model->modelToDataObject($itemMock);
96115
}
97116
}

0 commit comments

Comments
 (0)