8
8
namespace Magento \Catalog \Model \Product \Gallery ;
9
9
10
10
use Magento \Catalog \Api \Data \ProductInterface ;
11
+ use Magento \Catalog \Api \Data \ProductInterfaceFactory ;
11
12
use Magento \Catalog \Api \ProductRepositoryInterface ;
12
- use Magento \Catalog \Model \Product ;
13
13
use Magento \Catalog \Model \ResourceModel \Product as ProductResource ;
14
14
use Magento \Framework \EntityManager \MetadataPool ;
15
15
use Magento \Store \Api \StoreRepositoryInterface ;
@@ -37,6 +37,11 @@ class ReadHandlerTest extends \PHPUnit\Framework\TestCase
37
37
*/
38
38
private $ productRepository ;
39
39
40
+ /**
41
+ * @var ProductInterfaceFactory
42
+ */
43
+ private $ productFactory ;
44
+
40
45
/**
41
46
* @var ProductResource
42
47
*/
@@ -60,6 +65,7 @@ protected function setUp()
60
65
$ this ->objectManager = Bootstrap::getObjectManager ();
61
66
$ this ->readHandler = $ this ->objectManager ->create (ReadHandler::class);
62
67
$ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
68
+ $ this ->productFactory = $ this ->objectManager ->get (ProductInterfaceFactory::class);
63
69
$ this ->productResource = $ this ->objectManager ->get (ProductResource::class);
64
70
$ this ->storeRepository = $ this ->objectManager ->create (StoreRepositoryInterface::class);
65
71
$ this ->productLinkField = $ this ->objectManager ->get (MetadataPool::class)
@@ -258,25 +264,22 @@ public function executeOnStoreViewDataProvider(): array
258
264
/**
259
265
* Returns product for testing.
260
266
*
261
- * @return Product
267
+ * @return ProductInterface
262
268
*/
263
- private function getProduct (): Product
269
+ private function getProduct (): ProductInterface
264
270
{
265
- /** @var Product $product */
266
- $ product = $ this ->productRepository ->get ('simple ' , false , Store::DEFAULT_STORE_ID );
267
-
268
- return $ product ;
271
+ return $ this ->productRepository ->get ('simple ' , false , Store::DEFAULT_STORE_ID );
269
272
}
270
273
271
274
/**
272
275
* Updates product gallery images and saves product.
273
276
*
274
- * @param Product $product
277
+ * @param ProductInterface $product
275
278
* @param array $images
276
279
* @param int|null $storeId
277
280
* @return void
278
281
*/
279
- private function setGalleryImages (Product $ product , array $ images , int $ storeId = null ): void
282
+ private function setGalleryImages (ProductInterface $ product , array $ images , ? int $ storeId = null ): void
280
283
{
281
284
$ product ->setImage (null );
282
285
foreach ($ images as $ file => $ data ) {
@@ -306,12 +309,12 @@ private function setGalleryImages(Product $product, array $images, int $storeId
306
309
* Returns empty product instance.
307
310
*
308
311
* @param int|null $storeId
309
- * @return Product
312
+ * @return ProductInterface
310
313
*/
311
- private function getProductInstance (int $ storeId = null ): Product
314
+ private function getProductInstance (? int $ storeId = null ): ProductInterface
312
315
{
313
- /** @var Product $product */
314
- $ product = $ this ->objectManager ->create (Product::class );
316
+ /** @var ProductInterface $product */
317
+ $ product = $ this ->productFactory ->create ();
315
318
$ product ->setData (
316
319
$ this ->productLinkField ,
317
320
$ this ->getProduct ()->getData ($ this ->productLinkField )
0 commit comments