Skip to content

Commit ce37a79

Browse files
MC-21715: Storefront: view product images
1 parent 4e7cd44 commit ce37a79

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/GalleryTest.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace Magento\Catalog\Block\Product\View;
99

10+
use Magento\Catalog\Api\Data\ProductInterface;
1011
use Magento\Catalog\Api\ProductRepositoryInterface;
11-
use Magento\Catalog\Model\Product;
1212
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
1313
use Magento\Framework\Serialize\Serializer\Json;
1414
use Magento\Framework\View\LayoutInterface;
@@ -48,11 +48,6 @@ class GalleryTest extends \PHPUnit\Framework\TestCase
4848
*/
4949
private $serializer;
5050

51-
/**
52-
* @var Product
53-
*/
54-
private $product;
55-
5651
/**
5752
* @var Gallery
5853
*/
@@ -298,12 +293,12 @@ public function galleryImagesOnStoreViewDataProvider(): array
298293
/**
299294
* Updates product gallery images and saves product.
300295
*
301-
* @param Product $product
296+
* @param ProductInterface $product
302297
* @param array $images
303298
* @param int|null $storeId
304299
* @return void
305300
*/
306-
private function setGalleryImages(Product $product, array $images, int $storeId = null): void
301+
private function setGalleryImages(ProductInterface $product, array $images, int $storeId = null): void
307302
{
308303
$product->setImage(null);
309304
foreach ($images as $file => $data) {
@@ -334,11 +329,11 @@ private function setGalleryImages(Product $product, array $images, int $storeId
334329
* Returns current product.
335330
*
336331
* @param int|null $storeId
337-
* @return Product
332+
* @return ProductInterface
338333
*/
339-
private function getProduct(int $storeId = null): Product
334+
private function getProduct(?int $storeId = null): ProductInterface
340335
{
341-
return $this->product = $this->productRepository->get('simple', false, $storeId, true);
336+
return $this->productRepository->get('simple', false, $storeId, true);
342337
}
343338

344339
/**

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Gallery/ReadHandlerTest.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
namespace Magento\Catalog\Model\Product\Gallery;
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
1112
use Magento\Catalog\Api\ProductRepositoryInterface;
12-
use Magento\Catalog\Model\Product;
1313
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
1414
use Magento\Framework\EntityManager\MetadataPool;
1515
use Magento\Store\Api\StoreRepositoryInterface;
@@ -37,6 +37,11 @@ class ReadHandlerTest extends \PHPUnit\Framework\TestCase
3737
*/
3838
private $productRepository;
3939

40+
/**
41+
* @var ProductInterfaceFactory
42+
*/
43+
private $productFactory;
44+
4045
/**
4146
* @var ProductResource
4247
*/
@@ -60,6 +65,7 @@ protected function setUp()
6065
$this->objectManager = Bootstrap::getObjectManager();
6166
$this->readHandler = $this->objectManager->create(ReadHandler::class);
6267
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
68+
$this->productFactory = $this->objectManager->get(ProductInterfaceFactory::class);
6369
$this->productResource = $this->objectManager->get(ProductResource::class);
6470
$this->storeRepository = $this->objectManager->create(StoreRepositoryInterface::class);
6571
$this->productLinkField = $this->objectManager->get(MetadataPool::class)
@@ -258,25 +264,22 @@ public function executeOnStoreViewDataProvider(): array
258264
/**
259265
* Returns product for testing.
260266
*
261-
* @return Product
267+
* @return ProductInterface
262268
*/
263-
private function getProduct(): Product
269+
private function getProduct(): ProductInterface
264270
{
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);
269272
}
270273

271274
/**
272275
* Updates product gallery images and saves product.
273276
*
274-
* @param Product $product
277+
* @param ProductInterface $product
275278
* @param array $images
276279
* @param int|null $storeId
277280
* @return void
278281
*/
279-
private function setGalleryImages(Product $product, array $images, int $storeId = null): void
282+
private function setGalleryImages(ProductInterface $product, array $images, ?int $storeId = null): void
280283
{
281284
$product->setImage(null);
282285
foreach ($images as $file => $data) {
@@ -306,12 +309,12 @@ private function setGalleryImages(Product $product, array $images, int $storeId
306309
* Returns empty product instance.
307310
*
308311
* @param int|null $storeId
309-
* @return Product
312+
* @return ProductInterface
310313
*/
311-
private function getProductInstance(int $storeId = null): Product
314+
private function getProductInstance(?int $storeId = null): ProductInterface
312315
{
313-
/** @var Product $product */
314-
$product = $this->objectManager->create(Product::class);
316+
/** @var ProductInterface $product */
317+
$product = $this->productFactory->create();
315318
$product->setData(
316319
$this->productLinkField,
317320
$this->getProduct()->getData($this->productLinkField)

0 commit comments

Comments
 (0)