Skip to content

Commit

Permalink
MAGETWO-80179: Remove zend json from the test suite #10320
Browse files Browse the repository at this point in the history
  • Loading branch information
irenelagno committed Sep 29, 2017
1 parent 005ec16 commit 422a16e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -103,7 +103,7 @@ public function dispatch($uri)
/**
* Request getter
*
* @return \Magento\TestFramework\Request
* @return \Magento\Framework\App\RequestInterface
*/
public function getRequest()
{
Expand All @@ -116,7 +116,7 @@ public function getRequest()
/**
* Response getter
*
* @return \Magento\TestFramework\Response
* @return \Magento\Framework\App\ResponseInterface
*/
public function getResponse()
{
Expand Down Expand Up @@ -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 = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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],
]
)
Expand Down Expand Up @@ -234,6 +248,6 @@ private function addSessionMessages()

$this->cookieManagerMock->expects($this->any())
->method('getCookie')
->willReturn(\Zend_Json::encode($cookieMessages));
->willReturn(json_encode($cookieMessages));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
}

0 comments on commit 422a16e

Please sign in to comment.