3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Swatches \Test \Unit \Block \LayeredNavigation ;
7
9
10
+ use Magento \Catalog \Model \Layer \Filter \AbstractFilter ;
11
+ use Magento \Catalog \Model \Layer \Filter \Item ;
12
+ use Magento \Catalog \Model \ResourceModel \Layer \Filter \AttributeFactory ;
13
+ use Magento \Eav \Model \Entity \Attribute ;
14
+ use Magento \Eav \Model \Entity \Attribute \Option ;
15
+ use Magento \Framework \App \RequestInterface ;
16
+ use Magento \Framework \Url ;
17
+ use Magento \Framework \View \Element \Template \Context ;
18
+ use Magento \Swatches \Block \LayeredNavigation \RenderLayered ;
19
+ use Magento \Swatches \Helper \Data ;
20
+ use Magento \Swatches \Helper \Media ;
21
+ use Magento \Theme \Block \Html \Pager ;
22
+ use PHPUnit \Framework \MockObject \MockObject ;
23
+ use PHPUnit \Framework \TestCase ;
24
+
8
25
/**
9
26
* Class RenderLayered Render Swatches at Layered Navigation
10
27
*
11
28
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12
29
*/
13
- class RenderLayeredTest extends \ PHPUnit \ Framework \ TestCase
30
+ class RenderLayeredTest extends TestCase
14
31
{
15
- /** @var \PHPUnit_Framework_MockObject_MockObject */
16
- protected $ contextMock ;
17
-
18
- /** @var \PHPUnit_Framework_MockObject_MockObject */
19
- protected $ requestMock ;
20
-
21
- /** @var \PHPUnit_Framework_MockObject_MockObject */
22
- protected $ urlBuilder ;
23
-
24
- /** @var \PHPUnit_Framework_MockObject_MockObject */
25
- protected $ eavAttributeMock ;
26
-
27
- /** @var \PHPUnit_Framework_MockObject_MockObject */
28
- protected $ layerAttributeFactoryMock ;
29
-
30
- /** @var \PHPUnit_Framework_MockObject_MockObject */
31
- protected $ layerAttributeMock ;
32
-
33
- /** @var \PHPUnit_Framework_MockObject_MockObject */
34
- protected $ swatchHelperMock ;
35
-
36
- /** @var \PHPUnit_Framework_MockObject_MockObject */
37
- protected $ mediaHelperMock ;
38
-
39
- /** @var \PHPUnit_Framework_MockObject_MockObject */
40
- protected $ filterMock ;
41
-
42
- /** @var \PHPUnit_Framework_MockObject_MockObject */
43
- protected $ block ;
44
-
45
- protected function setUp ()
32
+ /**
33
+ * @var RenderLayered|MockObject
34
+ */
35
+ private $ block ;
36
+
37
+ /**
38
+ * @var Context|MockObject
39
+ */
40
+ private $ contextMock ;
41
+
42
+ /**
43
+ * @var RequestInterface|MockObject
44
+ */
45
+ private $ requestMock ;
46
+
47
+ /**
48
+ * @var Url|MockObject
49
+ */
50
+ private $ urlBuilder ;
51
+
52
+ /**
53
+ * @var Attribute|MockObject
54
+ */
55
+ private $ eavAttributeMock ;
56
+
57
+ /**
58
+ * @var AttributeFactory|MockObject
59
+ */
60
+ private $ layerAttributeFactoryMock ;
61
+
62
+ /**
63
+ * @var \Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute|MockObject
64
+ */
65
+ private $ layerAttributeMock ;
66
+
67
+ /**
68
+ * @var Data|MockObject
69
+ */
70
+ private $ swatchHelperMock ;
71
+
72
+ /**
73
+ * @var Media|MockObject
74
+ */
75
+ private $ mediaHelperMock ;
76
+
77
+ /**
78
+ * @var AbstractFilter|MockObject
79
+ */
80
+ private $ filterMock ;
81
+
82
+ /**
83
+ * @var Pager|MockObject
84
+ */
85
+ private $ htmlBlockPagerMock ;
86
+
87
+ protected function setUp (): void
46
88
{
47
- $ this ->contextMock = $ this ->createMock (\ Magento \ Framework \ View \ Element \ Template \ Context::class);
48
- $ this ->requestMock = $ this ->createMock (\ Magento \ Framework \ App \ RequestInterface::class);
89
+ $ this ->contextMock = $ this ->createMock (Context::class);
90
+ $ this ->requestMock = $ this ->createMock (RequestInterface::class);
49
91
$ this ->urlBuilder = $ this ->createPartialMock (
50
- \ Magento \ Framework \ Url::class,
92
+ Url::class,
51
93
['getCurrentUrl ' , 'getRedirectUrl ' , 'getUrl ' ]
52
94
);
53
- $ this ->contextMock ->expects ( $ this -> any ())-> method ('getRequest ' )->willReturn ($ this ->requestMock );
54
- $ this ->contextMock ->expects ( $ this -> any ())-> method ('getUrlBuilder ' )->willReturn ($ this ->urlBuilder );
55
- $ this ->eavAttributeMock = $ this ->createMock (\ Magento \ Eav \ Model \ Entity \ Attribute::class);
95
+ $ this ->contextMock ->method ('getRequest ' )->willReturn ($ this ->requestMock );
96
+ $ this ->contextMock ->method ('getUrlBuilder ' )->willReturn ($ this ->urlBuilder );
97
+ $ this ->eavAttributeMock = $ this ->createMock (Attribute::class);
56
98
$ this ->layerAttributeFactoryMock = $ this ->createPartialMock (
57
- \ Magento \ Catalog \ Model \ ResourceModel \ Layer \ Filter \ AttributeFactory::class,
99
+ AttributeFactory::class,
58
100
['create ' ]
59
101
);
60
102
$ this ->layerAttributeMock = $ this ->createPartialMock (
61
103
\Magento \Catalog \Model \ResourceModel \Layer \Filter \Attribute::class,
62
104
['getCount ' ]
63
105
);
64
- $ this ->swatchHelperMock = $ this ->createMock (\Magento \Swatches \Helper \Data::class);
65
- $ this ->mediaHelperMock = $ this ->createMock (\Magento \Swatches \Helper \Media::class);
66
- $ this ->filterMock = $ this ->createMock (\Magento \Catalog \Model \Layer \Filter \AbstractFilter::class);
106
+ $ this ->swatchHelperMock = $ this ->createMock (Data::class);
107
+ $ this ->mediaHelperMock = $ this ->createMock (Media::class);
108
+ $ this ->filterMock = $ this ->createMock (AbstractFilter::class);
109
+ $ this ->htmlBlockPagerMock = $ this ->createMock (Pager::class);
67
110
68
- $ this ->block = $ this ->getMockBuilder (\ Magento \ Swatches \ Block \ LayeredNavigation \ RenderLayered::class)
111
+ $ this ->block = $ this ->getMockBuilder (RenderLayered::class)
69
112
->setMethods (['filter ' , 'eavAttribute ' ])
70
113
->setConstructorArgs (
71
114
[
@@ -75,6 +118,7 @@ protected function setUp()
75
118
$ this ->swatchHelperMock ,
76
119
$ this ->mediaHelperMock ,
77
120
[],
121
+ $ this ->htmlBlockPagerMock
78
122
]
79
123
)
80
124
->getMock ();
@@ -92,13 +136,13 @@ public function testSetSwatchFilter()
92
136
93
137
public function testGetSwatchData ()
94
138
{
95
- /** @var \PHPUnit_Framework_MockObject_MockObject $item */
96
- $ item1 = $ this ->createMock (\ Magento \ Catalog \ Model \ Layer \ Filter \ Item::class);
97
- $ item2 = $ this ->createMock (\ Magento \ Catalog \ Model \ Layer \ Filter \ Item::class);
98
- $ item3 = $ this ->createMock (\ Magento \ Catalog \ Model \ Layer \ Filter \ Item::class);
99
- $ item4 = $ this ->createMock (\ Magento \ Catalog \ Model \ Layer \ Filter \ Item::class);
139
+ /** @var MockObject $item */
140
+ $ item1 = $ this ->createMock (Item::class);
141
+ $ item2 = $ this ->createMock (Item::class);
142
+ $ item3 = $ this ->createMock (Item::class);
143
+ $ item4 = $ this ->createMock (Item::class);
100
144
101
- $ item1 ->expects ( $ this -> any ())-> method ('__call ' )->withConsecutive (
145
+ $ item1 ->method ('__call ' )->withConsecutive (
102
146
['getValue ' ],
103
147
['getCount ' ],
104
148
['getValue ' ],
@@ -112,17 +156,17 @@ public function testGetSwatchData()
112
156
'Yellow '
113
157
);
114
158
115
- $ item2 ->expects ( $ this -> any ())-> method ('__call ' )->with ('getValue ' )->willReturn ('blue ' );
159
+ $ item2 ->method ('__call ' )->with ('getValue ' )->willReturn ('blue ' );
116
160
117
- $ item3 ->expects ( $ this -> any ())-> method ('__call ' )->withConsecutive (
161
+ $ item3 ->method ('__call ' )->withConsecutive (
118
162
['getValue ' ],
119
163
['getCount ' ]
120
164
)->willReturnOnConsecutiveCalls (
121
165
'red ' ,
122
166
0
123
167
);
124
168
125
- $ item4 ->expects ( $ this -> any ())-> method ('__call ' )->withConsecutive (
169
+ $ item4 ->method ('__call ' )->withConsecutive (
126
170
['getValue ' ],
127
171
['getCount ' ],
128
172
['getValue ' ],
@@ -145,23 +189,23 @@ public function testGetSwatchData()
145
189
146
190
$ this ->block ->method ('filter ' )->willReturn ($ this ->filterMock );
147
191
148
- $ option1 = $ this ->createMock (\ Magento \ Eav \ Model \ Entity \ Attribute \ Option::class);
149
- $ option1 ->expects ( $ this -> any ())-> method ('getValue ' )->willReturn ('yellow ' );
192
+ $ option1 = $ this ->createMock (Option::class);
193
+ $ option1 ->method ('getValue ' )->willReturn ('yellow ' );
150
194
151
- $ option2 = $ this ->createMock (\ Magento \ Eav \ Model \ Entity \ Attribute \ Option::class);
152
- $ option2 ->expects ( $ this -> any ())-> method ('getValue ' )->willReturn (null );
195
+ $ option2 = $ this ->createMock (Option::class);
196
+ $ option2 ->method ('getValue ' )->willReturn (null );
153
197
154
- $ option3 = $ this ->createMock (\ Magento \ Eav \ Model \ Entity \ Attribute \ Option::class);
155
- $ option3 ->expects ( $ this -> any ())-> method ('getValue ' )->willReturn ('red ' );
198
+ $ option3 = $ this ->createMock (Option::class);
199
+ $ option3 ->method ('getValue ' )->willReturn ('red ' );
156
200
157
- $ option4 = $ this ->createMock (\ Magento \ Eav \ Model \ Entity \ Attribute \ Option::class);
158
- $ option4 ->expects ( $ this -> any ())-> method ('getValue ' )->willReturn ('green ' );
201
+ $ option4 = $ this ->createMock (Option::class);
202
+ $ option4 ->method ('getValue ' )->willReturn ('green ' );
159
203
160
204
$ eavAttribute = $ this ->createMock (\Magento \Catalog \Model \ResourceModel \Eav \Attribute::class);
161
205
$ eavAttribute ->expects ($ this ->once ())
162
206
->method ('getOptions ' )
163
207
->willReturn ([$ option1 , $ option2 , $ option3 , $ option4 ]);
164
- $ eavAttribute ->expects ( $ this -> any ())-> method ('getIsFilterable ' )->willReturn (0 );
208
+ $ eavAttribute ->method ('getIsFilterable ' )->willReturn (0 );
165
209
166
210
$ this ->filterMock ->expects ($ this ->once ())->method ('getAttributeModel ' )->willReturn ($ eavAttribute );
167
211
$ this ->block ->method ('eavAttribute ' )->willReturn ($ eavAttribute );
@@ -184,7 +228,7 @@ public function testGetSwatchDataException()
184
228
{
185
229
$ this ->block ->method ('filter ' )->willReturn ($ this ->filterMock );
186
230
$ this ->block ->setSwatchFilter ($ this ->filterMock );
187
- $ this ->expectException (' \RuntimeException ' );
231
+ $ this ->expectException (\RuntimeException::class );
188
232
$ this ->block ->getSwatchData ();
189
233
}
190
234
0 commit comments