Skip to content

Commit 831ef30

Browse files
committed
AC-10634: setMethods replaced with onlyMethods() or addMethods()
1 parent 3d8075d commit 831ef30

File tree

148 files changed

+722
-645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+722
-645
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Entity/AttributeTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class AttributeTest extends TestCase
156156
protected function setUp(): void
157157
{
158158
$this->contextMock = $this->getMockBuilder(Context::class)
159-
->setMethods(['getCacheManager', 'getEventDispatcher'])
159+
->onlyMethods(['getCacheManager', 'getEventDispatcher'])
160160
->disableOriginalConstructor()
161161
->getMock();
162162
$this->registryMock = $this->getMockBuilder(Registry::class)
@@ -174,7 +174,7 @@ protected function setUp(): void
174174
->disableOriginalConstructor()
175175
->getMock();
176176
$this->typeFactoryMock = $this->getMockBuilder(TypeFactory::class)
177-
->setMethods(['create'])
177+
->onlyMethods(['create'])
178178
->disableOriginalConstructor()
179179
->getMock();
180180
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
@@ -187,7 +187,7 @@ protected function setUp(): void
187187
->getMock();
188188
$this->attributeOptionFactoryMock =
189189
$this->getMockBuilder(AttributeOptionInterfaceFactory::class)
190-
->setMethods(['create'])
190+
->onlyMethods(['create'])
191191
->disableOriginalConstructor()
192192
->getMock();
193193
$this->dataObjectProcessorMock = $this->getMockBuilder(DataObjectProcessor::class)
@@ -211,7 +211,8 @@ protected function setUp(): void
211211
);
212212

