Skip to content

Commit 415291b

Browse files
committed
Upgrade PHPUnit and fix failing / warnings in tests
1 parent 8d90d12 commit 415291b

File tree

6 files changed

+457
-239
lines changed

6 files changed

+457
-239
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
namespace Magento\CatalogImportExport\Test\Unit\Model\Export;
99

1010
use Magento\Catalog\Model\Product\LinkTypeProvider;
11+
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
1112
use Magento\CatalogImportExport\Model\Export\Product;
1213
use Magento\CatalogImportExport\Model\Export\Product\Type\Factory;
1314
use Magento\CatalogImportExport\Model\Export\RowCustomizer\Composite;
1415
use Magento\Eav\Model\Config;
1516
use Magento\Eav\Model\Entity\Collection\AbstractCollection;
1617
use Magento\Eav\Model\Entity\Type;
18+
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
1719
use Magento\Framework\App\ResourceConnection;
1820
use Magento\Framework\EntityManager\MetadataPool;
1921
use Magento\Framework\Logger\Monolog;
@@ -83,7 +85,7 @@ class ProductTest extends TestCase
8385
protected $attrSetColFactory;
8486

8587
/**
86-
* @var \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory|MockObject
88+
* @var CategoryCollectionFactory|MockObject
8789
*/
8890
protected $categoryColFactory;
8991

@@ -174,15 +176,14 @@ protected function setUp(): void
174176
->onlyMethods(['create'])
175177
->getMock();
176178

177-
$this->attrSetColFactory = $this->getMockBuilder(
178-
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory::class
179-
)->addMethods(['setEntityTypeFilter'])
179+
$this->attrSetColFactory = $this->getMockBuilder(AttributeSetCollectionFactory::class)
180+
->disableOriginalConstructor()
181+
->addMethods(['setEntityTypeFilter'])
180182
->onlyMethods(['create'])
181183
->getMock();
182184

183-
$this->categoryColFactory = $this->getMockBuilder(
184-
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory::class
185-
)->addMethods(['addNameToResult'])
185+
$this->categoryColFactory = $this->getMockBuilder(CategoryCollectionFactory::class)
186+
->disableOriginalConstructor()->addMethods(['addNameToResult'])
186187
->onlyMethods(['create'])
187188
->getMock();
188189

app/code/Magento/Developer/Test/Unit/Console/Command/XmlCatalogGenerateCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testExecuteBadType()
4646
->with(
4747
$this->equalTo(['urn:magento:framework:Module/etc/module.xsd' => $fixtureXmlFile]),
4848
$this->equalTo('test')
49-
)->willReturn(null);
49+
);
5050

5151
$formats = ['phpstorm' => $phpstormFormatMock];
5252
$readFactory = $this->createMock(ReadFactory::class);
@@ -97,7 +97,7 @@ public function testExecuteVsCodeFormat()
9797
->with(
9898
$this->equalTo(['urn:magento:framework:Module/etc/module.xsd' => $fixtureXmlFile]),
9999
$this->equalTo('test')
100-
)->willReturn(null);
100+
);
101101

102102
$formats = ['vscode' => $vscodeFormatMock];
103103
$readFactory = $this->createMock(ReadFactory::class);

