-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove zend json from the test suite #10320
Changes from all commits
474effb
db624ff
1ad0251
2867a11
8cd3d3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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->getMock(\Magento\Framework\Message\Manager::class, [], [], '', false); | ||
$this->cookieManagerMock = $this->getMock(CookieManagerInterface::class, [], [], '', false); | ||
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->serializerMock->expects($this->any())->method('unserialize')->willReturnCallback( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I love this approach for mocking methods There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to think that using real dependency in this case would be a better idea, however we usually stick to mocking all the stuff in the unit tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah when it comes to mocking or not mocking I am not so sure what is "best" but the callback here is a nice idea specifically for this mock. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Such "mock" is practically equivalent to a real class 😉 I prefer tiny tests with small fixtures having mocks in form of returning plain values. Copy-pasting such callbacks to dozens of tests somewhat increases maintenance efforts. |
||
function ($serializedData) { | ||
return json_decode($serializedData, true); | ||
} | ||
); | ||
$this->interpretationStrategyMock = $this->getMock(InterpretationStrategyInterface::class, [], [], '', false); | ||
$this->interpretationStrategyMock->expects($this->any()) | ||
->method('interpret') | ||
|
@@ -58,6 +71,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], | ||
] | ||
) | ||
|
@@ -244,6 +258,6 @@ private function addSessionMessages() | |
|
||
$this->cookieManagerMock->expects($this->any()) | ||
->method('getCookie') | ||
->willReturn(\Zend_Json::encode($cookieMessages)); | ||
->willReturn(json_encode($cookieMessages)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I was not sure if I should use the class
\Magento\Framework\Serialize\Serializer\Json
here or justjson_*
but I thought since this was using the cookie interface it should also use the serializer. Happy to make a change if it is thought best to do something else.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we suppress exception anyway here I would simplify implementation and got rid of try/catch at all. But as it is just testing code it does not really matter.