Skip to content

Commit a987761

Browse files
author
Oleksii Korshenko
committed
MAGETWO-71060: Remove zend json from package info #10340
- Merge Pull Request #10340 from dmanners/magento2:remove-zend-json-from-package-info - Merged commits: 1. f706fdd 2. fd155b3
2 parents c955c32 + fd155b3 commit a987761

File tree

10 files changed

+123
-51
lines changed

10 files changed

+123
-51
lines changed

app/code/Magento/Checkout/view/frontend/layout/checkout_cart_item_renderers.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
<update handle="checkout_item_price_renderers"/>
1010
<body>
1111
<referenceBlock name="checkout.cart.item.renderers">
12-
<block class="Magento\Checkout\Block\Cart\Item\Renderer" as="default" template="Magento_Checkout::cart/item/default.phtml">
12+
<block class="Magento\Checkout\Block\Cart\Item\Renderer" name="checkout.cart.item.renderers.default" as="default" template="Magento_Checkout::cart/item/default.phtml">
1313
<block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions" name="checkout.cart.item.renderers.default.actions" as="actions">
1414
<block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Edit" name="checkout.cart.item.renderers.default.actions.edit" template="Magento_Checkout::cart/item/renderer/actions/edit.phtml"/>
1515
<block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Remove" name="checkout.cart.item.renderers.default.actions.remove" template="Magento_Checkout::cart/item/renderer/actions/remove.phtml"/>
1616
</block>
1717
</block>
18-
<block class="Magento\Checkout\Block\Cart\Item\Renderer" as="simple" template="Magento_Checkout::cart/item/default.phtml">
18+
<block class="Magento\Checkout\Block\Cart\Item\Renderer" name="checkout.cart.item.renderers.simple" as="simple" template="Magento_Checkout::cart/item/default.phtml">
1919
<block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions" name="checkout.cart.item.renderers.simple.actions" as="actions">
2020
<block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Edit" name="checkout.cart.item.renderers.simple.actions.edit" template="Magento_Checkout::cart/item/renderer/actions/edit.phtml"/>
2121
<block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Remove" name="checkout.cart.item.renderers.simple.actions.remove" template="Magento_Checkout::cart/item/renderer/actions/remove.phtml"/>

dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ abstract class AbstractController extends \PHPUnit_Framework_TestCase
2525
protected $_runOptions = [];
2626

2727
/**
28-
* @var \Magento\TestFramework\Request
28+
* @var \Magento\Framework\App\RequestInterface
2929
*/
3030
protected $_request;
3131

3232
/**
33-
* @var \Magento\TestFramework\Response
33+
* @var \Magento\Framework\App\ResponseInterface
3434
*/
3535
protected $_response;
3636

