-
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
Remove zend json from the test suite #10320
Conversation
- replace with direct calls to json_decode and json_encode as these are test cases
- Mark AbstractController to ignore CouplingBetweenObjects - Set the same json_decode default that Zend_Json uses
@@ -268,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); |
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 just json_*
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.
@@ -15,6 +15,7 @@ | |||
|
|||
/** | |||
* @SuppressWarnings(PHPMD.NumberOfChildren) | |||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
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.
Adding SuppressWarnings, specially for Coupling, is generally considered a bad practice.
Did you add this as a result of tests execution? As it looks like that you have added same amount of dependencies as removed.
Usually in such cases refactoring has to be done to decouple objects
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.
@ishakhsuvarov I added this as the static test limit got hit because of adding in https://github.com/magento/magento2/pull/10320/files#diff-22fb93f06b955235735842cbdd6c2ab3R274 which I am still not sure about since this is inside the test framework itself.
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.
But at the same time you have decoupled this class from \Zend_Json
and \Zend_Json_Exception
. So to me it looks like that same coupling value should be in place after your changes.
Am I missing something?
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.
I am not sure myself. https://travis-ci.org/dmanners/magento2/jobs/257261073 that was the failure. I wonder if PHPMD runs from a diff of classes changed?
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.
Yes, it is executed from a diff, looks like it was already broken before.
I will look into the possible ways to reduce coupling for this class.
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.
Thanks, let me know if I can help out here.
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.
I've added some changes, which reduced coupling, in a way, which seems reasonable to me. Going to proceed with the merge now. Please let me know if it's ok from your perspective.
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.
Yeah those changes seem good to me still not 100% sure why that change fixes the static check, but I can live with not knowing that currently 👍
- Attempt to reduce coupling between objects
- Fixed unit test for the integration tests framework
$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 comment
The 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 comment
The 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 comment
The 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 comment
The 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.
@@ -268,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); |
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.
$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 comment
The 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.
Description
Since Zend_Json is at EOL we should replace the usage of
\Magento\Framework\Serialize\Serializer\Json
when required. In this PR I have removed the usage ofZend_Json
from the test suite.Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist