Skip to content

Commit 11b4fda

Browse files
authored
ENGCOM-7306: #27638 Fix fatal errors in Unit Tests #27701
2 parents ea7af78 + 16fc2af commit 11b4fda

File tree

5 files changed

+37
-36
lines changed

5 files changed

+37
-36
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Product/CopierTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Magento\Catalog\Test\Unit\Model\Product;
88

9-
use Magento\Catalog\Api\Data\ProductExtension;
9+
use Magento\Catalog\Api\Data\ProductExtensionInterface;
1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
1212
use Magento\Catalog\Model\Product;
@@ -106,9 +106,9 @@ protected function setUp()
106106
public function testCopy(): void
107107
{
108108
$stockItem = $this->createMock(StockItemInterface::class);
109-
$extensionAttributes = $this->getMockBuilder(ProductExtension::class)
109+
$extensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class)
110110
->setMethods(['getStockItem', 'setData'])
111-
->getMock();
111+
->getMockForAbstractClass();
112112
$extensionAttributes
113113
->expects($this->once())
114114
->method('getStockItem')
@@ -262,9 +262,9 @@ public function testUrlAlreadyExistsExceptionWhileCopyStoresUrl(): void
262262
{
263263
$stockItem = $this->getMockBuilder(StockItemInterface::class)
264264
->getMock();
265-
$extensionAttributes = $this->getMockBuilder(ProductExtension::class)
265+
$extensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class)
266266
->setMethods(['getStockItem', 'setData'])
267-
->getMock();
267+
->getMockForAbstractClass();
268268
$extensionAttributes
269269
->expects($this->once())
270270
->method('getStockItem')

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,33 @@
66

77
namespace Magento\Catalog\Test\Unit\Model\Product\Website;
88

9-
use Magento\Catalog\Api\Data\ProductExtension;
9+
use Magento\Catalog\Api\Data\ProductExtensionInterface;
1010
use Magento\Catalog\Model\Product;
1111
use Magento\Catalog\Model\Product\Website\ReadHandler;
1212
use Magento\Catalog\Model\ResourceModel\Product as ResourceModel;
13+
use PHPUnit\Framework\MockObject\MockObject;
1314

1415
class ReadHandlerTest extends \PHPUnit\Framework\TestCase
1516
{
16-
/** @var ResourceModel\Website\Link | \PHPUnit_Framework_MockObject_MockObject */
17-
private $websiteLink;
17+
/** @var ResourceModel\Website\Link|MockObject */
18+
private $websiteLinkMock;
1819

19-
/** @var \PHPUnit_Framework_MockObject_MockObject */
20-
private $extensionAttributes;
20+
/** @var MockObject */
21+
private $extensionAttributesMock;
2122

2223
/** @var ReadHandler */
2324
private $readHandler;
2425

2526
public function setUp()
2627
{
27-
$this->websiteLink = $this->getMockBuilder(ResourceModel\Website\Link::class)
28+
$this->websiteLinkMock = $this->getMockBuilder(ResourceModel\Website\Link::class)
2829
->disableOriginalConstructor()
2930
->getMock();
30-
$this->extensionAttributes = $this->getMockBuilder(ProductExtension::class)
31+
$this->extensionAttributesMock = $this->getMockBuilder(ProductExtensionInterface::class)
3132
->setMethods(['setWebsiteIds', 'getWebsiteIds'])
3233
->disableArgumentCloning()
33-
->getMock();
34-
$this->readHandler = new ReadHandler($this->websiteLink);
34+
->getMockForAbstractClass();
35+
$this->readHandler = new ReadHandler($this->websiteLinkMock);
3536
}
3637

3738
public function testExecuteWithNonCachedExtensionAttributes()
@@ -44,20 +45,20 @@ public function testExecuteWithNonCachedExtensionAttributes()
4445
->method('getId')
4546
->willReturn($productId);
4647
$websiteIds = [1,2];
47-
$this->websiteLink->expects($this->once())
48+
$this->websiteLinkMock->expects($this->once())
4849
->method("getWebsiteIdsByProductId")
4950
->with($productId)
5051
->willReturn($websiteIds);
5152
$product->expects($this->exactly(2))
5253
->method('getExtensionAttributes')
53-
->willReturn($this->extensionAttributes);
54-
$this->extensionAttributes->expects($this->once())
54+
->willReturn($this->extensionAttributesMock);
55+
$this->extensionAttributesMock->expects($this->once())
5556
->method("getWebsiteIds")
5657
->willReturn(null);
5758

5859
$product->expects($this->once())
5960
->method('setExtensionAttributes')
60-
->with($this->extensionAttributes);
61+
->with($this->extensionAttributesMock);
6162

6263
$this->assertEquals($this->readHandler->execute($product, []), $product);
6364
}
@@ -68,15 +69,15 @@ public function testExecuteWithCachedWebsiteIds()
6869
->disableOriginalConstructor()
6970
->getMock();
7071
$websiteIds = [1,2];
71-
$this->extensionAttributes->expects($this->once())
72+
$this->extensionAttributesMock->expects($this->once())
7273
->method("getWebsiteIds")
7374
->willReturn($websiteIds);
7475
$product->expects($this->never())
7576
->method('setExtensionAttributes')
76-
->with($this->extensionAttributes);
77+
->with($this->extensionAttributesMock);
7778
$product->expects($this->once())
7879
->method('getExtensionAttributes')
79-
->willReturn($this->extensionAttributes);
80+
->willReturn($this->extensionAttributesMock);
8081
$this->assertEquals($this->readHandler->execute($product, []), $product);
8182
}
8283
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Magento\Catalog\Test\Unit\Model\Product\Website;
88