app/code/Magento/ProductVideo/Test/Unit/Model/Product/Attribute/Media/ExternalVideoEntryConverterTest.php

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
@@ -26,34 +27,26 @@
2627
*/
2728
class ExternalVideoEntryConverterTest extends TestCase
2829
{
29-
/**
30-
* @var MockObject|ProductAttributeMediaGalleryEntryInterfaceFactory
31-
*/
32-
protected $mediaGalleryEntryFactoryMock;
30+
/** @var MockObject|ProductAttributeMediaGalleryEntryInterfaceFactory */
31+
private $mediaGalleryEntryFactoryMock;
3332

34-
/**
35-
* @var MockObject|ProductAttributeMediaGalleryEntryInterface
36-
*/
37-
protected $mediaGalleryEntryMock;
33+
/** @var MockObject|ProductAttributeMediaGalleryEntryInterface */
34+
private $mediaGalleryEntryMock;
3835

3936
/** @var MockObject|DataObjectHelper */
40-
protected $dataObjectHelperMock;
37+
private $dataObjectHelperMock;
4138

4239
/** @var MockObject|VideoContentInterfaceFactory */
43-
protected $videoEntryFactoryMock;
40+
private $videoEntryFactoryMock;
4441

4542
/** @var MockObject|VideoContentInterface */
46-
protected $videoEntryMock;
43+
private $videoEntryMock;
4744

48-
/**
49-
* @var MockObject|ProductAttributeMediaGalleryEntryExtensionFactory
50-
*/
51-
protected $mediaGalleryEntryExtensionFactoryMock;
45+
/** @var MockObject|ProductAttributeMediaGalleryEntryExtensionFactory */
46+
private $mediaGalleryEntryExtensionFactoryMock;
5247

53-
/**
54-
* @var MockObject|ProductAttributeMediaGalleryEntryExtensionFactory
55-
*/
56-
protected $mediaGalleryEntryExtensionMock;
48+
/** @var MockObject|ProductAttributeMediaGalleryEntryExtension */
49+
private $mediaGalleryEntryExtensionMock;
5750

5851
/**
5952
* @var ObjectManager|ExternalVideoEntryConverter
@@ -62,33 +55,35 @@ class ExternalVideoEntryConverterTest extends TestCase
6255

6356
protected function setUp(): void
6457
{
65-
$this->mediaGalleryEntryFactoryMock =
66-
$this->createPartialMock(
67-
ProductAttributeMediaGalleryEntryInterfaceFactory::class,
68-
['create']
69-
);
58+
$this->mediaGalleryEntryFactoryMock = $this->createPartialMock(
59+
ProductAttributeMediaGalleryEntryInterfaceFactory::class,
60+
['create']
61+
);
7062

7163
$this->mediaGalleryEntryMock =
72-
$this->createPartialMock(ProductAttributeMediaGalleryEntryInterface::class, [
73-
'getId',
74-
'setId',
75-
'getMediaType',
76-
'setMediaType',
77-
'getLabel',
78-
'setLabel',
79-
'getPosition',
80-
'setPosition',
81-
'isDisabled',
82-
'setDisabled',
83-
'getTypes',
84-
'setTypes',
85-
'getFile',
86-
'setFile',
87-
'getContent',
88-
'setContent',
89-
'getExtensionAttributes',
90-
'setExtensionAttributes'
91-
]);
64+
$this->createPartialMock(
65+
ProductAttributeMediaGalleryEntryInterface::class,
66+
[
67+
'getId',
68+
'setId',
69+
'getMediaType',
70+
'setMediaType',
71+
'getLabel',
72+
'setLabel',
73+
'getPosition',
74+
'setPosition',
75+
'isDisabled',
76+
'setDisabled',
77+
'getTypes',
78+
'setTypes',
79+
'getFile',
80+
'setFile',
81+
'getContent',
82+
'setContent',
83+
'getExtensionAttributes',
84+
'setExtensionAttributes'
85+
]
86+
);
9287

9388
$this->mediaGalleryEntryFactoryMock->expects($this->any())->method('create')->willReturn(
9489
$this->mediaGalleryEntryMock
@@ -110,7 +105,8 @@ protected function setUp(): void
110105
);
111106

112107
$this->mediaGalleryEntryExtensionMock = $this->getMockBuilder(ProductAttributeMediaGalleryEntryExtension::class)
113-
->addMethods(['getVideoProvider', 'setVideoContent', 'getVideoContent'])
108+
->addMethods(['getVideoProvider'])
109+
->onlyMethods(['setVideoContent', 'getVideoContent'])
114110
->disableOriginalConstructor()
115111
->getMock();
116112

app/code/Magento/Quote/Test/Unit/Model/Quote/Address/Total/SubtotalTest.php

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,16 @@
3232
*/
3333
class SubtotalTest extends TestCase
3434
{
35-
/**
36-
* @var ObjectManager
37-
*/
35+
/** @var ObjectManager */
3836
protected $objectManager;
3937

40-
/**
41-
* @var Subtotal
42-
*/
38+
/** @var Subtotal */
4339
protected $subtotalModel;
4440

4541
/** @var MockObject */
4642
protected $stockItemMock;
4743

48-
/**
49-
* @var MockObject
50-
*/
44+
/** @var MockObject */
5145
protected $stockRegistry;
5246

5347
protected function setUp(): void
@@ -57,14 +51,15 @@ protected function setUp(): void
5751
Subtotal::class
5852
);
5953

60-
$this->stockRegistry = $this->createPartialMock(
61-
StockRegistry::class,
62-
['getStockItem', '__wakeup']
63-
);
64-
$this->stockItemMock = $this->createPartialMock(
65-
\Magento\CatalogInventory\Model\Stock\Item::class,
66-
['getIsInStock', '__wakeup']
67-
);
54+
$this->stockRegistry = $this->getMockBuilder(StockRegistry::class)
55+
->disableOriginalConstructor()
56+
->addMethods(['__wakeup'])
57+
->onlyMethods(['getStockItem'])
58+
->getMock();
59+
$this->stockItemMock = $this->getMockBuilder(\Magento\CatalogInventory\Model\Stock\Item::class)
60+
->disableOriginalConstructor()
61+
->onlyMethods(['getIsInStock', '__wakeup'])
62+
->getMock();
6863
}
6964

