Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#27638 Fix fatal errors in Unit Tests #27701

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/code/Magento/Catalog/Test/Unit/Model/Product/CopierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

use Magento\Catalog\Api\Data\ProductExtension;
use Magento\Catalog\Api\Data\ProductExtensionInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
use Magento\Catalog\Model\Product;
Expand Down Expand Up @@ -106,9 +106,9 @@ protected function setUp()
public function testCopy(): void
{
$stockItem = $this->createMock(StockItemInterface::class);
$extensionAttributes = $this->getMockBuilder(ProductExtension::class)
$extensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class)
->setMethods(['getStockItem', 'setData'])
->getMock();
->getMockForAbstractClass();
$extensionAttributes
->expects($this->once())
->method('getStockItem')
Expand Down Expand Up @@ -262,9 +262,9 @@ public function testUrlAlreadyExistsExceptionWhileCopyStoresUrl(): void
{
$stockItem = $this->getMockBuilder(StockItemInterface::class)
->getMock();
$extensionAttributes = $this->getMockBuilder(ProductExtension::class)
$extensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class)
->setMethods(['getStockItem', 'setData'])
->getMock();
->getMockForAbstractClass();
$extensionAttributes
->expects($this->once())
->method('getStockItem')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@

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

use Magento\Catalog\Api\Data\ProductExtension;
use Magento\Catalog\Api\Data\ProductExtensionInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Website\ReadHandler;
use Magento\Catalog\Model\ResourceModel\Product as ResourceModel;
use PHPUnit\Framework\MockObject\MockObject;

class ReadHandlerTest extends \PHPUnit\Framework\TestCase
{
/** @var ResourceModel\Website\Link | \PHPUnit_Framework_MockObject_MockObject */
private $websiteLink;
/** @var ResourceModel\Website\Link|MockObject */
private $websiteLinkMock;

/** @var \PHPUnit_Framework_MockObject_MockObject */
private $extensionAttributes;
/** @var MockObject */
private $extensionAttributesMock;

/** @var ReadHandler */
private $readHandler;

public function setUp()
{
$this->websiteLink = $this->getMockBuilder(ResourceModel\Website\Link::class)
$this->websiteLinkMock = $this->getMockBuilder(ResourceModel\Website\Link::class)
->disableOriginalConstructor()
->getMock();
$this->extensionAttributes = $this->getMockBuilder(ProductExtension::class)
$this->extensionAttributesMock = $this->getMockBuilder(ProductExtensionInterface::class)
->setMethods(['setWebsiteIds', 'getWebsiteIds'])
->disableArgumentCloning()
->getMock();
$this->readHandler = new ReadHandler($this->websiteLink);
->getMockForAbstractClass();
$this->readHandler = new ReadHandler($this->websiteLinkMock);
}

public function testExecuteWithNonCachedExtensionAttributes()
Expand All @@ -44,20 +45,20 @@ public function testExecuteWithNonCachedExtensionAttributes()
->method('getId')
->willReturn($productId);
$websiteIds = [1,2];
$this->websiteLink->expects($this->once())
$this->websiteLinkMock->expects($this->once())
->method("getWebsiteIdsByProductId")
->with($productId)
->willReturn($websiteIds);
$product->expects($this->exactly(2))
->method('getExtensionAttributes')
->willReturn($this->extensionAttributes);
$this->extensionAttributes->expects($this->once())
->willReturn($this->extensionAttributesMock);
$this->extensionAttributesMock->expects($this->once())
->method("getWebsiteIds")
->willReturn(null);

$product->expects($this->once())
->method('setExtensionAttributes')
->with($this->extensionAttributes);
->with($this->extensionAttributesMock);

$this->assertEquals($this->readHandler->execute($product, []), $product);
}
Expand All @@ -68,15 +69,15 @@ public function testExecuteWithCachedWebsiteIds()
->disableOriginalConstructor()
->getMock();
$websiteIds = [1,2];
$this->extensionAttributes->expects($this->once())
$this->extensionAttributesMock->expects($this->once())
->method("getWebsiteIds")
->willReturn($websiteIds);
$product->expects($this->never())
->method('setExtensionAttributes')
->with($this->extensionAttributes);
->with($this->extensionAttributesMock);
$product->expects($this->once())
->method('getExtensionAttributes')
->willReturn($this->extensionAttributes);
->willReturn($this->extensionAttributesMock);
$this->assertEquals($this->readHandler->execute($product, []), $product);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

use Magento\Catalog\Api\Data\ProductExtension;
use Magento\Catalog\Api\Data\ProductExtensionInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\ResourceModel\Product\Website\Link;
use Magento\Catalog\Model\Product\Website\SaveHandler;
Expand All @@ -15,19 +15,20 @@
use Magento\Framework\Api\ExtensionAttributesInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;

class SaveHandlerTest extends \PHPUnit\Framework\TestCase
{
/** @var ResourceModel\Website\Link | \PHPUnit_Framework_MockObject_MockObject */
/** @var ResourceModel\Website\Link|MockObject */
private $productWebsiteLink;

/** @var StoreManagerInterface | \PHPUnit_Framework_MockObject_MockObject */
/** @var StoreManagerInterface|MockObject */
private $storeManager;

/** @var SaveHandler */
private $saveHandler;

/** @var ProductInterface | \PHPUnit_Framework_MockObject_MockObject */
/** @var ProductInterface|MockObject */
private $product;

public function setUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Class ProductRepositoryTest
* @package Magento\Catalog\Test\Unit\Model
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@

use Magento\ConfigurableProduct\Model\LinkManagement;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use PHPUnit\Framework\MockObject\MockObject;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class LinkManagementTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
protected $productRepository;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
protected $productFactory;

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

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
protected $configurableType;

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

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Api\DataObjectHelper
* @var MockObject|\Magento\Framework\Api\DataObjectHelper
*/
protected $dataObjectHelperMock;

Expand Down Expand Up @@ -149,7 +150,7 @@ public function testAddChild()
->disableOriginalConstructor()
->setMethods(['getId', 'getData'])
->getMock();
$extensionAttributesMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductExtension::class)
$extensionAttributesMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductExtensionInterface::class)
->disableOriginalConstructor()
->setMethods(
[
Expand All @@ -158,11 +159,11 @@ public function testAddChild()
'setConfigurableProductLinks'
]
)
->getMock();
$optionMock = $this->getMockBuilder(\Magento\ConfigurableProduct\Api\Data\Option::class)
->getMockForAbstractClass();
$optionMock = $this->getMockBuilder(\Magento\ConfigurableProduct\Api\Data\OptionInterface::class)
->disableOriginalConstructor()
->setMethods(['getProductAttribute', 'getPosition', 'getAttributeId'])
->getMock();
->getMockForAbstractClass();
$productAttributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
->disableOriginalConstructor()
->setMethods(['getAttributeCode'])
Expand Down