Skip to content

Commit bbfdb08

Browse files
committed
Refactor code
1 parent 7553225 commit bbfdb08

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

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

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,45 @@
77

88
namespace Magento\Catalog\Test\Unit\Ui\Component;
99

10-
use PHPUnit\Framework\TestCase;
11-
use Magento\Catalog\Ui\Component\FilterFactory;
12-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13-
use Magento\Framework\View\Element\UiComponentFactory;
1410
use Magento\Catalog\Api\Data\ProductAttributeInterface;
11+
use Magento\Catalog\Ui\Component\FilterFactory;
1512
use Magento\Eav\Model\Entity\Attribute\Source\SourceInterface;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1614
use Magento\Framework\View\Element\UiComponent\ContextInterface;
15+
use Magento\Framework\View\Element\UiComponentFactory;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
1718

1819
class FilterFactoryTest extends TestCase
1920
{
21+
/**
22+
* Stub attribute
23+
*/
24+
private const STUB_ATTRIBUTE = [
25+
'attribute_code' => 'color',
26+
'default_frontend_label' => 'Color',
27+
'uses_source' => 'Color',
28+
'source_model' => 'getSourceModel value',
29+
'frontend_input' => 'select',
30+
'all_options' => [
31+
[
32+
'value' => 1,
33+
'label' => 'Black',
34+
],
35+
[
36+
'value' => 2,
37+
'label' => 'White',
38+
]
39+
]
40+
];
41+
2042
/**
2143
* @var FilterFactory
2244
*/
2345
private $filterFactory;
2446

2547
/**
26-
* @var UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject
48+
* @var UiComponentFactory|MockObject
2749
*/
2850
private $componentFactoryMock;
2951

@@ -32,7 +54,7 @@ class FilterFactoryTest extends TestCase
3254
*/
3355
protected function setUp()
3456
{
35-
$objectManager = new ObjectManagerHelper($this);
57+
$objectManager = new ObjectManager($this);
3658

3759
$this->componentFactoryMock = $this->createMock(UiComponentFactory::class);
3860

@@ -53,43 +75,24 @@ public function testCreateWithUseSourceAttribute()
5375
$attributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
5476
->setMethods(['usesSource', 'getSource'])
5577
->getMockForAbstractClass();
56-
$attributeMock->method('getAttributeCode')->willReturn('color');
57-
$attributeMock->method('getDefaultFrontendLabel')->willReturn('Color');
58-
$attributeMock->method('usesSource')->willReturn(true);
59-
$attributeMock->method('getSourceModel')->willReturn('getSourceModel value');
60-
$attributeMock->method('getFrontendInput')->willReturn('select');
78+
$attributeMock->method('getAttributeCode')->willReturn(self::STUB_ATTRIBUTE['attribute_code']);
79+
$attributeMock->method('getDefaultFrontendLabel')
80+
->willReturn(self::STUB_ATTRIBUTE['default_frontend_label']);
81+
$attributeMock->method('usesSource')->willReturn(self::STUB_ATTRIBUTE['uses_source']);
82+
$attributeMock->method('getSourceModel')->willReturn(self::STUB_ATTRIBUTE['source_model']);
83+
$attributeMock->method('getFrontendInput')->willReturn(self::STUB_ATTRIBUTE['frontend_input']);
6184
$sourceMock = $this->createMock(SourceInterface::class);
6285
$attributeMock->method('getSource')->willReturn($sourceMock);
63-
$sourceMock->method('getAllOptions')->willReturn(
64-
[
65-
[
66-
'value' => 1,
67-
'label' => 'Black',
68-
],
69-
[
70-
'value' => 2,
71-
'label' => 'White',
72-
]
73-
]
74-
);
86+
$sourceMock->method('getAllOptions')->willReturn(self::STUB_ATTRIBUTE['all_options']);
7587
$this->componentFactoryMock->expects($this->once())
7688
->method('create')
7789
->with('color', 'filterSelect', [
7890
'data' => [
7991
'config' => [
80-
'options' => [
81-
[
82-
'value' => 1,
83-
'label' => 'Black',
84-
],
85-
[
86-
'value' => 2,
87-
'label' => 'White',
88-
]
89-
],
92+
'options' => self::STUB_ATTRIBUTE['all_options'],
9093
'caption' => (string)__('Select...'),
91-
'dataScope' => 'color',
92-
'label' => (string)__('Color'),
94+
'dataScope' => self::STUB_ATTRIBUTE['attribute_code'],
95+
'label' => (string)__(self::STUB_ATTRIBUTE['default_frontend_label']),
9396
]
9497
],
9598
'context' => $contextMock

0 commit comments

Comments
 (0)