- Notifications
You must be signed in to change notification settings - Fork 9.4k
[Catalog] Cover Component/FilterFactory by Unit Test #26042
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
[Catalog] Cover Component/FilterFactory by Unit Test #26042
Conversation
Hi @edenduong. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
Hi @kalpmehta, 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.
You may also Optimize imports
in your PHPStorm to sort the imports with alphabetic order.
private $filterFactory; | ||
| ||
/** | ||
* @var UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject |
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.
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; |
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.
You don't really need to suffix with Helper
. ObjectManager
is quite clear.
[ | ||
[ | ||
'value' => 1, | ||
'label' => 'Black', | ||
], | ||
[ | ||
'value' => 2, | ||
'label' => 'White', | ||
] | ||
] |
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.
You can extract that to private const STUB_COLOR_OPTIONS
for example.
[ | ||
'value' => 1, | ||
'label' => 'Black', | ||
], | ||
[ | ||
'value' => 2, | ||
'label' => 'White', | ||
] |
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.
Then refer to that STUB.
$attributeMock = $this->getMockBuilder(ProductAttributeInterface::class) | ||
->setMethods(['usesSource', 'getSource']) | ||
->getMockForAbstractClass(); | ||
$attributeMock->method('getAttributeCode')->willReturn('color'); |
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.
Also - extract that to private const STUB_ATTRIBUTE_CODE
] | ||
], | ||
'caption' => (string)__('Select...'), | ||
'dataScope' => 'color', |
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.
Refer to STUB_ATTRIBUTE_CODE
Hi @lbajsarowicz: Thank you. I have changed the source code. Please check it. |
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 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', [ |
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.
self::STUB_ATTRIBUTE['attribute_code']
I have changed it. Please check it again. Thanks @lbajsarowicz |
Could you please take a look? Thanks @lbajsarowicz |
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.
Thank you for your contribution.
Hi @lbajsarowicz, thank you for the review. |
Notice: QA not applicable |
Hi @edenduong, thank you for your contribution! |
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 (*)