Skip to content

[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

Merged

Conversation

eduard13
Copy link
Contributor

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 (*)

  1. ...
  2. ...

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@eduard13 eduard13 requested a review from paliarush as a code owner December 18, 2019 13:02
@m2-assistant
Copy link

m2-assistant bot commented Dec 18, 2019

Hi @eduard13. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@magento-engcom-team magento-engcom-team added Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner labels Dec 18, 2019
@dmytro-ch dmytro-ch self-assigned this Dec 18, 2019
@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch, thank you for the review.
ENGCOM-6499 has been created to process this Pull Request
✳️ @dmytro-ch, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

Copy link
Contributor

@dmytro-ch dmytro-ch left a 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?

@eduard13
Copy link
Contributor Author

Hi @dmytro-ch, already did.
Thank you.

@dmytro-ch dmytro-ch added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: test coverage labels Dec 18, 2019
@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch, thank you for the review.
ENGCOM-6499 has been created to process this Pull Request

@magento magento deleted a comment from magento-engcom-team Dec 18, 2019
@magento magento deleted a comment from magento-engcom-team Dec 18, 2019
Copy link
Contributor

@lbajsarowicz lbajsarowicz left a 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.

Comment on lines 99 to 119
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([]);
}
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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]);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@eduard13
Copy link
Contributor Author

Hi @lbajsarowicz, thank you for reviewing this one, could you please review it again?
Thank you.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz, thank you for the review.
ENGCOM-6499 has been created to process this Pull Request

@engcom-Alfa
Copy link
Contributor

QA not applicable

@m2-assistant
Copy link

m2-assistant bot commented Dec 24, 2019

Hi @eduard13, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: test coverage Component: Checkout Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner Progress: accept Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants