From 422a16e8036d37cd89bbfeca0c1de9d0d551f423 Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Fri, 29 Sep 2017 14:37:52 +0300 Subject: [PATCH] MAGETWO-80179: Remove zend json from the test suite #10320 --- .../TestCase/AbstractController.php | 21 ++++++++++++------- .../Test/TestCase/ControllerAbstractTest.php | 16 +++++++++++++- .../Magento/Email/Model/TemplateTest.php | 2 +- .../Adminhtml/Import/Edit/BeforeTest.php | 4 ++-- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php index 2ab5079b7df3c..9920f90193f69 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php +++ b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php @@ -26,12 +26,12 @@ abstract class AbstractController extends \PHPUnit\Framework\TestCase protected $_runOptions = []; /** - * @var \Magento\TestFramework\Request + * @var \Magento\Framework\App\RequestInterface */ protected $_request; /** - * @var \Magento\TestFramework\Response + * @var \Magento\Framework\App\ResponseInterface */ protected $_response; @@ -103,7 +103,7 @@ public function dispatch($uri) /** * Request getter * - * @return \Magento\TestFramework\Request + * @return \Magento\Framework\App\RequestInterface */ public function getRequest() { @@ -116,7 +116,7 @@ public function getRequest() /** * Response getter * - * @return \Magento\TestFramework\Response + * @return \Magento\Framework\App\ResponseInterface */ public function getResponse() { @@ -269,14 +269,21 @@ protected function getCookieMessages($messageType = null) { /** @var $cookieManager CookieManagerInterface */ $cookieManager = $this->_objectManager->get(CookieManagerInterface::class); + + /** @var $jsonSerializer \Magento\Framework\Serialize\Serializer\Json */ + $jsonSerializer = $this->_objectManager->get(\Magento\Framework\Serialize\Serializer\Json::class); try { - $messages = \Zend_Json::decode( - $cookieManager->getCookie(MessagePlugin::MESSAGES_COOKIES_NAME, \Zend_Json::encode([])) + $messages = $jsonSerializer->unserialize( + $cookieManager->getCookie( + MessagePlugin::MESSAGES_COOKIES_NAME, + $jsonSerializer->serialize([]) + ) ); + if (!is_array($messages)) { $messages = []; } - } catch (\Zend_Json_Exception $e) { + } catch (\InvalidArgumentException $e) { $messages = []; } diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/TestCase/ControllerAbstractTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/TestCase/ControllerAbstractTest.php index 4ad6214665d0e..564661b46c7b2 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/TestCase/ControllerAbstractTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/TestCase/ControllerAbstractTest.php @@ -25,12 +25,25 @@ class ControllerAbstractTest extends \Magento\TestFramework\TestCase\AbstractCon /** @var \PHPUnit_Framework_MockObject_MockObject | CookieManagerInterface */ private $cookieManagerMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Serialize\Serializer\Json + */ + private $serializerMock; + protected function setUp() { $testObjectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->messageManager = $this->createMock(\Magento\Framework\Message\Manager::class); $this->cookieManagerMock = $this->createMock(CookieManagerInterface::class); + $this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) + ->disableOriginalConstructor() + ->getMock(); + $this->serializerMock->expects($this->any())->method('unserialize')->willReturnCallback( + function ($serializedData) { + return json_decode($serializedData, true); + } + ); $this->interpretationStrategyMock = $this->createMock(InterpretationStrategyInterface::class); $this->interpretationStrategyMock->expects($this->any()) ->method('interpret') @@ -53,6 +66,7 @@ function (MessageInterface $message) { [\Magento\Framework\App\ResponseInterface::class, $response], [\Magento\Framework\Message\Manager::class, $this->messageManager], [CookieManagerInterface::class, $this->cookieManagerMock], + [\Magento\Framework\Serialize\Serializer\Json::class, $this->serializerMock], [InterpretationStrategyInterface::class, $this->interpretationStrategyMock], ] ) @@ -234,6 +248,6 @@ private function addSessionMessages() $this->cookieManagerMock->expects($this->any()) ->method('getCookie') - ->willReturn(\Zend_Json::encode($cookieMessages)); + ->willReturn(json_encode($cookieMessages)); } } diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php b/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php index 5ba4b5194c71f..a83de07443e95 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php +++ b/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php @@ -107,7 +107,7 @@ public function testLoadDefault() $this->assertNotEmpty($this->model->getTemplateText()); $this->assertNotEmpty($this->model->getTemplateSubject()); $this->assertNotEmpty($this->model->getOrigTemplateVariables()); - $this->assertInternalType('array', \Zend_Json::decode($this->model->getOrigTemplateVariables())); + $this->assertInternalType('array', json_decode($this->model->getOrigTemplateVariables(), true)); } /** diff --git a/dev/tests/integration/testsuite/Magento/ImportExport/Block/Adminhtml/Import/Edit/BeforeTest.php b/dev/tests/integration/testsuite/Magento/ImportExport/Block/Adminhtml/Import/Edit/BeforeTest.php index 6043926367553..e6fe0b788f20d 100644 --- a/dev/tests/integration/testsuite/Magento/ImportExport/Block/Adminhtml/Import/Edit/BeforeTest.php +++ b/dev/tests/integration/testsuite/Magento/ImportExport/Block/Adminhtml/Import/Edit/BeforeTest.php @@ -90,7 +90,7 @@ protected function setUp() public function testGetEntityBehaviors() { $actualEntities = $this->_model->getEntityBehaviors(); - $expectedEntities = \Zend_Json::encode($this->_expectedEntities); + $expectedEntities = json_encode($this->_expectedEntities); $this->assertEquals($expectedEntities, $actualEntities); } @@ -102,7 +102,7 @@ public function testGetEntityBehaviors() public function testGetUniqueBehaviors() { $actualBehaviors = $this->_model->getUniqueBehaviors(); - $expectedBehaviors = \Zend_Json::encode($this->_expectedBehaviors); + $expectedBehaviors = json_encode($this->_expectedBehaviors); $this->assertEquals($expectedBehaviors, $actualBehaviors); } }