Skip to content

Commit f1f5157

Browse files
committed
AC-10634: Unit Test fixes
1 parent afbce4a commit f1f5157

File tree

23 files changed

+126
-109
lines changed

23 files changed

+126
-109
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public function testConvertToBuyRequest(
114114
->getMockForAbstractClass();
115115

116116
$productOptionExtensionMock = $this->getMockBuilder(ProductOptionExtensionInterface::class)
117+
->addMethods(['getCustomOptions'])
117118
->getMockForAbstractClass();
118119

119120
$productOptionMock->expects($this->any())

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ public static function getStoreIdByCodeDataProvider(): array
11071107
* @return void
11081108
* @dataProvider validateRowCheckSpecifiedSkuDataProvider
11091109
*/
1110-
public function testValidateRowCheckSpecifiedSku($sku, $expectedError): void
1110+
public function testValidateRowCheckSpecifiedSku($sku): void
11111111
{
11121112
$importProduct = $this->createModelMockWithErrorAggregator(
11131113
['addRowError', 'getOptionEntity', 'getRowScope'],
@@ -1813,16 +1813,13 @@ public static function validateRowCheckSpecifiedSkuDataProvider(): array
18131813
{
18141814
return [
18151815
[
1816-
'$sku' => null,
1817-
'$expectedError' => Validator::ERROR_SKU_IS_EMPTY
1816+
'$sku' => null
18181817
],
18191818
[
1820-
'$sku' => false,
1821-
'$expectedError' => Validator::ERROR_ROW_IS_ORPHAN
1819+
'$sku' => false
18221820
],
18231821
[
1824-
'$sku' => 'sku',
1825-
'$expectedError' => Validator::ERROR_INVALID_STORE
1822+
'$sku' => 'sku'
18261823
]
18271824
];
18281825
}

app/code/Magento/CatalogInventory/Test/Unit/Api/StockRegistryTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ class StockRegistryTest extends TestCase
6868
*/
6969
protected $product;
7070

71-
protected $productId = 111;
72-
protected $productSku = 'simple';
73-
protected $websiteId = 111;
71+
private const PRODUCT_ID = 111;
72+
private const PRODUCT_SKU = 'simple';
73+
private const WEBSITE_ID = 111;
7474

7575
protected function setUp(): void
7676
{
@@ -79,8 +79,8 @@ protected function setUp(): void
7979
$this->product = $this->createPartialMock(Product::class, ['__wakeup', 'getIdBySku']);
8080
$this->product->expects($this->any())
8181
->method('getIdBySku')
82-
->willReturn($this->productId);
83-
//getIdBySku
82+
->willReturn(self::PRODUCT_ID);
83+
8484
$this->productFactory = $this->createPartialMock(ProductFactory::class, ['create']);
8585
$this->productFactory->expects($this->any())
8686
->method('create')
@@ -147,35 +147,35 @@ protected function tearDown(): void
147147

148148
public function testGetStock()
149149
{
150-
$this->assertEquals($this->stock, $this->stockRegistry->getStock($this->websiteId));
150+
$this->assertEquals($this->stock, $this->stockRegistry->getStock(self::WEBSITE_ID));
151151
}
152152

153153
public function testGetStockItem()
154154
{
155-
$this->assertEquals($this->stockItem, $this->stockRegistry->getStockItem($this->productId, $this->websiteId));
155+
$this->assertEquals($this->stockItem, $this->stockRegistry->getStockItem(self::PRODUCT_ID, self::WEBSITE_ID));
156156
}
157157

158158
public function testGetStockItemBySku()
159159
{
160160
$this->assertEquals(
161161
$this->stockItem,
162-
$this->stockRegistry->getStockItemBySku($this->productSku, $this->websiteId)
162+
$this->stockRegistry->getStockItemBySku(self::PRODUCT_SKU, self::WEBSITE_ID)
163163
);
164164
}
165165

166166
public function testGetStockStatus()
167167
{
168168
$this->assertEquals(
169169
$this->stockStatus,
170-
$this->stockRegistry->getStockStatus($this->productId, $this->websiteId)
170+
$this->stockRegistry->getStockStatus(self::PRODUCT_ID, self::WEBSITE_ID)
171171
);
172172
}
173173

174174
public function testGetStockStatusBySku()
175175
{
176176
$this->assertEquals(
177177
$this->stockStatus,
178-
$this->stockRegistry->getStockStatus($this->productId, $this->websiteId)
178+
$this->stockRegistry->getStockStatus(self::PRODUCT_ID, self::WEBSITE_ID)
179179
);
180180
}
181181

@@ -188,7 +188,7 @@ public function testUpdateStockItemBySku()
188188
$this->stockItem->expects($this->atLeastOnce())->method('getItemId')->willReturn($itemId);
189189
$this->assertEquals(
190190
$itemId,
191-
$this->stockRegistry->updateStockItemBySku($this->productSku, $this->stockItem)
191+
$this->stockRegistry->updateStockItemBySku(self::PRODUCT_SKU, $this->stockItem)
192192
);
193193
}
194194
}

app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ class StorageTest extends TestCase
4242
/**
4343
* Directory paths samples
4444
*/
45-
const STORAGE_ROOT_DIR = '/storage/root/dir/';
45+
private const STORAGE_ROOT_DIR = '/storage/root/dir/';
4646

47-
const INVALID_DIRECTORY_OVER_ROOT = '/storage/some/another/dir';
47+
private const INVALID_DIRECTORY_OVER_ROOT = '/storage/some/another/dir';
4848

4949
/**
5050
* @var Storage

app/code/Magento/Customer/Test/Unit/Model/Account/RedirectTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
3-
* Unit test for Magento\Customer\Test\Unit\Model\Account\Redirect
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
6+
declare(strict_types=1);
87

98
namespace Magento\Customer\Test\Unit\Model\Account;
109

app/code/Magento/GroupedProduct/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GroupedTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
*/
3333
class GroupedTest extends AbstractModifierTest
3434
{
35-
const PRODUCT_ID = 1;
36-
const LINKED_PRODUCT_ID = 2;
37-
const LINKED_PRODUCT_SKU = 'linked';
38-
const LINKED_PRODUCT_NAME = 'linked';
39-
const LINKED_PRODUCT_QTY = '0';
40-
const LINKED_PRODUCT_POSITION = 1;
41-
const LINKED_PRODUCT_POSITION_CALCULATED = 1;
42-
const LINKED_PRODUCT_PRICE = '1';
35+
private const PRODUCT_ID = 1;
36+
private const LINKED_PRODUCT_ID = 2;
37+
private const LINKED_PRODUCT_SKU = 'linked';
38+
private const LINKED_PRODUCT_NAME = 'linked';
39+
private const LINKED_PRODUCT_QTY = '0';
40+
private const LINKED_PRODUCT_POSITION = 1;
41+
private const LINKED_PRODUCT_POSITION_CALCULATED = 1;
42+
private const LINKED_PRODUCT_PRICE = '1';
4343

4444
/**
4545
* @var ProductInterface|MockObject

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/ViewTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ class ViewTest extends TestCase
108108
protected $pageTitleMock;
109109

110110
/**
111-
* @var \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\View
112111
* @var RedirectFactory|MockObject
113112
*/
114113
protected $resultRedirectFactoryMock;

app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ class ConfigTest extends TestCase
2828
/**
2929
* Pending status stub
3030
*/
31-
const STUB_PENDING_STATUS_CODE = 'pending';
31+
private const STUB_PENDING_STATUS_CODE = 'pending';
3232

3333
/**
3434
* Store view with id 2
3535
*/
36-
const STUB_STORE_VIEW_WITH_ID_2 = 2;
36+
private const STUB_STORE_VIEW_WITH_ID_2 = 2;
3737

3838
/**
3939
* Pending label in store view 2
4040
*/
41-
const STUB_STORE_VIEW_LABEL_WITH_ID_2 = 'Pending-2';
41+
private const STUB_STORE_VIEW_LABEL_WITH_ID_2 = 'Pending-2';
4242

4343
/**
4444
* @var Config
@@ -65,6 +65,9 @@ class ConfigTest extends TestCase
6565
*/
6666
protected $storeManagerMock;
6767

68+
/**
69+
* @var StatusLabel|MockObject
70+
*/
6871
protected $statusLabel;
6972

7073
/**
@@ -249,7 +252,7 @@ public function testGetStatuses($state, $joinLabels, $collectionData, $expectedR
249252
*
250253
* @return array
251254
*/
252-
public function getStatusesDataProvider()
255+
public static function getStatusesDataProvider()
253256
{
254257
return [
255258
'processing state' => [

app/code/Magento/SalesRule/Test/Unit/Model/Rule/Condition/ProductTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
class ProductTest extends TestCase
3737
{
38-
const STUB_CATEGORY_ID = 5;
38+
private const STUB_CATEGORY_ID = 5;
3939
/** @var SalesRuleProduct */
4040
protected $model;
4141

@@ -96,15 +96,15 @@ protected function setUp(): void
9696
->getMockForAbstractClass();
9797
$this->attributeLoaderInterfaceMock = $this->getMockBuilder(AbstractEntity::class)
9898
->disableOriginalConstructor()
99-
->setMethods(['getAttributesByCode'])
99+
->onlyMethods(['getAttributesByCode'])
100100
->getMock();
101101
$this->attributeLoaderInterfaceMock
102102
->expects($this->any())
103103
->method('getAttributesByCode')
104104
->willReturn([]);
105105
$this->selectMock = $this->getMockBuilder(Select::class)
106106
->disableOriginalConstructor()
107-
->setMethods(['distinct', 'from', 'where'])
107+
->onlyMethods(['distinct', 'from', 'where'])
108108
->getMock();
109109
$this->selectMock
110110
->expects($this->any())
@@ -117,15 +117,15 @@ protected function setUp(): void
117117
->willReturnSelf();
118118
$this->adapterInterfaceMock = $this->getMockBuilder(AdapterInterface::class)
119119
->disableOriginalConstructor()
120-
->setMethods(['fetchCol', 'select'])
120+
->onlyMethods(['fetchCol', 'select'])
121121
->getMockForAbstractClass();
122122
$this->adapterInterfaceMock
123123
->expects($this->any())
124124
->method('select')
125125
->willReturn($this->selectMock);
126126
$this->productMock = $this->getMockBuilder(Product::class)
127127
->disableOriginalConstructor()
128-
->setMethods(['loadAllAttributes', 'getConnection', 'getTable'])
128+
->onlyMethods(['loadAllAttributes', 'getConnection', 'getTable'])
129129
->getMock();
130130
$this->productMock
131131
->expects($this->any())
@@ -176,7 +176,7 @@ protected function setUp(): void
176176
/**
177177
* @return array
178178
*/
179-
public function getValueElementChooserUrlDataProvider()
179+
public static function getValueElementChooserUrlDataProvider()
180180
{
181181
return [
182182
'category_ids_without_js_object' => [
@@ -236,7 +236,8 @@ public function testValidateCategoriesIgnoresVisibility(): void
236236
/* @var \Magento\Catalog\Model\Product|MockObject $product */
237237
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
238238
->disableOriginalConstructor()
239-
->setMethods(['getAttribute', 'getId', 'setQuoteItemQty', 'setQuoteItemPrice'])
239+
->onlyMethods(['getId'])
240+
->addMethods(['getAttribute', 'setQuoteItemQty', 'setQuoteItemPrice'])
240241
->getMock();
241242
$product
242243
->method('setQuoteItemQty')
@@ -269,7 +270,7 @@ public function testQuoteLocaleFormatPrice($isValid, $conditionValue, $operator
269270
{
270271
$attr = $this->getMockBuilder(AbstractDb::class)
271272
->disableOriginalConstructor()
272-
->setMethods(['getAttribute'])
273+
->addMethods(['getAttribute'])
273274
->getMockForAbstractClass();
274275

275276
$attr->expects($this->any())
@@ -279,7 +280,8 @@ public function testQuoteLocaleFormatPrice($isValid, $conditionValue, $operator
279280
/* @var \Magento\Catalog\Model\Product|MockObject $product */
280281
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
281282
->disableOriginalConstructor()
282-
->setMethods(['setQuoteItemPrice', 'getResource', 'hasData', 'getData'])
283+
->addMethods(['setQuoteItemPrice'])
284+
->onlyMethods(['getResource', 'hasData', 'getData'])
283285
->getMock();
284286

285287
$product->expects($this->any())
@@ -302,7 +304,7 @@ public function testQuoteLocaleFormatPrice($isValid, $conditionValue, $operator
302304
/* @var AbstractItem|MockObject $item */
303305
$item = $this->getMockBuilder(AbstractItem::class)
304306
->disableOriginalConstructor()
305-
->setMethods(['getPrice', 'getProduct'])
307+
->onlyMethods(['getPrice', 'getProduct'])
306308
->getMockForAbstractClass();
307309

308310
$item->expects($this->any())
@@ -324,7 +326,7 @@ public function testQuoteLocaleFormatPrice($isValid, $conditionValue, $operator
324326
*
325327
* @return array
326328
*/
327-
public function localisationProvider(): array
329+
public static function localisationProvider(): array
328330
{
329331
return [
330332
'number' => [true, 500.01],

app/code/Magento/Search/Test/Unit/Block/TermsTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public function testGetTerms(string $termKey, bool $popularity): void
8787
$terms = $this->createMock(Collection::class);
8888
$dataObjectMock = $this->getMockBuilder(Query::class)
8989
->disableOriginalConstructor()
90-
->setMethods(['getPopularity', 'getQueryText'])
90+
->addMethods(['getPopularity'])
91+
->onlyMethods(['getQueryText'])
9192
->getMock();
9293
$storeMock = $this->createMock(Store::class);
9394

@@ -132,12 +133,13 @@ public function testGetSearchResult(): void
132133
{
133134
$urlMock = $this->getMockBuilder(Url::class)
134135
->disableOriginalConstructor()
135-
->setMethods(['setQueryParam', 'getUrl'])
136+
->onlyMethods(['setQueryParam', 'getUrl'])
136137
->getMock();
137138

138139
$dataObjectMock = $this->getMockBuilder(Query::class)
139140
->disableOriginalConstructor()
140-
->setMethods(['getPopularity', 'getQueryText'])
141+
->addMethods(['getPopularity'])
142+
->onlyMethods(['getQueryText'])
141143
->getMock();
142144
$this->urlFactoryMock->expects($this->once())
143145
->method('create')
@@ -159,7 +161,7 @@ public function testGetSearchResult(): void
159161
*
160162
* @return array
161163
*/
162-
public function termKeysProvider(): array
164+
public static function termKeysProvider(): array
163165
{
164166
return [
165167
[

0 commit comments

Comments
 (0)