Skip to content
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

Unit Test to cover class \Magento\Captcha\CustomerData\Captcha #25686

Conversation

edenduong
Copy link
Contributor

Description (*)

Unit Test to cover class \Magento\Captcha\CustomerData\Captcha

  • Test getSectionData() when user is login and require captcha

Fixed Issues (if relevant)

Manual testing scenarios (*)

Covered by Unit Test

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)

@edenduong edenduong requested a review from kokoc as a code owner November 21, 2019 14:31
@m2-assistant
Copy link

m2-assistant bot commented Nov 21, 2019

Hi @edenduong. 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.3-develop instance - deploy vanilla Magento instance

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

class CaptchaTest extends \PHPUnit\Framework\TestCase
{
/**
* @var CaptchaHelper | \PHPUnit_Framework_MockObject_MockObject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary spaces

/**
* Test getSectionData() when user is login and require captcha
*/
public function testGetSectionData()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name should be more explanatory, current is too generic.

@ghost ghost assigned lbajsarowicz Nov 22, 2019
@edenduong
Copy link
Contributor Author

Hi @lbajsarowicz: I have changed it. Please check it again.

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.

Several changes, in my opinion, are still necessary. Not crucial ones, but still something that needs to be done.

$this->customerSession->expects($this->any())->method('isLoggedIn')
->willReturn(true);

$this->customerData = $this->createMock(CustomerData::class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are instantiating mock there and using only for this test, use local variable instead of class property.

*
* Class \Magento\Captcha\Test\Unit\CustomerData\CaptchaTest
*/
class CaptchaTest extends \PHPUnit\Framework\TestCase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import the class.

/**
* Test class to cover \Magento\Captcha\CustomerData\Captcha
*
* Class \Magento\Captcha\Test\Unit\CustomerData\CaptchaTest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is completely redundant.

/**
* @var CaptchaHelper|\PHPUnit_Framework_MockObject_MockObject
*/
private $helper;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's highly recommended to mark that it's still mock, not the real implementation by renaming the property to helperMock

/**
* @var CustomerSession|\PHPUnit_Framework_MockObject_MockObject
*/
private $customerSession;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Append Mock to name to mark that's not real implementation.

/**
* @var CustomerData|\PHPUnit_Framework_MockObject_MockObject
*/
private $customerData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Append Mock to name to mark that's not real implementation.

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.

Now it's fine. Thanks for your contribution!

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz, thank you for the review.
ENGCOM-6322 has been created to process this Pull Request
✳️ @lbajsarowicz, 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

@engcom-Bravo engcom-Bravo self-assigned this Nov 24, 2019
@engcom-Bravo engcom-Bravo added the Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests label Nov 24, 2019
@engcom-Bravo
Copy link
Contributor

✔️ QA Passed

@engcom-Bravo engcom-Bravo added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests labels Nov 24, 2019
@engcom-Foxtrot engcom-Foxtrot self-assigned this Nov 25, 2019
@m2-assistant
Copy link

m2-assistant bot commented Nov 26, 2019

Hi @edenduong, 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.

@magento-engcom-team magento-engcom-team added this to the Release: 2.3.5 milestone Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants