9
9
10
10
use Magento \Backend \Helper \Data ;
11
11
use Magento \Catalog \Api \ProductRepositoryInterface ;
12
+ use Magento \Catalog \Model \ProductCategoryList ;
12
13
use Magento \Catalog \Model \ProductFactory ;
13
14
use Magento \Catalog \Model \ResourceModel \Product ;
14
15
use Magento \Directory \Model \CurrencyFactory ;
34
35
*/
35
36
class ProductTest extends TestCase
36
37
{
38
+ const STUB_CATEGORY_ID = 5 ;
37
39
/** @var SalesRuleProduct */
38
40
protected $ model ;
39
41
@@ -70,6 +72,9 @@ class ProductTest extends TestCase
70
72
/** @var Select|MockObject */
71
73
protected $ selectMock ;
72
74
75
+ /** @var MockObject|ProductCategoryList */
76
+ private $ productCategoryListMock ;
77
+
73
78
/**
74
79
* Setup the test
75
80
*/
@@ -138,6 +143,10 @@ protected function setUp(): void
138
143
$ this ->collectionMock = $ this ->getMockBuilder (Collection::class)
139
144
->disableOriginalConstructor ()
140
145
->getMock ();
146
+ $ this ->productCategoryListMock = $ this ->getMockBuilder (ProductCategoryList::class)
147
+ ->disableOriginalConstructor ()
148
+ ->onlyMethods (['getCategoryIds ' ])
149
+ ->getMock ();
141
150
$ this ->format = new Format (
142
151
$ this ->getMockBuilder (ScopeResolverInterface::class)
143
152
->disableOriginalConstructor ()
@@ -158,7 +167,9 @@ protected function setUp(): void
158
167
$ this ->productRepositoryMock ,
159
168
$ this ->productMock ,
160
169
$ this ->collectionMock ,
161
- $ this ->format
170
+ $ this ->format ,
171
+ [],
172
+ $ this ->productCategoryListMock
162
173
);
163
174
}
164
175
@@ -228,28 +239,22 @@ public function testValidateCategoriesIgnoresVisibility(): void
228
239
->setMethods (['getAttribute ' , 'getId ' , 'setQuoteItemQty ' , 'setQuoteItemPrice ' ])
229
240
->getMock ();
230
241
$ product
231
- ->expects ($ this ->any ())
232
242
->method ('setQuoteItemQty ' )
233
243
->willReturnSelf ();
234
244
$ product
235
- ->expects ($ this ->any ())
236
245
->method ('setQuoteItemPrice ' )
237
246
->willReturnSelf ();
238
247
/* @var AbstractItem|MockObject $item */
239
248
$ item = $ this ->getMockBuilder (AbstractItem::class)
240
249
->disableOriginalConstructor ()
241
- ->setMethods (['getProduct ' ])
250
+ ->onlyMethods (['getProduct ' ])
242
251
->getMockForAbstractClass ();
243
252
$ item ->expects ($ this ->any ())
244
253
->method ('getProduct ' )
245
254
->willReturn ($ product );
246
255
$ this ->model ->setAttribute ('category_ids ' );
247
-
248
- $ this ->selectMock
249
- ->expects ($ this ->once ())
250
- ->method ('where ' )
251
- ->with ($ this ->logicalNot ($ this ->stringContains ('visibility ' )), $ this ->anything (), $ this ->anything ());
252
-
256
+ $ this ->productCategoryListMock ->method ('getCategoryIds ' )
257
+ ->willReturn ([self ::STUB_CATEGORY_ID ]);
253
258
$ this ->model ->validate ($ item );
254
259
}
255
260
0 commit comments