Skip to content

Commit 13af48a

Browse files
author
vadim
committed
#7720 fix cs
1 parent a039ff4 commit 13af48a

File tree

2 files changed

+74
-24
lines changed

2 files changed

+74
-24
lines changed

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@
5454
*/
5555
class ProductRepositoryTest extends TestCase
5656
{
57+
private const STUB_STORE_ID = 1;
58+
59+
private const STUB_STORE_ID_GLOBAL = 0;
60+
61+
private const STUB_PRODUCT_ID = 100;
62+
63+
private const STUB_PRODUCT_NAME = 'name';
64+
65+
private const STUB_PRODUCT_SKU = 'sku';
66+
5767
/**
5868
* @var Product|MockObject
5969
*/
@@ -291,7 +301,7 @@ protected function setUp()
291301
->disableOriginalConstructor()
292302
->setMethods([])
293303
->getMockForAbstractClass();
294-
$storeMock->method('getId')->willReturn('1');
304+
$storeMock->method('getId')->willReturn(self::STUB_STORE_ID);
295305
$storeMock->expects($this->any())->method('getWebsiteId')->willReturn('1');
296306
$storeMock->expects($this->any())->method('getCode')->willReturn(Store::ADMIN_CODE);
297307
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeMock);
@@ -347,7 +357,7 @@ function ($value) {
347357
}
348358

349359
/**
350-
* Test save product with store id 0
360+
* Test save product with global store id
351361
*
352362
* @param array $productData
353363
* @return void
@@ -361,9 +371,10 @@ public function testSaveForAllStoreViewScope(array $productData): void
361371
->expects($this->once())
362372
->method('toNestedArray')
363373
->willReturn($productData);
364-
$this->resourceModel->method('getIdBySku')->willReturn(100);
374+
$this->resourceModel->method('getIdBySku')->willReturn(self::STUB_PRODUCT_ID);
365375
$this->resourceModel->expects($this->once())->method('validate')->willReturn(true);
366-
$this->product->expects($this->at(14))->method('setData')->with('store_id', $productData['store_id']);
376+
$this->product->expects($this->at(14))->method('setData')
377+
->with('store_id', $productData['store_id']);
367378

368379
$this->model->save($this->product);
369380
}
@@ -378,9 +389,9 @@ public function getProductData(): array
378389
return [
379390
[
380391
[
381-
'sku' => 'sku',
382-
'name' => 'product',
383-
'store_id' => 0,
392+
'sku' => self::STUB_PRODUCT_SKU,
393+
'name' => self::STUB_PRODUCT_NAME,
394+
'store_id' => self::STUB_STORE_ID_GLOBAL,
384395
],
385396
],
386397
];
@@ -399,9 +410,10 @@ public function testSaveWithoutStoreId(): void
399410
->expects($this->once())
400411
->method('toNestedArray')
401412
->willReturn($this->productData);
402-
$this->resourceModel->method('getIdBySku')->willReturn(100);
413+
$this->resourceModel->method('getIdBySku')->willReturn(self::STUB_PRODUCT_ID);
403414
$this->resourceModel->expects($this->once())->method('validate')->willReturn(true);
404-
$this->product->expects($this->at(15))->method('setData')->with('store_id', 1);
415+
$this->product->expects($this->at(15))->method('setData')
416+
->with('store_id', self::STUB_STORE_ID);
405417

406418
$this->model->save($this->product);
407419
}

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductRepositoryTest.php

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77

88
namespace Magento\Catalog\Model;
99

10-
use Magento\Backend\Model\Auth;
1110
use Magento\Catalog\Api\ProductRepositoryInterface;
1211
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
1312
use Magento\Framework\Api\SearchCriteriaBuilder;
1413
use Magento\Framework\Exception\LocalizedException;
1514
use Magento\TestFramework\Catalog\Model\ProductLayoutUpdateManager;
1615
use Magento\TestFramework\Helper\Bootstrap;
17-
use Magento\TestFramework\Bootstrap as TestBootstrap;
18-
use Magento\Framework\Acl\Builder;
1916

2017
/**
2118
* Provide tests for ProductRepository model.
@@ -26,6 +23,16 @@
2623
*/
2724
class ProductRepositoryTest extends \PHPUnit\Framework\TestCase
2825
{
26+
private const STUB_STORE_ID = 1;
27+
28+
private const STUB_STORE_ID_GLOBAL = 0;
29+
30+
private const STUB_PRODUCT_NAME = 'Simple Product';
31+
32+
private const STUB_UPDATED_PRODUCT_NAME = 'updated';
33+
34+
private const STUB_PRODUCT_SKU = 'simple';
35+
2936
/**
3037
* Test subject.
3138
*
@@ -235,22 +242,53 @@ public function testCustomLayout(): void
235242
}
236243

237244
/**
238-
* Tests product repository update should use provided store code.
245+
* Tests product repository update
239246
*
247+
* @dataProvider productUpdateDataProvider
240248
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
249+
* @param int $storeId
250+
* @param int $checkStoreId
251+
* @param string $expectedNameStore
252+
* @param string $expectedNameCheckedStore
241253
*/
242-
public function testProductUpdate(): void
243-
{
244-
$sku = 'simple';
245-
$nameUpdated = 'updated';
254+
public function testProductUpdate(
255+
int $storeId,
256+
int $checkStoreId,
257+
string $expectedNameStore,
258+
string $expectedNameCheckedStore
259+
): void {
260+
$sku = self::STUB_PRODUCT_SKU;
246261

247-
$product = $this->productRepository->get($sku, false, 0);
248-
$product->setName($nameUpdated);
262+
$product = $this->productRepository->get($sku, false, $storeId);
263+
$product->setName(self::STUB_UPDATED_PRODUCT_NAME);
249264
$this->productRepository->save($product);
250-
$product = $this->productRepository->get($sku, false, 0);
251-
$this->assertEquals(
252-
$nameUpdated,
253-
$product->getName()
254-
);
265+
$productNameStoreId = $this->productRepository->get($sku, false, $storeId)->getName();
266+
$productNameCheckedStoreId = $this->productRepository->get($sku, false, $checkStoreId)->getName();
267+
268+
$this->assertEquals($expectedNameStore, $productNameStoreId);
269+
$this->assertEquals($expectedNameCheckedStore, $productNameCheckedStoreId);
270+
}
271+
272+
/**
273+
* Product update data provider
274+
*
275+
* @return array
276+
*/
277+
public function productUpdateDataProvider(): array
278+
{
279+
return [
280+
'Updating for global store' => [
281+
self::STUB_STORE_ID_GLOBAL,
282+
self::STUB_STORE_ID,
283+
self::STUB_UPDATED_PRODUCT_NAME,
284+
self::STUB_UPDATED_PRODUCT_NAME,
285+
],
286+
'Updating for store' => [
287+
self::STUB_STORE_ID,
288+
self::STUB_STORE_ID_GLOBAL,
289+
self::STUB_UPDATED_PRODUCT_NAME,
290+
self::STUB_PRODUCT_NAME,
291+
],
292+
];
255293
}
256294
}

0 commit comments

Comments
 (0)