Skip to content

#27500 Prepare ConfigurableProduct module Tests for PHPUnit 8 #27822

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

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Test\Unit\Block\Adminhtml\Product\Edit\Button;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Button\Save as SaveButton;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\Registry;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class SaveTest extends \PHPUnit\Framework\TestCase
class SaveTest extends TestCase
{
/**
* @var SaveButton
Expand All @@ -23,16 +27,16 @@ class SaveTest extends \PHPUnit\Framework\TestCase
private $objectManagerHelper;

/**
* @var Registry|\PHPUnit_Framework_MockObject_MockObject
* @var Registry|MockObject
*/
private $registryMock;

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

protected function setUp()
protected function setUp(): void
{
$this->registryMock = $this->getMockBuilder(Registry::class)
->disableOriginalConstructor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,44 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Test\Unit\Block\Adminhtml\Product\Edit\Tab\Variations\Config;

/**
* Class MatrixTest
*/
class MatrixTest extends \PHPUnit\Framework\TestCase
use Magento\Backend\Block\Template\Context;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ProductFactory;
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\CatalogInventory\Api\StockRegistryInterface;
use Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Variations\Config\Matrix;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\View\LayoutInterface;
use Magento\Store\Model\Store;
use Magento\Ui\Block\Component\StepsWizard;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class MatrixTest extends TestCase
{
/**
* Object under test
*
* @var \Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Variations\Config\Matrix
* @var Matrix
*/
protected $_block;

/**
* @var \Magento\CatalogInventory\Api\StockRegistryInterface|\PHPUnit_Framework_MockObject_MockObject
* @var StockRegistryInterface|MockObject
*/
protected $stockRegistryMock;

protected function setUp()
protected function setUp(): void
{
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$objectHelper = new ObjectManager($this);

$this->stockRegistryMock = $this->getMockForAbstractClass(
\Magento\CatalogInventory\Api\StockRegistryInterface::class,
StockRegistryInterface::class,
[],
'',
false,
Expand All @@ -37,18 +50,17 @@ protected function setUp()
);

$context = $objectHelper->getObject(
\Magento\Backend\Block\Template\Context::class
Context::class
);
$data = [
'context' => $context,
'formFactory' => $this->createMock(\Magento\Framework\Data\FormFactory::class),
'productFactory' => $this->createMock(\Magento\Catalog\Model\ProductFactory::class),
'formFactory' => $this->createMock(FormFactory::class),
'productFactory' => $this->createMock(ProductFactory::class),
'stockRegistry' => $this->stockRegistryMock,
];
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->_object = $helper->getObject(\Magento\Config\Block\System\Config\Form::class, $data);
$helper = new ObjectManager($this);
$this->_block = $helper->getObject(
\Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Variations\Config\Matrix::class,
Matrix::class,
$data
);
}
Expand All @@ -64,10 +76,10 @@ public function testGetProductStockQty()
$websiteId = 99;
$qty = 100.00;

$productMock = $this->createPartialMock(\Magento\Catalog\Model\Product::class, ['getId', 'getStore']);
$storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getWebsiteId']);
$productMock = $this->createPartialMock(Product::class, ['getId', 'getStore']);
$storeMock = $this->createPartialMock(Store::class, ['getWebsiteId']);
$stockItemMock = $this->getMockForAbstractClass(
\Magento\CatalogInventory\Api\Data\StockItemInterface::class,
StockItemInterface::class,
[],
'',
false,
Expand Down Expand Up @@ -111,8 +123,8 @@ public function testGetVariationWizard($wizardBlockName, $wizardHtml)
]
];

$layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
$wizardBlock = $this->createMock(\Magento\Ui\Block\Component\StepsWizard::class);
$layout = $this->createMock(LayoutInterface::class);
$wizardBlock = $this->createMock(StepsWizard::class);
$layout->expects($this->any())->method('getChildName')->with(null, $wizardName)
->willReturn($wizardBlockName);
$layout->expects($this->any())->method('getBlock')->with($wizardBlockName)->willReturn($wizardBlock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,56 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Test\Unit\Block\Adminhtml\Product\Steps;

use Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\SelectAttributes;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Registry;
use Magento\Backend\Block\Widget\Button;
use Magento\Framework\View\LayoutInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\SelectAttributes;
use Magento\Framework\Registry;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\View\LayoutInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class SelectAttributesTest extends \PHPUnit\Framework\TestCase
class SelectAttributesTest extends TestCase
{
/**
* @var SelectAttributes
*/
private $selectAttributes;

/**
* @var Context|\PHPUnit_Framework_MockObject_MockObject
* @var Context|MockObject
*/
private $contextMock;

/**
* @var Registry|\PHPUnit_Framework_MockObject_MockObject
* @var Registry|MockObject
*/
private $registryMock;

/**
* @var Button|\PHPUnit_Framework_MockObject_MockObject
* @var Button|MockObject
*/
private $buttonMock;

/**
* @var LayoutInterface|\PHPUnit_Framework_MockObject_MockObject
* @var LayoutInterface|MockObject
*/
private $layoutMock;

/**
* @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject
* @var UrlInterface|MockObject
*/
private $urlBuilderMock;

/**
* {@inheritDoc}
*/
protected function setUp()
protected function setUp(): void
{
$this->contextMock = $this->getMockBuilder(Context::class)
->disableOriginalConstructor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,49 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Test\Unit\Block\Cart\Item\Renderer;

use Magento\Catalog\Model\Config\Source\Product\Thumbnail as ThumbnailSource;
use Magento\Catalog\Helper\Image;
use Magento\Catalog\Helper\Product\Configuration;
use Magento\Catalog\Model\Product;
use Magento\ConfigurableProduct\Block\Cart\Item\Renderer\Configurable as Renderer;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\View\ConfigInterface;
use Magento\Quote\Model\Quote\Item;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ConfigurableTest extends \PHPUnit\Framework\TestCase
class ConfigurableTest extends TestCase
{
/** @var \Magento\Framework\View\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
/** @var ConfigInterface|MockObject */
private $configManager;

/** @var \Magento\Catalog\Helper\Image|\PHPUnit_Framework_MockObject_MockObject */
/** @var Image|MockObject */
private $imageHelper;

/** @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
/** @var ScopeConfigInterface|MockObject */
private $scopeConfig;

/** @var \PHPUnit_Framework_MockObject_MockObject */
/** @var MockObject */
private $productConfigMock;

/** @var Renderer */
private $renderer;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->configManager = $this->createMock(\Magento\Framework\View\ConfigInterface::class);
$objectManagerHelper = new ObjectManager($this);
$this->configManager = $this->createMock(ConfigInterface::class);
$this->imageHelper = $this->createPartialMock(
\Magento\Catalog\Helper\Image::class,
Image::class,
['init', 'resize', '__toString']
);
$this->scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$this->productConfigMock = $this->createMock(\Magento\Catalog\Helper\Product\Configuration::class);
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
$this->productConfigMock = $this->createMock(Configuration::class);
$this->renderer = $objectManagerHelper->getObject(
\Magento\ConfigurableProduct\Block\Cart\Item\Renderer\Configurable::class,
[
Expand All @@ -49,7 +59,7 @@ protected function setUp()

public function testGetOptionList()
{
$itemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
$itemMock = $this->createMock(Item::class);
$this->renderer->setItem($itemMock);
$this->productConfigMock->expects($this->once())->method('getOptions')->with($itemMock);
$this->renderer->getOptionList();
Expand All @@ -58,9 +68,9 @@ public function testGetOptionList()
public function testGetIdentities()
{
$productTags = ['catalog_product_1'];
$product = $this->createMock(\Magento\Catalog\Model\Product::class);
$product = $this->createMock(Product::class);
$product->expects($this->exactly(2))->method('getIdentities')->will($this->returnValue($productTags));
$item = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
$item = $this->createMock(Item::class);
$item->expects($this->exactly(2))->method('getProduct')->will($this->returnValue($product));
$this->renderer->setItem($item);
$this->assertEquals(array_merge($productTags, $productTags), $this->renderer->getIdentities());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Test\Unit\Block\Plugin\Product\Media;

use Magento\ConfigurableProduct\Block\Plugin\Product\Media\Gallery;
use Magento\Catalog\Model\Product;
use Magento\ConfigurableProduct\Block\Plugin\Product\Media\Gallery;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Framework\DataObject;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Class GalleryTest
*/
class GalleryTest extends \PHPUnit\Framework\TestCase
class GalleryTest extends TestCase
{

public function testAfterGetOptions()
{
$jsonMock = $this->createJsonMock();
Expand All @@ -34,7 +37,7 @@ public function testAfterGetOptions()
]
]
];
$image = new \Magento\Framework\DataObject(
$image = new DataObject(
['media_type' => 'type', 'video_url' => 'url', 'file' => 'image.jpg']
);

Expand All @@ -49,7 +52,7 @@ public function testAfterGetOptions()
$jsonMock->expects($this->once())->method('serialize')->with($expectedGalleryJson)
->willReturn(json_encode($expectedGalleryJson));

$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$helper = new ObjectManager($this);
$plugin = $helper->getObject(
Gallery::class,
[
Expand All @@ -61,7 +64,7 @@ public function testAfterGetOptions()
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
* @return MockObject
*/
private function createJsonMock()
{
Expand All @@ -71,7 +74,7 @@ private function createJsonMock()
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
* @return MockObject
*/
private function createProductMock()
{
Expand All @@ -81,7 +84,7 @@ private function createProductMock()
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
* @return MockObject
*/
private function createGalleryMock()
{
Expand All @@ -91,11 +94,11 @@ private function createGalleryMock()
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
* @return MockObject
*/
private function createConfigurableTypeMock()
{
return $this->getMockBuilder(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::class)
return $this->getMockBuilder(Configurable::class)
->disableOriginalConstructor()
->getMock();
}
Expand Down
Loading