Skip to content

Commit 1b990e8

Browse files
committed
Replace Zend_Json from the Magento Weee module with the lib framework json serializer
1 parent e3fc5b7 commit 1b990e8

File tree

3 files changed

+78
-34
lines changed

3 files changed

+78
-34
lines changed

app/code/Magento/Weee/Helper/Data.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,38 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
7777
protected $cacheProductWeeeAmount = '_cache_product_weee_amount';
7878

7979
/**
80+
* @var \Magento\Framework\Serialize\Serializer\Json
81+
*/
82+
private $serializer;
83+
84+
/**
85+
* Data constructor.
86+
*
8087
* @param \Magento\Framework\App\Helper\Context $context
8188
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
82-
* @param \Magento\Weee\Model\Tax $weeeTax
89+
* @param WeeeDisplayConfig $weeeTax
8390
* @param \Magento\Weee\Model\Config $weeeConfig
8491
* @param \Magento\Tax\Helper\Data $taxData
8592
* @param \Magento\Framework\Registry $coreRegistry
93+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
94+
* @throws \RuntimeException
8695
*/
8796
public function __construct(
8897
\Magento\Framework\App\Helper\Context $context,
8998
\Magento\Store\Model\StoreManagerInterface $storeManager,
9099
\Magento\Weee\Model\Tax $weeeTax,
91100
\Magento\Weee\Model\Config $weeeConfig,
92101
\Magento\Tax\Helper\Data $taxData,
93-
\Magento\Framework\Registry $coreRegistry
102+
\Magento\Framework\Registry $coreRegistry,
103+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
94104
) {
95105
$this->_storeManager = $storeManager;
96106
$this->_weeeTax = $weeeTax;
97107
$this->_coreRegistry = $coreRegistry;
98108
$this->_taxData = $taxData;
99109
$this->_weeeConfig = $weeeConfig;
110+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
111+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
100112
parent::__construct($context);
101113
}
102114

@@ -373,7 +385,7 @@ public function getApplied($item)
373385
if (empty($data)) {
374386
return [];
375387
}
376-
return \Zend_Json::decode($item->getWeeeTaxApplied());
388+
return $this->serializer->unserialize($item->getWeeeTaxApplied());
377389
}
378390

379391
/**
@@ -385,7 +397,7 @@ public function getApplied($item)
385397
*/
386398
public function setApplied($item, $value)
387399
{
388-
$item->setWeeeTaxApplied(\Zend_Json::encode($value));
400+
$item->setWeeeTaxApplied($this->serializer->serialize($value));
389401
return $this;
390402
}
391403

app/code/Magento/Weee/Test/Unit/Helper/DataTest.php

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class DataTest extends \PHPUnit_Framework_TestCase
4242
*/
4343
protected $helperData;
4444

45+
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
46+
private $serializerMock;
47+
4548
protected function setUp()
4649
{
4750
$this->product = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
@@ -57,10 +60,14 @@ protected function setUp()
5760
'',
5861
false
5962
);
63+
64+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)->getMock();
65+
6066
$arguments = [
6167
'weeeConfig' => $weeeConfig,
6268
'weeeTax' => $this->weeeTax,
63-
'taxData' => $this->taxData
69+
'taxData' => $this->taxData,
70+
'serializer' => $this->serializerMock
6471
];
6572
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
6673
$this->helperData = $helper->getObject(\Magento\Weee\Helper\Data::class, $arguments);
@@ -84,33 +91,38 @@ private function setupOrderItem()
8491
->setMethods(['__wakeup'])
8592
->getMock();
8693

