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

#27500 Prepare Catalog module Tests for PHPUnit 8 #27823

Merged
merged 16 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,66 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Category;

class AbstractCategoryTest extends \PHPUnit\Framework\TestCase
use Magento\Backend\Block\Template\Context;
use Magento\Catalog\Block\Adminhtml\Category\AbstractCategory;
use Magento\Catalog\Model\Category;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class AbstractCategoryTest extends TestCase
{
/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
* @var ObjectManager
*/
protected $objectManager;

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

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

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

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

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

/**
* @var \Magento\Catalog\Block\Adminhtml\Category\AbstractCategory
* @var AbstractCategory
*/
protected $category;

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

$this->contextMock = $this->createMock(\Magento\Backend\Block\Template\Context::class);
$this->contextMock = $this->createMock(Context::class);

$this->requestMock = $this->getMockBuilder(
\Magento\Framework\App\RequestInterface::class
RequestInterface::class
)
->disableOriginalConstructor()
->getMock();
Expand All @@ -60,13 +72,13 @@ protected function setUp()
->will($this->returnValue($this->requestMock));

$this->urlBuilderMock = $this->getMockBuilder(
\Magento\Framework\UrlInterface::class
UrlInterface::class
)
->disableOriginalConstructor()
->getMock();

$this->storeManagerMock = $this->getMockBuilder(
\Magento\Store\Model\StoreManagerInterface::class
StoreManagerInterface::class
)
->disableOriginalConstructor()
->getMock();
Expand All @@ -75,7 +87,7 @@ protected function setUp()
->method('getStoreManager')
->will($this->returnValue($this->storeManagerMock));

$this->storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
$this->storeMock = $this->getMockBuilder(Store::class)
->disableOriginalConstructor()
->getMock();

Expand All @@ -84,7 +96,7 @@ protected function setUp()
->will($this->returnValue($this->urlBuilderMock));

$this->category = $this->objectManager->getObject(
\Magento\Catalog\Block\Adminhtml\Category\AbstractCategory::class,
AbstractCategory::class,
[
'context' => $this->contextMock,
]
Expand Down Expand Up @@ -129,6 +141,6 @@ public function testGetRootIds()
$this->storeManagerMock->expects($this->once())->method('getGroups')->willReturn([$this->storeMock]);
$this->storeMock->expects($this->once())->method('getRootCategoryId')->willReturn('storeId');

$this->assertEquals([\Magento\Catalog\Model\Category::TREE_ROOT_ID, 'storeId'], $this->category->getRootIds());
$this->assertEquals([Category::TREE_ROOT_ID, 'storeId'], $this->category->getRootIds());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute\Button;

use Magento\Catalog\Block\Adminhtml\Product\Attribute\Button\Cancel;

/**
* Class CancelTest
*/
class CancelTest extends GenericTest
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute\Button;

use Magento\Catalog\Block\Adminhtml\Product\Edit\Button\Generic;
use Magento\Framework\Registry;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\View\Element\UiComponent\Context;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Class GenericTest
*/
class GenericTest extends \PHPUnit\Framework\TestCase
class GenericTest extends TestCase
{
/**
* @var Context|\PHPUnit_Framework_MockObject_MockObject
* @var Context|MockObject
*/
protected $contextMock;

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

Expand All @@ -30,7 +31,7 @@ class GenericTest extends \PHPUnit\Framework\TestCase
*/
protected $objectManager;

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

namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute\Button;

use Magento\Catalog\Block\Adminhtml\Product\Attribute\Button\Save;

/**
* Class SaveTest
*/
class SaveTest extends GenericTest
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute\Edit\Tab;

use Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Advanced;
Expand All @@ -22,13 +24,14 @@
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Test product attribute add/edit advanced form tab
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AdvancedTest extends \PHPUnit\Framework\TestCase
class AdvancedTest extends TestCase
{
/**
* @var Advanced
Expand Down Expand Up @@ -73,7 +76,7 @@ class AdvancedTest extends \PHPUnit\Framework\TestCase
/**
* @inheritdoc
*/
protected function setUp()
protected function setUp(): void
{
$objectManager = new ObjectManager($this);
$this->registry = $this->createMock(Registry::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute;

class GridTest extends \PHPUnit\Framework\TestCase
use Magento\Backend\Block\Template\Context;
use Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Framework\Filesystem;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\UrlInterface;
use PHPUnit\Framework\TestCase;

class GridTest extends TestCase
{
public function testGetRowUrl()
{
$attribute = $this->createMock(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
$attribute = $this->createMock(Attribute::class);
$attribute->expects($this->once())->method('getAttributeId')->will($this->returnValue(2));

$filesystem = $this->createMock(\Magento\Framework\Filesystem::class);
$filesystem = $this->createMock(Filesystem::class);

$urlBuilder = $this->createMock(\Magento\Framework\UrlInterface::class);
$urlBuilder = $this->createMock(UrlInterface::class);
$urlBuilder->expects(
$this->once()
)->method(
Expand All @@ -26,15 +36,15 @@ public function testGetRowUrl()
$this->returnValue('catalog/product_attribute/edit/id/2')
);

$context = $this->createMock(\Magento\Backend\Block\Template\Context::class);
$context = $this->createMock(Context::class);
$context->expects($this->once())->method('getUrlBuilder')->will($this->returnValue($urlBuilder));
$context->expects($this->any())->method('getFilesystem')->will($this->returnValue($filesystem));

$data = ['context' => $context];

$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
/** @var \Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid $block */
$block = $helper->getObject(\Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid::class, $data);
$helper = new ObjectManager($this);
/** @var Grid $block */
$block = $helper->getObject(Grid::class, $data);

$this->assertEquals('catalog/product_attribute/edit/id/2', $block->getRowUrl($attribute));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,68 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Composite\Fieldset;

use Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Options;
use Magento\Catalog\Model\CategoryFactory;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Configuration\Item\OptionFactory;
use Magento\Catalog\Model\ProductFactory;
use Magento\Catalog\Model\ResourceModel\Product\Option;
use Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory;
use Magento\Framework\Data\CollectionFactory;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\View\Layout;
use PHPUnit\Framework\TestCase;

/**
* Test class for \Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Options
*
* @SuppressWarnings(PHPMD.LongVariable)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class OptionsTest extends \PHPUnit\Framework\TestCase
class OptionsTest extends TestCase
{
/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
* @var ObjectManager
*/
protected $_objectHelper;

/**
* @var \Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Options
* @var Options
*/
protected $_optionsBlock;

/**
* @var \Magento\Catalog\Model\ResourceModel\Product\Option
* @var Option
*/
protected $_optionResource;

protected function setUp()
protected function setUp(): void
{
$this->_objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->_optionResource = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product\Option::class);
$this->_objectHelper = new ObjectManager($this);
$this->_optionResource = $this->createMock(Option::class);
}

public function testGetOptionHtml()
{
$layout = $this->createPartialMock(
\Magento\Framework\View\Layout::class,
Layout::class,
['getChildName', 'getBlock', 'renderElement']
);
$context = $this->_objectHelper->getObject(
\Magento\Framework\View\Element\Template\Context::class,
Context::class,
['layout' => $layout]
);
$optionFactoryMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\ValueFactory::class)
->setMethods(['create'])
->disableOriginalConstructor()
->getMock();

$optionFactoryMock = $this->createPartialMock('\Magento\Catalog\Model\Product\Option\ValueFactory', ['create']);
$option = $this->_objectHelper->getObject(
\Magento\Catalog\Model\Product\Option::class,
['resource' => $this->_optionResource, 'optionValueFactory' => $optionFactoryMock]
);
$dateBlock = $this->getMockBuilder(\Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Options::class)
$dateBlock = $this->getMockBuilder(Options::class)
->setMethods(['setSkipJsReloadPrice'])
->setConstructorArgs(['context' => $context, 'option' => $option])
->disableOriginalConstructor()
Expand All @@ -65,26 +76,26 @@ public function testGetOptionHtml()
$layout->expects($this->any())->method('renderElement')->with('date', false)->will($this->returnValue('html'));

$this->_optionsBlock = $this->_objectHelper->getObject(
\Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Options::class,
Options::class,
['context' => $context, 'option' => $option]
);

$itemOptFactoryMock = $this->createPartialMock(
\Magento\Catalog\Model\Product\Configuration\Item\OptionFactory::class,
OptionFactory::class,
['create']
);
$stockItemFactoryMock = $this->createPartialMock(
\Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory::class,
StockItemInterfaceFactory::class,
['create']
);
$productFactoryMock = $this->createPartialMock(\Magento\Catalog\Model\ProductFactory::class, ['create']);
$categoryFactoryMock = $this->createPartialMock(\Magento\Catalog\Model\CategoryFactory::class, ['create']);
$productFactoryMock = $this->createPartialMock(ProductFactory::class, ['create']);
$categoryFactoryMock = $this->createPartialMock(CategoryFactory::class, ['create']);

$this->_optionsBlock->setProduct(
$this->_objectHelper->getObject(
\Magento\Catalog\Model\Product::class,
Product::class,
[
'collectionFactory' => $this->createMock(\Magento\Framework\Data\CollectionFactory::class),
'collectionFactory' => $this->createMock(CollectionFactory::class),
'itemOptionFactory' => $itemOptFactoryMock,
'stockItemFactory' => $stockItemFactoryMock,
'productFactory' => $productFactoryMock,
Expand Down
Loading