213213
$this->resourceMock = $this->getMockBuilder(AbstractResource::class)
214-
->setMethods(['_construct', 'getConnection', 'getIdFieldName', 'saveInSetIncluding'])
214+
->addMethods(['getIdFieldName', 'saveInSetIncluding'])
215+
->onlyMethods(['_construct', 'getConnection'])
215216
->getMockForAbstractClass();
216217
$this->cacheManager = $this->getMockBuilder(CacheInterface::class)
217218
->getMock();
@@ -226,6 +227,7 @@ protected function setUp(): void
226227
->method('getEventDispatcher')
227228
->willReturn($this->eventDispatcher);
228229
$objectManagerHelper = new ObjectManagerHelper($this);
230+
$objectManagerHelper->prepareObjectManager();
229231
$this->attribute = $objectManagerHelper->getObject(
230232
Attribute::class,
231233
[

app/code/Magento/Catalog/Test/Unit/Model/Product/Type/AbstractTypeTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@ protected function setUp(): void
4848
$this->model = $this->objectManagerHelper->getObject(Simple::class);
4949

5050
$this->product = $this->getMockBuilder(Product::class)
51-
->setMethods(['getHasOptions', '__sleep', 'getResource', 'getStatus'])
51+
->addMethods(['getHasOptions'])
52+
->onlyMethods(['__sleep', 'getResource', 'getStatus'])
5253
->disableOriginalConstructor()
5354
->getMock();
5455
$this->productResource = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product::class)
55-
->setMethods(['getSortedAttributes', 'loadAllAttributes'])
56+
->onlyMethods(['getSortedAttributes', 'loadAllAttributes'])
5657
->disableOriginalConstructor()
5758
->getMockForAbstractClass();
5859

5960
$this->product->expects($this->any())->method('getResource')->willReturn($this->productResource);
6061

6162
$this->attribute = $this->getMockBuilder(Attribute::class)
62-
->setMethods(['getGroupSortPath', 'getSortPath'])
63+
->addMethods(['getGroupSortPath', 'getSortPath'])
6364
->disableOriginalConstructor()
6465
->getMock();
6566
}
@@ -106,7 +107,7 @@ public function testAttributesCompare($attr1, $attr2, $expectedResult)
106107
/**
107108
* @return array
108109
*/
109-
public function attributeCompareProvider()
110+
public static function attributeCompareProvider()
110111
{
111112
return [
112113
[2, 2, 0],

app/code/Magento/Catalog/Test/Unit/Model/Product/Website/ReadHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function setUp(): void
3232
->disableOriginalConstructor()
3333
->getMock();
3434
$this->extensionAttributesMock = $this->getMockBuilder(ProductExtensionInterface::class)
35-
->setMethods(['setWebsiteIds', 'getWebsiteIds'])
35+
->addMethods(['setWebsiteIds', 'getWebsiteIds'])
3636
->disableArgumentCloning()
3737
->getMockForAbstractClass();
3838
$this->readHandler = new ReadHandler($this->websiteLinkMock);

app/code/Magento/Catalog/Test/Unit/Model/ProductRender/FormattedPriceInfoBuilderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public function testBuild()
5353

5454
$formattedPriceInfoInterfaceMock = $this->getMockBuilder(FormattedPriceInfoInterface::class)
5555
->disableOriginalConstructor()
56-
->setMethods(['setData'])
56+
->addMethods(['setData'])
5757
->getMockForAbstractClass();
5858
$priceInfoMock = $this->getMockBuilder(PriceInfoInterface::class)
5959
->disableOriginalConstructor()
60-
->setMethods(['getData'])
60+
->addMethods(['getData'])
6161
->getMockForAbstractClass();
6262
$priceInfoMock->expects($this->any())
6363
->method('getData')

app/code/Magento/Catalog/Test/Unit/Model/ProductRepository/MediaGalleryProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function testProcessMediaGallery(): void
147147
//verify new entries
148148
$contentDataObject = $this->getMockBuilder(ImageContent::class)
149149
->disableOriginalConstructor()
150-
->setMethods(null)
150+
->onlyMethods([])
151151
->getMock();
152152
$this->contentFactoryMock->expects($this->once())->method('create')->willReturn($contentDataObject);
153153
$this->imageProcessorMock->expects($this->once())->method('processImageContent')->willReturn($absolutePath);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ public function testSaveExistingWithNewMediaGalleryEntries(): void
14041404
//verify new entries
14051405
$contentDataObject = $this->getMockBuilder(ImageContent::class)
14061406
->disableOriginalConstructor()
1407-
->setMethods(null)
1407+
->onlyMethods([])
14081408
->getMock();
14091409
$this->contentFactory->expects($this->once())
14101410
->method('create')

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/MediaImageDeleteProcessorTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,27 @@ protected function setUp(): void
7070

7171
$this->productMock = $this->getMockBuilder(Product::class)
7272
->disableOriginalConstructor()
73-
->setMethods(['getId', 'getMediaGalleryImages'])
73+
->onlyMethods(['getId', 'getMediaGalleryImages'])
7474
->getMock();
7575

7676
$this->imageConfig = $this->getMockBuilder(MediaConfig::class)
7777
->disableOriginalConstructor()
78-
->setMethods(['getBaseMediaUrl', 'getMediaUrl', 'getBaseMediaPath', 'getMediaPath'])
78+
->onlyMethods(['getBaseMediaUrl', 'getMediaUrl', 'getBaseMediaPath', 'getMediaPath'])
7979
->getMock();
8080

8181
$this->mediaDirectory = $this->getMockBuilder(Filesystem::class)
8282
->disableOriginalConstructor()
83-
->setMethods(['getRelativePath', 'isFile', 'delete'])
83+
->addMethods(['getRelativePath', 'isFile', 'delete'])
8484
->getMock();
8585

8686
$this->imageProcessor = $this->getMockBuilder(Processor::class)
8787
->disableOriginalConstructor()
88-
->setMethods(['removeImage'])
88+
->onlyMethods(['removeImage'])
8989
->getMock();
9090

9191
$this->productGallery = $this->getMockBuilder(Gallery::class)
9292
->disableOriginalConstructor()
93-
->setMethods(['deleteGallery', 'countImageUses'])
93+
->onlyMethods(['deleteGallery', 'countImageUses'])
9494
->getMock();
9595

9696
$this->mediaImageDeleteProcessor = $this->objectManager->getObject(
@@ -133,8 +133,10 @@ public function testExecuteCategoryProductMediaDelete(
133133

134134
$this->mediaDirectory->expects($this->any())
135135
->method('getRelativePath')
136-
->withConsecutive([$productImages[0]->getFile()], [$productImages[1]->getFile()])
137-
->willReturnOnConsecutiveCalls($productImages[0]->getPath(), $productImages[1]->getPath());
136+
->willReturnCallback(fn($param) => match ([$param]) {
137+
[$productImages[0]->getFile()] => $productImages[0]->getPath(),
138+
[$productImages[1]->getFile()] => $productImages[1]->getPath()
139+
});
138140

139141
$this->productGallery->expects($this->any())
140142
->method('countImageUses')
@@ -154,7 +156,7 @@ public function testExecuteCategoryProductMediaDelete(
154156
/**
155157
* @return array
156158
*/
157-
public function executeCategoryProductMediaDeleteDataProvider(): array
159+
public static function executeCategoryProductMediaDeleteDataProvider(): array
158160
{
159161
$imageDirectoryPath = '/media/dir1/dir2/catalog/product/';
160162
$image1FilePath = '/test/test1.jpg';

app/code/Magento/Catalog/Test/Unit/Observer/SetSpecialPriceStartDateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ protected function setUp(): void
7171

7272
$this->eventMock = $this->getMockBuilder(Event::class)
7373
->disableOriginalConstructor()
74-
->setMethods(['getProduct'])
74+
->addMethods(['getProduct'])
7575
->getMock();
7676

7777
$this->productMock = $this->getMockBuilder(Product::class)
7878
->disableOriginalConstructor()
79-
->setMethods(['getSpecialPrice', 'getSpecialFromDate', 'setData'])
79+
->onlyMethods(['getSpecialPrice', 'getSpecialFromDate', 'setData'])
8080
->getMock();
8181

8282
$this->observer = $this->objectManager->getObject(

app/code/Magento/Catalog/Test/Unit/Plugin/Model/AttributeSetRepository/RemoveProductsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function setUp(): void
3939
$objectManager = new ObjectManager($this);
4040
$this->collectionFactory = $this->getMockBuilder(CollectionFactory::class)
4141
->disableOriginalConstructor()
42-
->setMethods(['create'])
42+
->onlyMethods(['create'])
4343
->getMock();
4444
$this->testSubject = $objectManager->getObject(
4545
RemoveProducts::class,
@@ -77,7 +77,7 @@ public function testAfterDelete()
7777

7878
/** @var AttributeSetInterface|MockObject $attributeSet */
7979
$attributeSet = $this->getMockBuilder(AttributeSetInterface::class)
80-
->setMethods(['getId'])
80+
->addMethods(['getId'])
8181
->disableOriginalConstructor()
8282
->getMockForAbstractClass();
8383
$attributeSet->expects(self::once())

app/code/Magento/Catalog/Test/Unit/Ui/Component/FilterFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testCreateWithUseSourceAttribute()
7373
{
7474
$contextMock = $this->getMockForAbstractClass(ContextInterface::class);
7575
$attributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
76-
->setMethods(['usesSource', 'getSource'])
76+
->addMethods(['usesSource', 'getSource'])
7777
->getMockForAbstractClass();
7878
$attributeMock->method('getAttributeCode')->willReturn(self::STUB_ATTRIBUTE['attribute_code']);
7979
$attributeMock->method('getDefaultFrontendLabel')

0 commit comments

Comments
 (0)