9-
use Magento\Catalog\Api\Data\ProductExtension;
9+
use Magento\Catalog\Api\Data\ProductExtensionInterface;
1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Model\ResourceModel\Product\Website\Link;
1212
use Magento\Catalog\Model\Product\Website\SaveHandler;
@@ -15,19 +15,20 @@
1515
use Magento\Framework\Api\ExtensionAttributesInterface;
1616
use Magento\Store\Api\Data\StoreInterface;
1717
use Magento\Store\Model\StoreManagerInterface;
18+
use PHPUnit\Framework\MockObject\MockObject;
1819

1920
class SaveHandlerTest extends \PHPUnit\Framework\TestCase
2021
{
21-
/** @var ResourceModel\Website\Link | \PHPUnit_Framework_MockObject_MockObject */
22+
/** @var ResourceModel\Website\Link|MockObject */
2223
private $productWebsiteLink;
2324

24-
/** @var StoreManagerInterface | \PHPUnit_Framework_MockObject_MockObject */
25+
/** @var StoreManagerInterface|MockObject */
2526
private $storeManager;
2627

2728
/** @var SaveHandler */
2829
private $saveHandler;
2930

30-
/** @var ProductInterface | \PHPUnit_Framework_MockObject_MockObject */
31+
/** @var ProductInterface|MockObject */
3132
private $product;
3233

3334
public function setUp()

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@
4242
use Magento\Store\Api\Data\StoreInterface;
4343
use Magento\Store\Model\Store;
4444
use Magento\Store\Model\StoreManagerInterface;
45+
use PHPUnit\Framework\MockObject\MockObject;
4546
use PHPUnit\Framework\TestCase;
46-
use PHPUnit_Framework_MockObject_MockObject as MockObject;
4747

4848
/**
49-
* Class ProductRepositoryTest
50-
* @package Magento\Catalog\Test\Unit\Model
5149
* @SuppressWarnings(PHPMD.TooManyFields)
5250
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
5351
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@
88

99
use Magento\ConfigurableProduct\Model\LinkManagement;
1010
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
11+
use PHPUnit\Framework\MockObject\MockObject;
1112

1213
/**
1314
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1415
*/
1516
class LinkManagementTest extends \PHPUnit\Framework\TestCase
1617
{
1718
/**
18-
* @var \PHPUnit_Framework_MockObject_MockObject
19+
* @var MockObject
1920
*/
2021
protected $productRepository;
2122

2223
/**
23-
* @var \PHPUnit_Framework_MockObject_MockObject
24+
* @var MockObject
2425
*/
2526
protected $productFactory;
2627

@@ -30,7 +31,7 @@ class LinkManagementTest extends \PHPUnit\Framework\TestCase
3031
protected $objectManagerHelper;
3132

3233
/**
33-
* @var \PHPUnit_Framework_MockObject_MockObject
34+
* @var MockObject
3435
*/
3536
protected $configurableType;
3637

@@ -40,7 +41,7 @@ class LinkManagementTest extends \PHPUnit\Framework\TestCase
4041
protected $object;
4142

4243
/**
43-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Api\DataObjectHelper
44+
* @var MockObject|\Magento\Framework\Api\DataObjectHelper
4445
*/
4546
protected $dataObjectHelperMock;
4647

@@ -149,7 +150,7 @@ public function testAddChild()
149150
->disableOriginalConstructor()
150151
->setMethods(['getId', 'getData'])
151152
->getMock();
152-
$extensionAttributesMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductExtension::class)
153+
$extensionAttributesMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductExtensionInterface::class)
153154
->disableOriginalConstructor()
154155
->setMethods(
155156
[
@@ -158,11 +159,11 @@ public function testAddChild()
158159
'setConfigurableProductLinks'
159160
]
160161
)
161-
->getMock();
162-
$optionMock = $this->getMockBuilder(\Magento\ConfigurableProduct\Api\Data\Option::class)
162+
->getMockForAbstractClass();
163+
$optionMock = $this->getMockBuilder(\Magento\ConfigurableProduct\Api\Data\OptionInterface::class)
163164
->disableOriginalConstructor()
164165
->setMethods(['getProductAttribute', 'getPosition', 'getAttributeId'])
165-
->getMock();
166+
->getMockForAbstractClass();
166167
$productAttributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
167168
->disableOriginalConstructor()
168169
->setMethods(['getAttributeCode'])

0 commit comments

Comments
 (0)