33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
7+
68namespace Magento \Swatches \Test \Unit \Block \LayeredNavigation ;
79
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+
825/**
926 * Class RenderLayered Render Swatches at Layered Navigation
1027 *
1128 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1229 */
13- class RenderLayeredTest extends \ PHPUnit \ Framework \ TestCase
30+ class RenderLayeredTest extends TestCase
1431{
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
4688 {
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);
4991 $ this ->urlBuilder = $ this ->createPartialMock (
50- \ Magento \ Framework \ Url::class,
92+ Url::class,
5193 ['getCurrentUrl ' , 'getRedirectUrl ' , 'getUrl ' ]
5294 );
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);
5698 $ this ->layerAttributeFactoryMock = $ this ->createPartialMock (
57- \ Magento \ Catalog \ Model \ ResourceModel \ Layer \ Filter \ AttributeFactory::class,
99+ AttributeFactory::class,
58100 ['create ' ]
59101 );
60102 $ this ->layerAttributeMock = $ this ->createPartialMock (
61103 \Magento \Catalog \Model \ResourceModel \Layer \Filter \Attribute::class,
62104 ['getCount ' ]
63105 );
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);
67110
68- $ this ->block = $ this ->getMockBuilder (\ Magento \ Swatches \ Block \ LayeredNavigation \ RenderLayered::class)
111+ $ this ->block = $ this ->getMockBuilder (RenderLayered::class)
69112 ->setMethods (['filter ' , 'eavAttribute ' ])
70113 ->setConstructorArgs (
71114 [
@@ -75,6 +118,7 @@ protected function setUp()
75118 $ this ->swatchHelperMock ,
76119 $ this ->mediaHelperMock ,
77120 [],
121+ $ this ->htmlBlockPagerMock
78122 ]
79123 )
80124 ->getMock ();
@@ -92,13 +136,13 @@ public function testSetSwatchFilter()
92136
93137 public function testGetSwatchData ()
94138 {
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);
100144
101- $ item1 ->expects ( $ this -> any ())-> method ('__call ' )->withConsecutive (
145+ $ item1 ->method ('__call ' )->withConsecutive (
102146 ['getValue ' ],
103147 ['getCount ' ],
104148 ['getValue ' ],
@@ -112,17 +156,17 @@ public function testGetSwatchData()
112156 'Yellow '
113157 );
114158
115- $ item2 ->expects ( $ this -> any ())-> method ('__call ' )->with ('getValue ' )->willReturn ('blue ' );
159+ $ item2 ->method ('__call ' )->with ('getValue ' )->willReturn ('blue ' );
116160
117- $ item3 ->expects ( $ this -> any ())-> method ('__call ' )->withConsecutive (
161+ $ item3 ->method ('__call ' )->withConsecutive (
118162 ['getValue ' ],
119163 ['getCount ' ]
120164 )->willReturnOnConsecutiveCalls (
121165 'red ' ,
122166 0
123167 );
124168
125- $ item4 ->expects ( $ this -> any ())-> method ('__call ' )->withConsecutive (
169+ $ item4 ->method ('__call ' )->withConsecutive (
126170 ['getValue ' ],
127171 ['getCount ' ],
128172 ['getValue ' ],
@@ -145,23 +189,23 @@ public function testGetSwatchData()
145189
146190 $ this ->block ->method ('filter ' )->willReturn ($ this ->filterMock );
147191
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 ' );
150194
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 );
153197
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 ' );
156200
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 ' );
159203
160204 $ eavAttribute = $ this ->createMock (\Magento \Catalog \Model \ResourceModel \Eav \Attribute::class);
161205 $ eavAttribute ->expects ($ this ->once ())
162206 ->method ('getOptions ' )
163207 ->willReturn ([$ option1 , $ option2 , $ option3 , $ option4 ]);
164- $ eavAttribute ->expects ( $ this -> any ())-> method ('getIsFilterable ' )->willReturn (0 );
208+ $ eavAttribute ->method ('getIsFilterable ' )->willReturn (0 );
165209
166210 $ this ->filterMock ->expects ($ this ->once ())->method ('getAttributeModel ' )->willReturn ($ eavAttribute );
167211 $ this ->block ->method ('eavAttribute ' )->willReturn ($ eavAttribute );
@@ -184,7 +228,7 @@ public function testGetSwatchDataException()
184228 {
185229 $ this ->block ->method ('filter ' )->willReturn ($ this ->filterMock );
186230 $ this ->block ->setSwatchFilter ($ this ->filterMock );
187- $ this ->expectException (' \RuntimeException ' );
231+ $ this ->expectException (\RuntimeException::class );
188232 $ this ->block ->getSwatchData ();
189233 }
190234
0 commit comments