1212use Magento \Catalog \Model \ResourceModel \Product \Collection as ProductCollection ;
1313use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory as ProductCollectionFactory ;
1414use Magento \Framework \DataObject ;
15- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
1615use PHPUnit \Framework \MockObject \MockObject ;
1716use PHPUnit \Framework \TestCase ;
1817
1918class DuplicateUrlKeyTest extends TestCase
2019{
21- /** @var ObjectManagerHelper */
22- private $ objectManagerHelper ;
23-
24- protected function setUp (): void
25- {
26- $ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
27- }
28-
2920 /**
3021 * @dataProvider duplicatedProductUrlKeyValuesDataProvider
3122 *
@@ -57,8 +48,12 @@ function ($productData) use ($storeId) {
5748 $ collectionsPerStoreId = array_map (
5849 function ($ productsData ) {
5950 /** @var MockObject $productCollectionMock */
60- $ productCollectionMock = $ this ->objectManagerHelper
61- ->getCollectionMock (ProductCollection::class, $ productsData );
51+ $ productCollectionMock = $ this ->getMockBuilder (ProductCollection::class)
52+ ->disableOriginalConstructor ()
53+ ->getMock ();
54+ $ productCollectionMock ->expects ($ this ->any ())
55+ ->method ('getIterator ' )
56+ ->will ($ this ->returnValue (new \ArrayIterator ($ productsData )));
6257
6358 $ productCollectionMock ->expects ($ this ->once ())
6459 ->method ('setStoreId ' )
@@ -97,7 +92,7 @@ function ($productsData) {
9792 $ productCollectionFactoryMock = $ this
9893 ->getMockBuilder (ProductCollectionFactory::class)
9994 ->disableOriginalConstructor ()
100- ->setMethods (['create ' ])
95+ ->onlyMethods (['create ' ])
10196 ->getMock ();
10297
10398 $ productCollectionFactoryMock ->expects ($ this ->exactly (count ($ storeIds )))
@@ -118,7 +113,7 @@ function ($productsData) {
118113 $ attributeScopeOverriddenValueFactoryMock = $ this
119114 ->getMockBuilder (AttributeScopeOverriddenValueFactory::class)
120115 ->disableOriginalConstructor ()
121- ->setMethods (['create ' ])
116+ ->onlyMethods (['create ' ])
122117 ->getMock ();
123118 $ attributeScopeOverriddenValueFactoryMock ->expects ($ this ->exactly (count ($ dbData )))
124119 ->method ('create ' )
0 commit comments