94+
$weeeTaxApplied = [
95+
[
96+
WeeeHelper::KEY_WEEE_AMOUNT_INVOICED => self::ROW_AMOUNT_INVOICED,
97+
WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED => self::BASE_ROW_AMOUNT_INVOICED,
98+
WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED => self::TAX_AMOUNT_INVOICED,
99+
WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED => self::BASE_TAX_AMOUNT_INVOICED,
100+
WeeeHelper::KEY_WEEE_AMOUNT_REFUNDED => self::ROW_AMOUNT_REFUNDED,
101+
WeeeHelper::KEY_BASE_WEEE_AMOUNT_REFUNDED => self::BASE_ROW_AMOUNT_REFUNDED,
102+
WeeeHelper::KEY_WEEE_TAX_AMOUNT_REFUNDED => self::TAX_AMOUNT_REFUNDED,
103+
WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_REFUNDED => self::BASE_TAX_AMOUNT_REFUNDED,
104+
],
105+
[
106+
WeeeHelper::KEY_WEEE_AMOUNT_INVOICED => self::ROW_AMOUNT_INVOICED,
107+
WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED => self::BASE_ROW_AMOUNT_INVOICED,
108+
WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED => self::TAX_AMOUNT_INVOICED,
109+
WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED => self::BASE_TAX_AMOUNT_INVOICED,
110+
WeeeHelper::KEY_WEEE_AMOUNT_REFUNDED => self::ROW_AMOUNT_REFUNDED,
111+
WeeeHelper::KEY_BASE_WEEE_AMOUNT_REFUNDED => self::BASE_ROW_AMOUNT_REFUNDED,
112+
WeeeHelper::KEY_WEEE_TAX_AMOUNT_REFUNDED => self::TAX_AMOUNT_REFUNDED,
113+
WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_REFUNDED => self::BASE_TAX_AMOUNT_REFUNDED,
114+
],
115+
];
116+
87117
$orderItem->setData(
88118
'weee_tax_applied',
89-
\Zend_Json::encode(
90-
[
91-
[
92-
WeeeHelper::KEY_WEEE_AMOUNT_INVOICED => self::ROW_AMOUNT_INVOICED,
93-
WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED => self::BASE_ROW_AMOUNT_INVOICED,
94-
WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED => self::TAX_AMOUNT_INVOICED,
95-
WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED => self::BASE_TAX_AMOUNT_INVOICED,
96-
WeeeHelper::KEY_WEEE_AMOUNT_REFUNDED => self::ROW_AMOUNT_REFUNDED,
97-
WeeeHelper::KEY_BASE_WEEE_AMOUNT_REFUNDED => self::BASE_ROW_AMOUNT_REFUNDED,
98-
WeeeHelper::KEY_WEEE_TAX_AMOUNT_REFUNDED => self::TAX_AMOUNT_REFUNDED,
99-
WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_REFUNDED => self::BASE_TAX_AMOUNT_REFUNDED,
100-
],
101-
[
102-
WeeeHelper::KEY_WEEE_AMOUNT_INVOICED => self::ROW_AMOUNT_INVOICED,
103-
WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED => self::BASE_ROW_AMOUNT_INVOICED,
104-
WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED => self::TAX_AMOUNT_INVOICED,
105-
WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED => self::BASE_TAX_AMOUNT_INVOICED,
106-
WeeeHelper::KEY_WEEE_AMOUNT_REFUNDED => self::ROW_AMOUNT_REFUNDED,
107-
WeeeHelper::KEY_BASE_WEEE_AMOUNT_REFUNDED => self::BASE_ROW_AMOUNT_REFUNDED,
108-
WeeeHelper::KEY_WEEE_TAX_AMOUNT_REFUNDED => self::TAX_AMOUNT_REFUNDED,
109-
WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_REFUNDED => self::BASE_TAX_AMOUNT_REFUNDED,
110-
],
111-
]
112-
)
119+
json_encode($weeeTaxApplied)
113120
);
121+
122+
$this->serializerMock->expects($this->any())
123+
->method('unserialize')
124+
->will($this->returnValue($weeeTaxApplied));
125+
114126
return $orderItem;
115127
}
116128

@@ -290,14 +302,18 @@ public function dataProviderGetWeeeAttributesForBundle()
290302
public function testGetAppliedSimple()
291303
{
292304
$testArray = ['key' => 'value'];
293-
$itemProductSimple=$this->getMock(\Magento\Quote\Model\Quote\Item::class, ['getWeeeTaxApplied'], [], '', false);
305+
$itemProductSimple = $this->getMock(\Magento\Quote\Model\Quote\Item::class, ['getWeeeTaxApplied'], [], '', false);
294306
$itemProductSimple->expects($this->any())
295307
->method('getHasChildren')
296308
->will($this->returnValue(false));
297309

298310
$itemProductSimple->expects($this->any())
299311
->method('getWeeeTaxApplied')
300-
->will($this->returnValue(\Zend_Json::encode($testArray)));
312+
->will($this->returnValue(json_encode($testArray)));
313+
314+
$this->serializerMock->expects($this->any())
315+
->method('unserialize')
316+
->will($this->returnValue($testArray));
301317

302318
$this->assertEquals($testArray, $this->helperData->getApplied($itemProductSimple));
303319
}
@@ -326,11 +342,11 @@ public function testGetAppliedBundle()
326342

327343
$itemProductSimple1->expects($this->any())
328344
->method('getWeeeTaxApplied')
329-
->will($this->returnValue(\Zend_Json::encode($testArray1)));
345+
->will($this->returnValue(json_encode($testArray1)));
330346

331347
$itemProductSimple2->expects($this->any())
332348
->method('getWeeeTaxApplied')
333-
->will($this->returnValue(\Zend_Json::encode($testArray2)));
349+
->will($this->returnValue(json_encode($testArray2)));
334350

335351
$itemProductBundle=$this->getMock(
336352
\Magento\Quote\Model\Quote\Item::class,
@@ -349,6 +365,10 @@ public function testGetAppliedBundle()
349365
->method('getChildren')
350366
->will($this->returnValue([$itemProductSimple1, $itemProductSimple2]));
351367

368+
$this->serializerMock->expects($this->any())
369+
->method('unserialize')
370+
->will($this->returnValue($testArray));
371+
352372
$this->assertEquals($testArray, $this->helperData->getApplied($itemProductBundle));
353373
}
354374

app/code/Magento/Weee/Test/Unit/Model/Total/Quote/WeeeTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class WeeeTest extends \PHPUnit_Framework_TestCase
2222
*/
2323
protected $weeeCollector;
2424

25+
private $serializerMock;
26+
2527
/**
2628
* Setup tax helper with an array of methodName, returnValue
2729
*
@@ -77,7 +79,17 @@ protected function setupTaxCalculation($taxRates)
7779
*/
7880
protected function setupWeeeHelper($weeeConfig)
7981
{
80-
$weeeHelper = $this->getMock(\Magento\Weee\Helper\Data::class, [], [], '', false);
82+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)->getMock();
83+
84+
$weeeHelper = $this->getMock(
85+
\Magento\Weee\Helper\Data::class,
86+
[],
87+
[
88+
'serializer' => $this->serializerMock
89+
],
90+
'',
91+
false
92+
);
8193

8294
foreach ($weeeConfig as $method => $value) {
8395
$weeeHelper->expects($this->any())->method($method)->will($this->returnValue($value));

0 commit comments

Comments
 (0)