Skip to content

Commit edf7732

Browse files
committed
AC-10634: setMethods replaced with onlyMethods() or addMethods()
1 parent bc9004d commit edf7732

File tree

19 files changed

+128
-109
lines changed

19 files changed

+128
-109
lines changed

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Export/AdvancedPricingTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,15 @@ protected function setUp(): void
225225
'initWebsites',
226226
'initCategories'
227227
];
228+
$mockAddMethods = [
229+
'_headerColumns'
230+
];
228231
$mockMethods = array_merge($constructorMethods, [
229232
'_customHeadersMapping',
230233
'_prepareEntityCollection',
231234
'_getEntityCollection',
232235
'getWriter',
233236
'getExportData',
234-
'_headerColumns',
235237
'_customFieldsMapping',
236238
'getItemsPerPage',
237239
'paginateCollection',
@@ -243,7 +245,8 @@ protected function setUp(): void
243245
$this->advancedPricing = $this->getMockBuilder(
244246
AdvancedPricing::class
245247
)
246-
->setMethods($mockMethods)
248+
->addMethods($mockAddMethods)
249+
->onlyMethods($mockMethods)
247250
->disableOriginalConstructor()
248251
->getMock();
249252
foreach ($constructorMethods as $method) {

app/code/Magento/Cms/Test/Unit/Helper/PageTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,20 @@ protected function setUp(): void
153153
->getMock();
154154
$this->pageFactoryMock = $this->getMockBuilder(PageFactory::class)
155155
->disableOriginalConstructor()
156-
->setMethods(['create'])
156+
->onlyMethods(['create'])
157157
->getMock();
158158
$this->pageMock = $this->getMockBuilder(\Magento\Cms\Model\Page::class)
159159
->disableOriginalConstructor()
160-
->setMethods(
160+
->addMethods(['setStoreId', 'getCustomPageLayout'])
161+
->onlyMethods(
161162
[
162163
'getId',
163-
'setStoreId',
164164
'load',
165165
'getCustomThemeFrom',
166166
'getCustomThemeTo',
167167
'getCustomTheme',
168168
'getPageLayout',
169169
'getIdentifier',
170-
'getCustomPageLayout',
171170
'getCustomLayoutUpdateXml',
172171
'getLayoutUpdateXml',
173172
'getContentHeading',
@@ -203,7 +202,7 @@ protected function setUp(): void
203202
$this->layoutProcessorMock = $this->getMockBuilder(ProcessorInterface::class)
204203
->getMockForAbstractClass();
205204
$this->blockMock = $this->getMockBuilder(AbstractBlock::class)
206-
->setMethods(['setContentHeading'])
205+
->addMethods(['setContentHeading'])
207206
->disableOriginalConstructor()
208207
->getMockForAbstractClass();
209208
$this->messagesBlockMock = $this->getMockBuilder(Messages::class)
@@ -398,7 +397,7 @@ public function testPrepareResultPage(
398397
/**
399398
* @return array
400399
*/
401-
public function renderPageExtendedDataProvider()
400+
public static function renderPageExtendedDataProvider()
402401
{
403402
return [
404403
'ids NOT EQUAL BUT page->load() NOT SUCCESSFUL' => [
@@ -501,7 +500,7 @@ public function testGetPageUrl(
501500
/**
502501
* @return array
503502
*/
504-
public function getPageUrlDataProvider()
503+
public static function getPageUrlDataProvider()
505504
{
506505
return [
507506
'ids NOT EQUAL BUT page->load() NOT SUCCESSFUL' => [

app/code/Magento/Cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ protected function setUp(): void
138138
->method('getDirectoryReadByPath')
139139
->willReturn($this->directoryReadMock);
140140
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
141-
->setMethods(
141+
->addMethods(['clearWebsiteCache'])
142+
->onlyMethods(
142143
[
143-
'clearWebsiteCache', 'getDefaultStoreView', 'getGroup', 'getGroups',
144+
'getDefaultStoreView', 'getGroup', 'getGroups',
144145
'getStore', 'getStores', 'getWebsite', 'getWebsites', 'hasSingleStore',
145146
'isSingleStoreMode', 'reinitStores', 'setCurrentStore', 'setIsSingleStoreModeAllowed',
146147
]
@@ -290,7 +291,7 @@ public function testConvertIdToPathAnyId($path, $pathId)
290291
/**
291292
* @return array
292293
*/
293-
public function providerConvertIdToPath()
294+
public static function providerConvertIdToPath()
294295
{
295296
return [
296297
['', ''],
@@ -318,7 +319,7 @@ public function testGetShortFilename($fileName, $maxLength, $expectedFilename)
318319
/**
319320
* @return array
320321
*/
321-
public function providerShortFilename()
322+
public static function providerShortFilename()
322323
{
323324
return [
324325
['test', 3, 'tes...'],
@@ -340,7 +341,7 @@ public function testGetShortFilenameDefaultMaxLength($fileName, $expectedFilenam
340341
/**
341342
* @return array
342343
*/
343-
public function providerShortFilenameDefaultMaxLength()
344+
public static function providerShortFilenameDefaultMaxLength()
344345
{
345346
return [
346347
['Mini text', 'Mini text'],
@@ -380,7 +381,7 @@ protected function generalSettingsIsUsingStaticUrlsAllowed($allowedValue)
380381
/**
381382
* @return array
382383
*/
383-
public function providerIsUsingStaticUrlsAllowed()
384+
public static function providerIsUsingStaticUrlsAllowed()
384385
{
385386
return [
386387
[true],
@@ -467,7 +468,7 @@ public function testGetCurrentPathThrowException()
467468
/**
468469
* @return array
469470
*/
470-
public function providerGetCurrentPath()
471+
public static function providerGetCurrentPath()
471472
{
472473
return [
473474
['L3Rlc3RfcGF0aA--', 'L3Rlc3RfcGF0aA--', 'PATH/test_path', true],
@@ -523,7 +524,7 @@ public function testGetImageHtmlDeclarationRenderingAsTag(
523524
/**
524525
* @return array
525526
*/
526-
public function providerGetImageHtmlDeclarationRenderingAsTag()
527+
public static function providerGetImageHtmlDeclarationRenderingAsTag()
527528
{
528529
return [
529530
[
@@ -572,7 +573,7 @@ public function testGetImageHtmlDeclaration($baseUrl, $fileName, $isUsingStaticU
572573
/**
573574
* @return array
574575
*/
575-
public function providerGetImageHtmlDeclaration()
576+
public static function providerGetImageHtmlDeclaration()
576577
{
577578
return [
578579
['http://localhost', 'test.png', true, 'http://localhost/test.png'],

app/code/Magento/Cms/Test/Unit/Model/PageTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ protected function setUp(): void
6363
->getMock();
6464
$this->resourcePageMock = $this->getMockBuilder(PageResource::class)
6565
->disableOriginalConstructor()
66-
->setMethods(['getIdFieldName', 'checkIdentifier', 'getResources'])
66+
->addMethods(['getResources'])
67+
->onlyMethods(['getIdFieldName', 'checkIdentifier'])
6768
->getMock();
6869
$this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)
6970
->disableOriginalConstructor()
7071
->getMockForAbstractClass();
7172
$this->resourcesMock = $this->getMockBuilder(AbstractResource::class)
72-
->setMethods(['getIdFieldName', 'load', 'checkIdentifier'])
73+
->addMethods(['getIdFieldName', 'load', 'checkIdentifier'])
7374
->getMockForAbstractClass();
7475
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
7576
->getMockForAbstractClass();

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected function setUp(): void
165165
$this->objectManagerHelper = new ObjectManager($this);
166166
$this->filesystemMock = $this->createMock(Filesystem::class);
167167
$this->driverMock = $this->getMockBuilder(DriverInterface::class)
168-
->setMethods(['getRealPathSafety'])
168+
->onlyMethods(['getRealPathSafety'])
169169
->getMockForAbstractClass();
170170

171171
$this->directoryMock = $this->createPartialMock(
@@ -238,9 +238,9 @@ function ($path) {
238238
->disableOriginalConstructor()
239239
->getMock();
240240
$this->sessionMock = $this->getMockBuilder(Session::class)
241-
->setMethods(
241+
->addMethods(['getCurrentPath'])
242+
->onlyMethods(
242243
[
243-
'getCurrentPath',
244244
'getName',
245245
'getSessionId',
246246
'getCookieLifetime',
@@ -383,7 +383,7 @@ public function testGetDirsCollection($path, $callNum, $dirsFilter = '')
383383
/**
384384
* @return array
385385
*/
386-
public function dirsCollectionDataProvider()
386+
public static function dirsCollectionDataProvider()
387387
{
388388
return [
389389
[
@@ -476,7 +476,7 @@ public function testUploadFile()
476476
];
477477
$uploader = $this->getMockBuilder(Uploader::class)
478478
->disableOriginalConstructor()
479-
->setMethods(
479+
->onlyMethods(
480480
[
481481
'setAllowedExtensions',
482482
'setAllowRenameFiles',
@@ -526,7 +526,8 @@ public function testUploadFile()
526526

527527
$image = $this->getMockBuilder(Image::class)
528528
->disableOriginalConstructor()
529-
->setMethods(['open', 'keepAspectRatio', 'resize', 'save'])
529+
->addMethods(['open', 'keepAspectRatio'])
530+
->onlyMethods(['resize', 'save'])
530531
->getMock();
531532
$image->expects($this->atLeastOnce())->method('open')->with($realPath);
532533
$image->expects($this->atLeastOnce())->method('keepAspectRatio')->with(true);

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/FieldsetTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ class FieldsetTest extends TestCase
9696
protected function setUp(): void
9797
{
9898
$this->authSessionMock = $this->getMockBuilder(Session::class)
99-
->setMethods(['getUser'])
99+
->addMethods(['getUser'])
100100
->disableOriginalConstructor()
101101
->getMock();
102102

103103
$this->userMock = $this->getMockBuilder(User::class)
104-
->setMethods(['getExtra'])
104+
->addMethods(['getExtra'])
105105
->disableOriginalConstructor()
106106
->getMock();
107107

@@ -200,7 +200,8 @@ public function testRenderWithStoredElements($expanded, $nested, $extra)
200200
$this->userMock->expects($this->any())->method('getExtra')->willReturn($extra);
201201
$this->_helperMock->expects($this->any())->method('getScript')->willReturnArgument(0);
202202
$fieldMock = $this->getMockBuilder(Text::class)
203-
->setMethods(['getId', 'getTooltip', 'toHtml', 'getHtmlId', 'getIsNested', 'getExpanded'])
203+
->addMethods(['getTooltip', 'getIsNested', 'getExpanded'])
204+
->onlyMethods(['getId', 'toHtml', 'getHtmlId'])
204205
->disableOriginalConstructor()
205206
->getMock();
206207
$fieldMock->expects($this->any())->method('getId')->willReturn('test_field_id');
@@ -209,7 +210,8 @@ public function testRenderWithStoredElements($expanded, $nested, $extra)
209210
$fieldMock->expects($this->any())->method('getHtmlId')->willReturn('test_field_HTML_id');
210211

211212
$fieldSetMock = $this->getMockBuilder(\Magento\Framework\Data\Form\Element\Fieldset::class)
212-
->setMethods(['getId', 'getTooltip', 'toHtml', 'getHtmlId', 'getIsNested', 'getExpanded'])
213+
->addMethods(['getTooltip', 'getIsNested', 'getExpanded'])
214+
->onlyMethods(['getId', 'toHtml', 'getHtmlId'])
213215
->disableOriginalConstructor()
214216
->getMock();
215217
$fieldSetMock->expects($this->any())->method('getId')->willReturn('test_fieldset_id');

app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockConfigProcessorTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ protected function setUp(): void
7777
->disableOriginalConstructor()
7878
->getMock();
7979
$this->valueMock = $this->getMockBuilder(Value::class)
80-
->setMethods(['validateBeforeSave', 'beforeSave', 'setValue', 'getValue', 'afterSave'])
80+
->addMethods(['setValue', 'getValue'])
81+
->onlyMethods(['validateBeforeSave', 'beforeSave', 'afterSave'])
8182
->disableOriginalConstructor()
8283
->getMock();
8384

@@ -156,7 +157,7 @@ public function testProcess($path, $value, $scope, $scopeCode)
156157
/**
157158
* @return array
158159
*/
159-
public function processDataProvider()
160+
public static function processDataProvider()
160161
{
161162
return [
162163
['test/test/test', 'value', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],

app/code/Magento/Config/Test/Unit/Model/PreparedValueFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ protected function setUp(): void
9292
{
9393
$this->structureFactoryMock = $this->getMockBuilder(StructureFactory::class)
9494
->disableOriginalConstructor()
95-
->setMethods(['create'])
95+
->onlyMethods(['create'])
9696
->getMock();
9797
$this->valueFactoryMock = $this->getMockBuilder(BackendFactory::class)
9898
->disableOriginalConstructor()
99-
->setMethods(['create'])
99+
->onlyMethods(['create'])
100100
->getMock();
101101
$this->structureMock = $this->getMockBuilder(Structure::class)
102102
->disableOriginalConstructor()
@@ -106,7 +106,7 @@ protected function setUp(): void
106106
->getMock();
107107
$this->valueMock = $this->getMockBuilder(Value::class)
108108
->disableOriginalConstructor()
109-
->setMethods([
109+
->addMethods([
110110
'setPath', 'setScope', 'setScopeId', 'setValue', 'setField',
111111
'setGroupId', 'setFieldConfig', 'setScopeCode'
112112
])
@@ -251,7 +251,7 @@ public function testCreate(
251251
/**
252252
* @return array
253253
*/
254-
public function createDataProvider()
254+
public static function createDataProvider()
255255
{
256256
return [
257257
'standard flow' => [

app/code/Magento/ConfigurableProduct/Test/Unit/Controller/Adminhtml/Product/Initialization/Helper/Plugin/ConfigurableTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,24 @@ protected function setUp(): void
5757
{
5858
$this->variationHandler = $this->getMockBuilder(VariationHandler::class)
5959
->disableOriginalConstructor()
60-
->setMethods(['generateSimpleProducts', 'prepareAttributeSet'])
60+
->onlyMethods(['generateSimpleProducts', 'prepareAttributeSet'])
6161
->getMock();
6262

6363
$this->request = $this->getMockBuilder(Http::class)
6464
->disableOriginalConstructor()
65-
->setMethods(['getParam', 'getPost'])
65+
->onlyMethods(['getParam', 'getPost'])
6666
->getMock();
6767

6868
$this->optionFactory = $this->getMockBuilder(Factory::class)
6969
->disableOriginalConstructor()
70-
->setMethods(['create'])
70+
->onlyMethods(['create'])
7171
->getMock();
7272

7373
$this->product = $this->getMockBuilder(Product::class)
7474
->disableOriginalConstructor()
75-
->setMethods([
76-
'getTypeId', 'setAttributeSetId', 'getExtensionAttributes', 'setNewVariationsAttributeSetId',
77-
'setCanSaveConfigurableAttributes', 'setExtensionAttributes'
75+
->addMethods(['setNewVariationsAttributeSetId', 'setCanSaveConfigurableAttributes'])
76+
->onlyMethods([
77+
'getTypeId', 'setAttributeSetId', 'getExtensionAttributes', 'setExtensionAttributes'
7878
])
7979
->getMock();
8080

@@ -168,7 +168,7 @@ public function testAfterInitializeWithAttributesAndVariations()
168168

169169
$extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class)
170170
->disableOriginalConstructor()
171-
->setMethods(['setConfigurableProductOptions', 'setConfigurableProductLinks'])
171+
->addMethods(['setConfigurableProductOptions', 'setConfigurableProductLinks'])
172172
->getMockForAbstractClass();
173173
$this->product->expects(static::once())
174174
->method('getExtensionAttributes')
@@ -234,7 +234,7 @@ public function testAfterInitializeWithAttributesAndWithoutVariations()
234234

235235
$extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class)
236236
->disableOriginalConstructor()
237-
->setMethods(['setConfigurableProductOptions', 'setConfigurableProductLinks'])
237+
->addMethods(['setConfigurableProductOptions', 'setConfigurableProductLinks'])
238238
->getMockForAbstractClass();
239239
$this->product->expects(static::once())
240240
->method('getExtensionAttributes')

app/code/Magento/ConfigurableProduct/Test/Unit/Model/OptionRepositoryTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ public function testValidateNewOptionData($attributeId, $label, $optionValues, $
356356
$this->expectException(InputException::class);
357357
$this->expectExceptionMessage($msg);
358358
$optionValueMock = $this->getMockBuilder(OptionValueInterface::class)
359-
->setMethods(['getValueIndex', 'getPricingValue', 'getIsPercent'])
359+
->addMethods(['getPricingValue', 'getIsPercent'])
360+
->onlyMethods(['getValueIndex'])
360361
->getMockForAbstractClass();
361362
$optionValuesMock = [];
362363
if (!empty($optionValues)) {
@@ -389,7 +390,7 @@ public function testValidateNewOptionData($attributeId, $label, $optionValues, $
389390
/**
390391
* @return array
391392
*/
392-
public function validateOptionDataProvider()
393+
public static function validateOptionDataProvider()
393394
{
394395
return [
395396
[null, '', ['v' => null, 'p' => null, 'r' => null], 'One or more input exceptions have occurred.'],

0 commit comments

Comments
 (0)