Skip to content

Commit 0a7ee59

Browse files
committed
Replace the usage of the depricated \Magento\Framework\Json\EncoderInterface in the CustomerScopeData block,
- Use \Magento\Framework\Serialize\Serializer\Json instead when dealing with serilization - Update test to mirror the change in the main class
1 parent 2e72fb0 commit 0a7ee59

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

app/code/Magento/Customer/Block/CustomerScopeData.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ class CustomerScopeData extends \Magento\Framework\View\Element\Template
2020
private $storeManager;
2121

2222
/**
23-
* @var \Magento\Framework\Json\EncoderInterface
23+
* @var \Magento\Framework\Serialize\Serializer\Json
2424
*/
25-
private $jsonEncoder;
25+
private $serializer;
2626

2727
/**
2828
* @param \Magento\Framework\View\Element\Template\Context $context
29-
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
29+
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
3030
* @param array $data
3131
*/
3232
public function __construct(
3333
\Magento\Framework\View\Element\Template\Context $context,
34-
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
34+
\Magento\Framework\Serialize\Serializer\Json $serializer,
3535
array $data = []
3636
) {
3737
parent::__construct($context, $data);
3838
$this->storeManager = $context->getStoreManager();
39-
$this->jsonEncoder = $jsonEncoder;
39+
$this->serializer = $serializer;
4040
}
4141

4242
/**
@@ -54,11 +54,12 @@ public function getWebsiteId()
5454
/**
5555
* Get the invalidation rules json encoded
5656
*
57-
* @return string
57+
* @return bool|string
58+
* @throws \InvalidArgumentException
5859
*/
59-
public function getInvalidationRulesJson()
60+
public function getSerializedInvalidationRules()
6061
{
61-
return $this->jsonEncoder->encode(
62+
return $this->serializer->serialize(
6263
[
6364
'*' => [
6465
'Magento_Customer/js/invalidation-processor' => [

app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class CustomerScopeDataTest extends \PHPUnit_Framework_TestCase
2626
/** @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
2727
private $scopeConfigMock;
2828

29-
/** @var \Magento\Framework\Json\EncoderInterface|\PHPUnit_Framework_MockObject_MockObject */
30-
private $encoderMock;
29+
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
30+
private $serializerMock;
3131

3232
protected function setUp()
3333
{
@@ -41,7 +41,7 @@ protected function setUp()
4141
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
4242
->getMock();
4343

44-
$this->encoderMock = $this->getMockBuilder(EncoderInterface::class)
44+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
4545
->getMock();
4646

4747
$this->contextMock->expects($this->exactly(2))
@@ -54,7 +54,7 @@ protected function setUp()
5454

5555
$this->model = new CustomerScopeData(
5656
$this->contextMock,
57-
$this->encoderMock,
57+
$this->serializerMock,
5858
[]
5959
);
6060
}

app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
<script type="text/x-magento-init">
1313
<?php
1414
/* @noEscape */
15-
echo $block->getInvalidationRulesJson();
15+
echo $block->getSerializedInvalidationRules();
1616
?>
1717
</script>

0 commit comments

Comments
 (0)