99
1010use Magento \Backend \Helper \Data ;
1111use Magento \Catalog \Api \ProductRepositoryInterface ;
12+ use Magento \Catalog \Model \ProductCategoryList ;
1213use Magento \Catalog \Model \ProductFactory ;
1314use Magento \Catalog \Model \ResourceModel \Product ;
1415use Magento \Directory \Model \CurrencyFactory ;
3435 */
3536class ProductTest extends TestCase
3637{
38+ const STUB_CATEGORY_ID = 5 ;
3739 /** @var SalesRuleProduct */
3840 protected $ model ;
3941
@@ -70,6 +72,9 @@ class ProductTest extends TestCase
7072 /** @var Select|MockObject */
7173 protected $ selectMock ;
7274
75+ /** @var MockObject|ProductCategoryList */
76+ private $ productCategoryListMock ;
77+
7378 /**
7479 * Setup the test
7580 */
@@ -138,6 +143,10 @@ protected function setUp(): void
138143 $ this ->collectionMock = $ this ->getMockBuilder (Collection::class)
139144 ->disableOriginalConstructor ()
140145 ->getMock ();
146+ $ this ->productCategoryListMock = $ this ->getMockBuilder (ProductCategoryList::class)
147+ ->disableOriginalConstructor ()
148+ ->onlyMethods (['getCategoryIds ' ])
149+ ->getMock ();
141150 $ this ->format = new Format (
142151 $ this ->getMockBuilder (ScopeResolverInterface::class)
143152 ->disableOriginalConstructor ()
@@ -158,7 +167,9 @@ protected function setUp(): void
158167 $ this ->productRepositoryMock ,
159168 $ this ->productMock ,
160169 $ this ->collectionMock ,
161- $ this ->format
170+ $ this ->format ,
171+ [],
172+ $ this ->productCategoryListMock
162173 );
163174 }
164175
@@ -228,28 +239,22 @@ public function testValidateCategoriesIgnoresVisibility(): void
228239 ->setMethods (['getAttribute ' , 'getId ' , 'setQuoteItemQty ' , 'setQuoteItemPrice ' ])
229240 ->getMock ();
230241 $ product
231- ->expects ($ this ->any ())
232242 ->method ('setQuoteItemQty ' )
233243 ->willReturnSelf ();
234244 $ product
235- ->expects ($ this ->any ())
236245 ->method ('setQuoteItemPrice ' )
237246 ->willReturnSelf ();
238247 /* @var AbstractItem|MockObject $item */
239248 $ item = $ this ->getMockBuilder (AbstractItem::class)
240249 ->disableOriginalConstructor ()
241- ->setMethods (['getProduct ' ])
250+ ->onlyMethods (['getProduct ' ])
242251 ->getMockForAbstractClass ();
243252 $ item ->expects ($ this ->any ())
244253 ->method ('getProduct ' )
245254 ->willReturn ($ product );
246255 $ 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 ]);
253258 $ this ->model ->validate ($ item );
254259 }
255260
0 commit comments