@@ -102,7 +102,7 @@ public function dispatch($uri)
102102
/**
103103
* Request getter
104104
*
105-
* @return \Magento\TestFramework\Request
105+
* @return \Magento\Framework\App\RequestInterface
106106
*/
107107
public function getRequest()
108108
{
@@ -115,7 +115,7 @@ public function getRequest()
115115
/**
116116
* Response getter
117117
*
118-
* @return \Magento\TestFramework\Response
118+
* @return \Magento\Framework\App\ResponseInterface
119119
*/
120120
public function getResponse()
121121
{
@@ -268,14 +268,21 @@ protected function getCookieMessages($messageType = null)
268268
{
269269
/** @var $cookieManager CookieManagerInterface */
270270
$cookieManager = $this->_objectManager->get(CookieManagerInterface::class);
271+
272+
/** @var $jsonSerializer \Magento\Framework\Serialize\Serializer\Json */
273+
$jsonSerializer = $this->_objectManager->get(\Magento\Framework\Serialize\Serializer\Json::class);
271274
try {
272-
$messages = \Zend_Json::decode(
273-
$cookieManager->getCookie(MessagePlugin::MESSAGES_COOKIES_NAME, \Zend_Json::encode([]))
275+
$messages = $jsonSerializer->unserialize(
276+
$cookieManager->getCookie(
277+
MessagePlugin::MESSAGES_COOKIES_NAME,
278+
$jsonSerializer->serialize([])
279+
)
274280
);
281+
275282
if (!is_array($messages)) {
276283
$messages = [];
277284
}
278-
} catch (\Zend_Json_Exception $e) {
285+
} catch (\InvalidArgumentException $e) {
279286
$messages = [];
280287
}
281288

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/TestCase/ControllerAbstractTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,25 @@ class ControllerAbstractTest extends \Magento\TestFramework\TestCase\AbstractCon
2525
/** @var \PHPUnit_Framework_MockObject_MockObject | CookieManagerInterface */
2626
private $cookieManagerMock;
2727

28+
/**
29+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Serialize\Serializer\Json
30+
*/
31+
private $serializerMock;
32+
2833
protected function setUp()
2934
{
3035
$testObjectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
3136

3237
$this->messageManager = $this->getMock(\Magento\Framework\Message\Manager::class, [], [], '', false);
3338
$this->cookieManagerMock = $this->getMock(CookieManagerInterface::class, [], [], '', false);
39+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
40+
->disableOriginalConstructor()
41+
->getMock();
42+
$this->serializerMock->expects($this->any())->method('unserialize')->willReturnCallback(
43+
function ($serializedData) {
44+
return json_decode($serializedData, true);
45+
}
46+
);
3447
$this->interpretationStrategyMock = $this->getMock(InterpretationStrategyInterface::class, [], [], '', false);
3548
$this->interpretationStrategyMock->expects($this->any())
3649
->method('interpret')
@@ -58,6 +71,7 @@ function (MessageInterface $message) {
5871
[\Magento\Framework\App\ResponseInterface::class, $response],
5972
[\Magento\Framework\Message\Manager::class, $this->messageManager],
6073
[CookieManagerInterface::class, $this->cookieManagerMock],
74+
[\Magento\Framework\Serialize\Serializer\Json::class, $this->serializerMock],
6175
[InterpretationStrategyInterface::class, $this->interpretationStrategyMock],
6276
]
6377
)
@@ -244,6 +258,6 @@ private function addSessionMessages()
244258

245259
$this->cookieManagerMock->expects($this->any())
246260
->method('getCookie')
247-
->willReturn(\Zend_Json::encode($cookieMessages));
261+
->willReturn(json_encode($cookieMessages));
248262
}
249263
}

dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function testLoadDefault()
108108
$this->assertNotEmpty($this->model->getTemplateText());
109109
$this->assertNotEmpty($this->model->getTemplateSubject());
110110
$this->assertNotEmpty($this->model->getOrigTemplateVariables());
111-
$this->assertInternalType('array', \Zend_Json::decode($this->model->getOrigTemplateVariables()));
111+
$this->assertInternalType('array', json_decode($this->model->getOrigTemplateVariables(), true));
112112
}
113113

114114
/**

dev/tests/integration/testsuite/Magento/ImportExport/Block/Adminhtml/Import/Edit/BeforeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function setUp()
9393
public function testGetEntityBehaviors()
9494
{
9595
$actualEntities = $this->_model->getEntityBehaviors();
96-
$expectedEntities = \Zend_Json::encode($this->_expectedEntities);
96+
$expectedEntities = json_encode($this->_expectedEntities);
9797
$this->assertEquals($expectedEntities, $actualEntities);
9898
}
9999

@@ -105,7 +105,7 @@ public function testGetEntityBehaviors()
105105
public function testGetUniqueBehaviors()
106106
{
107107
$actualBehaviors = $this->_model->getUniqueBehaviors();
108-
$expectedBehaviors = \Zend_Json::encode($this->_expectedBehaviors);
108+
$expectedBehaviors = json_encode($this->_expectedBehaviors);
109109
$this->assertEquals($expectedBehaviors, $actualBehaviors);
110110
}
111111
}

lib/internal/Magento/Framework/Module/PackageInfo.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,32 @@ class PackageInfo
5959
protected $nonExistingDependencies = [];
6060

6161
/**
62-
* Constructor
63-
*
62+
* @var \Magento\Framework\Serialize\Serializer\Json
63+
*/
64+
private $serializer;
65+
66+
/**
6467
* @param Dir\Reader $reader
6568
* @param ComponentRegistrar $componentRegistrar
69+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
70+
* @throws \RuntimeException
6671
*/
67-
public function __construct(Dir\Reader $reader, ComponentRegistrar $componentRegistrar)
68-
{
72+
public function __construct(
73+
Dir\Reader $reader,
74+
ComponentRegistrar $componentRegistrar,
75+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
76+
) {
6977
$this->reader = $reader;
7078
$this->componentRegistrar = $componentRegistrar;
79+
$this->serializer = $serializer?: \Magento\Framework\App\ObjectManager::getInstance()
80+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
7181
}
7282

7383
/**
7484
* Load the packages information
7585
*
7686
* @return void
77-
* @throws \Zend_Json_Exception
87+
* @throws \InvalidArgumentException
7888
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7989
*/
8090
private function load()
@@ -85,9 +95,9 @@ private function load()
8595
$key = $moduleDir . '/composer.json';
8696
if (isset($jsonData[$key]) && $jsonData[$key]) {
8797
try {
88-
$packageData = \Zend_Json::decode($jsonData[$key]);
89-
} catch (\Zend_Json_Exception $e) {
90-
throw new \Zend_Json_Exception(
98+
$packageData = $this->serializer->unserialize($jsonData[$key]);
99+
} catch (\InvalidArgumentException $e) {
100+
throw new \InvalidArgumentException(
91101
sprintf(
92102
"%s composer.json error: %s",
93103
$moduleName,

lib/internal/Magento/Framework/Module/Test/Unit/PackageInfoTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,21 @@ protected function setUp()
5454
->method('getComposerJsonFiles')
5555
->will($this->returnValue($fileIteratorMock));
5656

57-
$this->packageInfo = new PackageInfo($this->reader, $this->componentRegistrar);
57+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
58+
->getMock();
59+
60+
$this->serializerMock->expects($this->any())
61+
->method('unserialize')
62+
->willReturnCallback(
63+
function ($serializedData) {
64+
return json_decode($serializedData, true);
65+
}
66+
);
67+
$this->packageInfo = new PackageInfo(
68+
$this->reader,
69+
$this->componentRegistrar,
70+
$this->serializerMock
71+
);
5872
}
5973

6074
public function testGetModuleName()

lib/internal/Magento/Framework/Webapi/Rest/Request/Deserializer/Json.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,37 @@
1212

1313
class Json implements \Magento\Framework\Webapi\Rest\Request\DeserializerInterface
1414
{
15-
/** @var \Magento\Framework\Json\Decoder */
15+
/**
16+
* @var \Magento\Framework\Json\Decoder
17+
* @deprecated
18+
*/
1619
protected $decoder;
1720

1821
/**
1922
* @var State
2023
*/
2124
protected $_appState;
2225

26+
/**
27+
* @var \Magento\Framework\Serialize\Serializer\Json
28+
*/
29+
private $serializer;
30+
2331
/**
2432
* @param \Magento\Framework\Json\Decoder $decoder
25-
* @param \Magento\Framework\App\State $appState
33+
* @param State $appState
34+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
35+
* @throws \RuntimeException
2636
*/
27-
public function __construct(\Magento\Framework\Json\Decoder $decoder, State $appState)
28-
{
37+
public function __construct(
38+
\Magento\Framework\Json\Decoder $decoder,
39+
State $appState,
40+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
41+
) {
2942
$this->decoder = $decoder;
3043
$this->_appState = $appState;
44+
$this->serializer = $serializer?: \Magento\Framework\App\ObjectManager::getInstance()
45+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
3146
}
3247

3348
/**
@@ -46,8 +61,8 @@ public function deserialize($encodedBody)
4661
);
4762
}
4863
try {
49-
$decodedBody = $this->decoder->decode($encodedBody);
50-
} catch (\Zend_Json_Exception $e) {
64+
$decodedBody = $this->serializer->unserialize($encodedBody);
65+
} catch (\InvalidArgumentException $e) {
5166
if ($this->_appState->getMode() !== State::MODE_DEVELOPER) {
5267
throw new \Magento\Framework\Webapi\Exception(new Phrase('Decoding error.'));
5368
} else {

lib/internal/Magento/Framework/Webapi/Test/Unit/Rest/Request/Deserializer/JsonTest.php

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,30 @@ class JsonTest extends \PHPUnit_Framework_TestCase
2121
/** @var \PHPUnit_Framework_MockObject_MockObject */
2222
protected $_appStateMock;
2323

24+
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
25+
private $serializerMock;
26+
2427
protected function setUp()
2528
{
2629
/** Prepare mocks for SUT constructor. */
2730
$this->decoderMock = $this->getMockBuilder(\Magento\Framework\Json\Decoder::class)
2831
->disableOriginalConstructor()
2932
->setMethods(['decode'])
3033
->getMock();
31-
$this->_appStateMock = $this->getMock(\Magento\Framework\App\State::class, [], [], '', false);
34+
$this->_appStateMock = $this->getMock(
35+
\Magento\Framework\App\State::class,
36+
[],
37+
[],
38+
'',
39+
false
40+
);
41+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
42+
->getMock();
3243
/** Initialize SUT. */
3344
$this->_jsonDeserializer = new \Magento\Framework\Webapi\Rest\Request\Deserializer\Json(
3445
$this->decoderMock,
35-
$this->_appStateMock
46+
$this->_appStateMock,
47+
$this->serializerMock
3648
);
3749
parent::setUp();
3850
}
@@ -60,13 +72,13 @@ public function testDeserialize()
6072
'key2' => 'test2',
6173
'array' => ['test01' => 'some1', 'test02' => 'some2'],
6274
];
63-
$this->decoderMock->expects(
64-
$this->once()
65-
)->method(
66-
'decode'
67-
)->will(
68-
$this->returnValue($expectedDecodedJson)
69-
);
75+
$this->serializerMock->expects($this->any())
76+
->method('unserialize')
77+
->willReturnCallback(
78+
function ($serializedData) {
79+
return json_decode($serializedData, true);
80+
}
81+
);
7082
/** Initialize SUT. */
7183
$this->assertEquals(
7284
$expectedDecodedJson,
@@ -78,9 +90,10 @@ public function testDeserialize()
7890
public function testDeserializeInvalidEncodedBodyExceptionDeveloperModeOff()
7991
{
8092
/** Prepare mocks for SUT constructor. */
81-
$this->decoderMock->expects($this->once())
82-
->method('decode')
83-
->will($this->throwException(new \Zend_Json_Exception));
93+
$this->serializerMock
94+
->expects($this->once())
95+
->method('unserialize')
96+
->will($this->throwException(new \InvalidArgumentException));
8497
$this->_appStateMock->expects($this->once())
8598
->method('getMode')
8699
->will($this->returnValue('production'));
@@ -103,15 +116,14 @@ public function testDeserializeInvalidEncodedBodyExceptionDeveloperModeOff()
103116
public function testDeserializeInvalidEncodedBodyExceptionDeveloperModeOn()
104117
{
105118
/** Prepare mocks for SUT constructor. */
106-
$this->decoderMock->expects(
107-
$this->once()
108-
)->method(
109-
'decode'
110-
)->will(
111-
$this->throwException(
112-
new \Zend_Json_Exception('Decoding error:' . PHP_EOL . 'Decoding failed: Syntax error')
113-
)
114-
);
119+
$this->serializerMock
120+
->expects($this->once())
121+
->method('unserialize')
122+
->will(
123+
$this->throwException(
124+
new \InvalidArgumentException('Unable to unserialize value.')
125+
)
126+
);
115127
$this->_appStateMock->expects($this->once())
116128
->method('getMode')
117129
->will($this->returnValue('developer'));

setup/src/Magento/Setup/Test/Unit/Controller/MarketplaceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testSaveAuthJsonAction()
3939
$this->packagesAuth
4040
->expects($this->once())
4141
->method('checkCredentials')
42-
->will($this->returnValue(\Zend_Json::encode(['success' => true])));
42+
->will($this->returnValue(json_encode(['success' => true])));
4343
$this->packagesAuth
4444
->expects($this->once())
4545
->method('saveAuthJson')
@@ -75,7 +75,7 @@ public function testCheckAuthAction()
7575
$this->packagesAuth
7676
->expects($this->once())
7777
->method('checkCredentials')
78-
->will($this->returnValue(\Zend_Json::encode(['success' => true])));
78+
->will($this->returnValue(json_encode(['success' => true])));
7979
$jsonModel = $this->controller->checkAuthAction();
8080
$this->assertInstanceOf(\Zend\View\Model\ViewModel::class, $jsonModel);
8181
$variables = $jsonModel->getVariables();

0 commit comments

Comments
 (0)