7065
/**
@@ -110,10 +105,11 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri
110105
]
111106
);
112107
/** @var Address|MockObject $address */
113-
$address = $this->createPartialMock(
114-
Address::class,
115-
['setTotalQty', 'getTotalQty', 'removeItem', 'getQuote']
116-
);
108+
$address = $this->getMockBuilder(Address::class)
109+
->addMethods(['setTotalQty', 'getTotalQty'])
110+
->onlyMethods(['removeItem', 'getQuote'])
111+
->disableOriginalConstructor()
112+
->getMock();
117113

118114
/** @var Product|MockObject $product */
119115
$product = $this->createMock(Product::class);
@@ -161,10 +157,10 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri
161157
$shippingAssignmentMock->expects($this->exactly(2))->method('getShipping')->willReturn($shipping);
162158
$shippingAssignmentMock->expects($this->once())->method('getItems')->willReturn([$quoteItem]);
163159

164-
$total = $this->createPartialMock(
165-
Total::class,
166-
['setBaseVirtualAmount', 'setVirtualAmount']
167-
);
160+
$total = $this->getMockBuilder(Total::class)
161+
->addMethods(['setBaseVirtualAmount', 'setVirtualAmount'])
162+
->getMock();
163+
168164
$total->expects($this->once())->method('setBaseVirtualAmount')->willReturnSelf();
169165
$total->expects($this->once())->method('setVirtualAmount')->willReturnSelf();
170166

@@ -185,7 +181,10 @@ public function testFetch()
185181
];
186182

187183
$quoteMock = $this->createMock(Quote::class);
188-
$totalMock = $this->createPartialMock(Total::class, ['getSubtotal']);
184+
$totalMock = $this->getMockBuilder(Total::class)
185+
->addMethods(['getSubtotal'])
186+
->disableOriginalConstructor()
187+
->getMock();
189188
$totalMock->expects($this->once())->method('getSubtotal')->willReturn(100);
190189

191190
$this->assertEquals($expectedResult, $this->subtotalModel->fetch($quoteMock, $totalMock));
@@ -229,13 +228,11 @@ public function testCollectWithInvalidItems()
229228
$address->expects($this->once())
230229
->method('removeItem')
231230
->with($addressItemId);
232-
$addressItem = $this->createPartialMock(
233-
AddressItem::class,
234-
[
235-
'getId',
236-
'getQuoteItemId'
237-
]
238-
);
231+
$addressItem = $this->getMockBuilder(AddressItem::class)
232+
->onlyMethods(['getId'])
233+
->addMethods(['getQuoteItemId'])
234+
->disableOriginalConstructor()
235+
->getMock();
239236
$addressItem->setAddress($address);
240237
$addressItem->method('getId')
241238
->willReturn($addressItemId);

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,13 @@ class CreditmemoFactoryTest extends TestCase
4949
*/
5050
protected function setUp(): void
5151
{
52-
$this->orderItemMock = $this->createPartialMock(
53-
Item::class,
54-
['getChildrenItems', 'isDummy', 'getHasChildren', 'getId', 'getParentItemId']
55-
);
56-
$this->orderChildItemOneMock = $this->createPartialMock(
57-
Item::class,
58-
['getQtyToRefund', 'getId']
59-
);
60-
$this->orderChildItemTwoMock = $this->createPartialMock(
61-
Item::class,
62-
['getQtyToRefund', 'getId']
63-
);
52+
$this->orderItemMock = $this->getMockBuilder(Item::class)
53+
->onlyMethods(['getChildrenItems', 'isDummy', 'getId', 'getParentItemId'])
54+
->addMethods(['getHasChildren'])
55+
->disableOriginalConstructor()
56+
->getMock();
57+
$this->orderChildItemOneMock = $this->createPartialMock(Item::class, ['getQtyToRefund', 'getId']);
58+
$this->orderChildItemTwoMock = $this->createPartialMock(Item::class, ['getQtyToRefund', 'getId']);
6459
$this->testMethod = new ReflectionMethod(CreditmemoFactory::class, 'canRefundItem');
6560

6661
$objectManagerHelper = new ObjectManagerHelper($this);

0 commit comments

Comments
 (0)