Skip to content

Conversation

edenduong
Copy link
Contributor

@edenduong edenduong commented Dec 14, 2019

Description (*)

Increase Test Coverage

[Catalog] Cover Component/FilterFactory by Unit Test

Cover Class Magento\Catalog\Ui\Component\FilterFactory

Fixed Issues (if relevant)

Manual testing scenarios (*)

vendor/bin/phpunit app/code/Magento/Catalog/Test/Unit/Ui/Component/FilterFactoryTest.php

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 akaplya as a code owner December 14, 2019 12:07
@m2-assistant
Copy link

m2-assistant bot commented Dec 14, 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.4-develop instance - deploy vanilla Magento instance

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

@magento-engcom-team
Copy link
Contributor

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

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.

You may also Optimize imports in your PHPStorm to sort the imports with alphabetic order.

private $filterFactory;

/**
* @var UiComponentFactory|\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.

Alias \PHPUnit_Framework_MockObject_MockObject as MockObject


use PHPUnit\Framework\TestCase;
use Magento\Catalog\Ui\Component\FilterFactory;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't really need to suffix with Helper. ObjectManager is quite clear.

Comment on lines 64 to 73
[
[
'value' => 1,
'label' => 'Black',
],
[
'value' => 2,
'label' => 'White',
]
]
Copy link
Contributor

Choose a reason for hiding this comment

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

You can extract that to private const STUB_COLOR_OPTIONS for example.

Comment on lines 81 to 88
[
'value' => 1,
'label' => 'Black',
],
[
'value' => 2,
'label' => 'White',
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Then refer to that STUB.

$attributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
->setMethods(['usesSource', 'getSource'])
->getMockForAbstractClass();
$attributeMock->method('getAttributeCode')->willReturn('color');
Copy link
Contributor

Choose a reason for hiding this comment

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

Also - extract that to private const STUB_ATTRIBUTE_CODE

]
],
'caption' => (string)__('Select...'),
'dataScope' => 'color',
Copy link
Contributor

Choose a reason for hiding this comment

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

Refer to STUB_ATTRIBUTE_CODE

@edenduong
Copy link
Contributor Author

Hi @lbajsarowicz: Thank you. I have changed the source code. Please check it.

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.

I haven't expected that kind of stub, but it's also fine.
Last replacement and I'll accept the PR.

$sourceMock->method('getAllOptions')->willReturn(self::STUB_ATTRIBUTE['all_options']);
$this->componentFactoryMock->expects($this->once())
->method('create')
->with('color', 'filterSelect', [
Copy link
Contributor

Choose a reason for hiding this comment

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

self::STUB_ATTRIBUTE['attribute_code']

@edenduong
Copy link
Contributor Author

I have changed it. Please check it again. Thanks @lbajsarowicz

@edenduong
Copy link
Contributor Author

Could you please take a look? Thanks @lbajsarowicz

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.

Thank you for your contribution.

@magento-engcom-team
Copy link
Contributor

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

@engcom-Delta engcom-Delta self-assigned this Dec 17, 2019
@engcom-Delta
Copy link
Contributor

Notice: QA not applicable

@m2-assistant
Copy link

m2-assistant bot commented Dec 18, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment