-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[Checkout] Covering the ResetQuoteAddresses by Unit Test #26096
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
[Checkout] Covering the ResetQuoteAddresses by Unit Test #26096
Conversation
Hi @eduard13. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
Hi @dmytro-ch, thank you for the review.
|
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.
Hi @eduard13, could you please fix the static test recommendations?
Hi @dmytro-ch, already did. |
Hi @dmytro-ch, thank you for the review. |
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.
Please get through the recommendations. In my opinion you tried to cover too much logic in single Unit Test.
if ($quoteHasAddresses) { | ||
$address = $this->createPartialMock(Address::class, ['getId']); | ||
|
||
$address->expects($this->any()) | ||
->method('getId') | ||
->willReturn(1); | ||
|
||
$addresses = [$address]; | ||
|
||
$this->quoteMock->expects($this->any()) | ||
->method('getAllAddresses') | ||
->will($this->returnValue($addresses)); | ||
|
||
$this->quoteMock->expects($this->exactly(count($addresses))) | ||
->method('removeAddress') | ||
->willReturnSelf(); | ||
} else { | ||
$this->quoteMock->expects($this->any()) | ||
->method('getAllAddresses') | ||
->willReturn([]); | ||
} |
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.
Having this conditional logic in Unit Test means that you are trying to do too much inside the single test.
Split that into two tests - for example:
- testClearingAddressesSuccessfullyFromEmptyQuoteWithAddress
- testClearingAddressesSuccessfullyFromEmptyQuoteWithoutAddress
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.
Moved the logic into a separated test cases. 👌
|
||
$address->expects($this->any()) | ||
->method('getId') | ||
->willReturn(1); |
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.
Try to avoid Magic Numbers - use private const STUB_ADDRESS_ID
instead.
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.
Updated. 👌
if ($isVirtualQuote && $extensionAttributes) { | ||
$this->extensionAttributesMock->expects($this->any()) | ||
->method('getShippingAssignments') | ||
->willReturn([1]); |
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.
If that 1
means the same ID that STUB_ADDRESS_ID
- put that reference there instead of magic number that has unclear meaning.
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.
Actually no, so I moved it to a const as well.
Hi @lbajsarowicz, thank you for reviewing this one, could you please review it again? |
Hi @lbajsarowicz, thank you for the review. |
QA not applicable |
Hi @eduard13, thank you for your contribution! |
Description (*)
This PR is improving the test coverage for Checkout module, by covering the
Magento\Checkout\Plugin\Model\Quote\ResetQuoteAddresses
by Unit Tests.Fixed Issues (if relevant)
N/A
Manual testing scenarios (*)
Questions or comments
Contribution checklist (*)