17
17
use Magento \Catalog \Model \ResourceModel \Product \Compare \Item \Collection ;
18
18
use Magento \Framework \App \Config \ScopeConfigInterface ;
19
19
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
20
+ use Magento \Framework \UrlInterface ;
21
+ use Magento \Store \Model \StoreManagerInterface ;
20
22
use Magento \Store \Model \Website ;
21
23
use PHPUnit \Framework \MockObject \MockObject ;
22
24
use PHPUnit \Framework \TestCase ;
23
- use Magento \Store \Model \StoreManagerInterface ;
24
25
26
+ /**
27
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
28
+ */
25
29
class CompareProductsTest extends TestCase
26
30
{
27
31
/**
@@ -64,6 +68,11 @@ class CompareProductsTest extends TestCase
64
68
*/
65
69
private $ websiteMock ;
66
70
71
+ /**
72
+ * @var UrlInterface|MockObject
73
+ */
74
+ private $ urlBuilder ;
75
+
67
76
/**
68
77
* @var array
69
78
*/
@@ -88,6 +97,9 @@ protected function setUp(): void
88
97
$ this ->scopeConfigMock = $ this ->getMockBuilder (ScopeConfigInterface::class)
89
98
->disableOriginalConstructor ()
90
99
->getMockForAbstractClass ();
100
+ $ this ->urlBuilder = $ this ->getMockBuilder (UrlInterface::class)
101
+ ->disableOriginalConstructor ()
102
+ ->getMock ();
91
103
92
104
$ this ->storeManagerMock = $ this ->getMockBuilder (
93
105
StoreManagerInterface::class
@@ -97,7 +109,7 @@ protected function setUp(): void
97
109
$ this ->websiteMock = $ this ->getMockBuilder (
98
110
Website::class
99
111
)->onlyMethods (
100
- ['getId ' , ]
112
+ ['getId ' ]
101
113
)->disableOriginalConstructor ()
102
114
->getMock ();
103
115
@@ -110,8 +122,8 @@ protected function setUp(): void
110
122
'productUrl ' => $ this ->productUrlMock ,
111
123
'outputHelper ' => $ this ->outputHelperMock ,
112
124
'scopeConfig ' => $ this ->scopeConfigMock ,
113
- 'storeManager ' => $ this ->storeManagerMock
114
-
125
+ 'storeManager ' => $ this ->storeManagerMock ,
126
+ ' urlBuilder ' => $ this -> urlBuilder
115
127
]
116
128
);
117
129
}
@@ -219,9 +231,10 @@ public function testGetSectionData()
219
231
->method ('getItemCollection ' )
220
232
->willReturn ($ itemCollectionMock );
221
233
222
- $ this ->helperMock ->expects ($ this ->once ())
223
- ->method ('getListUrl ' )
234
+ $ this ->urlBuilder ->expects ($ this ->once ())
235
+ ->method ('getUrl ' )
224
236
->willReturn ('http://list.url ' );
237
+
225
238
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('getWebsite ' )->willReturn ($ this ->websiteMock );
226
239
$ this ->websiteMock ->expects ($ this ->any ())->method ('getId ' )->willReturn (1 );
227
240
$ this ->assertEquals (
@@ -269,8 +282,8 @@ public function testGetSectionDataNoItems()
269
282
$ this ->helperMock ->expects ($ this ->never ())
270
283
->method ('getItemCollection ' );
271
284
272
- $ this ->helperMock ->expects ($ this ->once ())
273
- ->method ('getListUrl ' )
285
+ $ this ->urlBuilder ->expects ($ this ->once ())
286
+ ->method ('getUrl ' )
274
287
->willReturn ('http://list.url ' );
275
288
276
289
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('getWebsite ' )->willReturn ($ this ->websiteMock );
@@ -314,8 +327,8 @@ public function testGetSectionDataSingleItem()
314
327
->method ('getItemCollection ' )
315
328
->willReturn ($ itemCollectionMock );
316
329
317
- $ this ->helperMock ->expects ($ this ->once ())
318
- ->method ('getListUrl ' )
330
+ $ this ->urlBuilder ->expects ($ this ->once ())
331
+ ->method ('getUrl ' )
319
332
->willReturn ('http://list.url ' );
320
333
321
334
$ this ->assertEquals (
0 commit comments