Skip to content

Commit

Permalink
#27500 Prepare GroupedProduct module Tests for PHPUnit 8
Browse files Browse the repository at this point in the history
  • Loading branch information
lbajsarowicz committed Apr 12, 2020
1 parent 86515dd commit 99e517f
Show file tree
Hide file tree
Showing 25 changed files with 637 additions and 440 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GroupedProduct\Test\Unit\Block\Adminhtml\Order\Create;

class SidebarTest extends \PHPUnit\Framework\TestCase
use Magento\Catalog\Model\Product;
use Magento\Framework\DataObject;
use Magento\GroupedProduct\Block\Adminhtml\Order\Create\Sidebar;
use Magento\GroupedProduct\Model\Product\Type\Grouped;
use Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class SidebarTest extends TestCase
{
/**
* @var \Magento\GroupedProduct\Block\Adminhtml\Order\Create\Sidebar
* @var Sidebar
*/
protected $sidebarMock;

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

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

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

Expand All @@ -32,17 +40,17 @@ class SidebarTest extends \PHPUnit\Framework\TestCase
*/
protected $closureMock;

protected function setUp()
protected function setUp(): void
{
$this->itemMock = $this->createPartialMock(\Magento\Framework\DataObject::class, ['getProduct']);
$this->productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
$this->itemMock = $this->createPartialMock(DataObject::class, ['getProduct']);
$this->productMock = $this->createMock(Product::class);
$this->subjectMock = $this->createMock(
\Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar::class
AbstractSidebar::class
);
$this->closureMock = function () {
return 'Expected';
};
$this->sidebarMock = new \Magento\GroupedProduct\Block\Adminhtml\Order\Create\Sidebar();
$this->sidebarMock = new Sidebar();
}

public function testAroundGetItemQtyWhenProductGrouped()
Expand All @@ -53,7 +61,7 @@ public function testAroundGetItemQtyWhenProductGrouped()
)->method(
'getTypeId'
)->will(
$this->returnValue(\Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE)
$this->returnValue(Grouped::TYPE_CODE)
);
$this->assertEquals(
'',
Expand All @@ -75,7 +83,7 @@ public function testAroundIsConfigurationRequiredWhenProductGrouped()
$this->sidebarMock->aroundIsConfigurationRequired(
$this->subjectMock,
$this->closureMock,
\Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE
Grouped::TYPE_CODE
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,64 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GroupedProduct\Test\Unit\Block\Adminhtml\Product\Composite\Fieldset;

class GroupedTest extends \PHPUnit\Framework\TestCase
use Magento\Catalog\Model\Product;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Framework\DataObject;
use Magento\Framework\Pricing\Helper\Data;
use Magento\Framework\Registry;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\GroupedProduct\Block\Adminhtml\Product\Composite\Fieldset\Grouped;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class GroupedTest extends TestCase
{
/**
* @var \Magento\GroupedProduct\Block\Adminhtml\Product\Composite\Fieldset\Grouped
* @var Grouped
*/
protected $block;

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

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

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

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

protected function setUp()
protected function setUp(): void
{
$this->registryMock = $this->createMock(\Magento\Framework\Registry::class);
$this->productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
$this->pricingHelperMock = $this->createMock(\Magento\Framework\Pricing\Helper\Data::class);
$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
$this->registryMock = $this->createMock(Registry::class);
$this->productMock = $this->createMock(Product::class);
$this->pricingHelperMock = $this->createMock(Data::class);
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);

$customerMock = $this->getMockBuilder(
\Magento\Customer\Api\Data\CustomerInterface::class
CustomerInterface::class
)->disableOriginalConstructor()->getMock();
$customerMock->expects($this->any())->method('getId')->will($this->returnValue(1));

$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$objectHelper = new ObjectManager($this);
$this->block = $objectHelper->getObject(
\Magento\GroupedProduct\Block\Adminhtml\Product\Composite\Fieldset\Grouped::class,
Grouped::class,
[
'registry' => $this->registryMock,
'storeManager' => $this->storeManagerMock,
Expand All @@ -62,7 +74,7 @@ protected function setUp()
public function testGetProductPositive()
{
$instanceMock = $this->createMock(\Magento\GroupedProduct\Model\Product\Type\Grouped::class);
$storeMock = $this->createMock(\Magento\Store\Model\Store::class);
$storeMock = $this->createMock(Store::class);

$this->productMock->expects($this->any())->method('getTypeInstance')->will($this->returnValue($instanceMock));

Expand All @@ -80,7 +92,7 @@ public function testGetProductNegative()
{
$storeId = 2;
$instanceMock = $this->createMock(\Magento\GroupedProduct\Model\Product\Type\Grouped::class);
$storeMock = $this->createMock(\Magento\Store\Model\Store::class);
$storeMock = $this->createMock(Store::class);

$this->productMock->expects($this->any())->method('getTypeInstance')->will($this->returnValue($instanceMock));

Expand Down Expand Up @@ -148,7 +160,7 @@ public function testSetPreconfiguredValue()
{
$storeId = 2;

$objectMock = $this->createPartialMock(\Magento\Framework\DataObject::class, ['getSuperGroup']);
$objectMock = $this->createPartialMock(DataObject::class, ['getSuperGroup']);
$instanceMock = $this->createMock(\Magento\GroupedProduct\Model\Product\Type\Grouped::class);

$objectMock->expects($this->once())->method('getSuperGroup')->will($this->returnValue([]));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GroupedProduct\Test\Unit\Block\Cart\Item\Renderer;

use Magento\Catalog\Model\Config\Source\Product\Thumbnail as ThumbnailSource;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\GroupedProduct\Block\Cart\Item\Renderer\Grouped as Renderer;
use Magento\Quote\Model\Quote\Item;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class GroupedTest extends \PHPUnit\Framework\TestCase
class GroupedTest extends TestCase
{
/** @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
/** @var ScopeConfigInterface|MockObject */
private $scopeConfig;

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

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$objectManagerHelper = new ObjectManager($this);
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
$this->renderer = $objectManagerHelper->getObject(
\Magento\GroupedProduct\Block\Cart\Item\Renderer\Grouped::class,
['scopeConfig' => $this->scopeConfig]
Expand All @@ -30,9 +35,9 @@ protected function setUp()
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
@@ -1,60 +1,72 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GroupedProduct\Test\Unit\Block\Product\Grouped\AssociatedProducts;

class ListAssociatedProductsTest extends \PHPUnit\Framework\TestCase
use Magento\Backend\Block\Template\Context;
use Magento\Catalog\Model\Product;
use Magento\Framework\DataObject;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\Registry;
use Magento\GroupedProduct\Block\Product\Grouped\AssociatedProducts\ListAssociatedProducts;
use Magento\GroupedProduct\Model\Product\Type\Grouped;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ListAssociatedProductsTest extends TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
protected $contextMock;

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

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

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

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

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

/**
* @var \Magento\GroupedProduct\Block\Product\Grouped\AssociatedProducts\ListAssociatedProducts
* @var ListAssociatedProducts
*/
protected $block;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\PriceCurrencyInterface
* @var MockObject|PriceCurrencyInterface
*/
protected $priceCurrency;

protected function setUp()
protected function setUp(): void
{
$this->contextMock = $this->createMock(\Magento\Backend\Block\Template\Context::class);
$this->registryMock = $this->createMock(\Magento\Framework\Registry::class);
$this->productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
$this->storeMock = $this->createMock(\Magento\Store\Model\Store::class);
$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManager::class);
$this->typeInstanceMock = $this->createMock(\Magento\GroupedProduct\Model\Product\Type\Grouped::class);
$this->contextMock = $this->createMock(Context::class);
$this->registryMock = $this->createMock(Registry::class);
$this->productMock = $this->createMock(Product::class);
$this->storeMock = $this->createMock(Store::class);
$this->storeManagerMock = $this->createMock(StoreManager::class);
$this->typeInstanceMock = $this->createMock(Grouped::class);

$this->contextMock->expects(
$this->any()
Expand All @@ -65,10 +77,10 @@ protected function setUp()
);

$this->priceCurrency = $this->getMockBuilder(
\Magento\Framework\Pricing\PriceCurrencyInterface::class
PriceCurrencyInterface::class
)->getMock();

$this->block = new \Magento\GroupedProduct\Block\Product\Grouped\AssociatedProducts\ListAssociatedProducts(
$this->block = new ListAssociatedProducts(
$this->contextMock,
$this->registryMock,
$this->priceCurrency
Expand Down Expand Up @@ -148,12 +160,12 @@ public function testGetAssociatedProducts()
* Generate associated product mock
*
* @param int $productKey
* @return \PHPUnit_Framework_MockObject_MockObject
* @return MockObject
*/
protected function generateAssociatedProduct($productKey = 0)
{
$associatedProduct = $this->createPartialMock(
\Magento\Framework\DataObject::class,
DataObject::class,
['getQty', 'getPosition', 'getId', 'getSku', 'getName', 'getPrice']
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GroupedProduct\Test\Unit\Block\Product\Grouped;

class AssociatedProductsTest extends \PHPUnit\Framework\TestCase
use Magento\Backend\Block\Template\Context;
use Magento\GroupedProduct\Block\Product\Grouped\AssociatedProducts;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class AssociatedProductsTest extends TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
protected $contextMock;

/**
* @var \Magento\GroupedProduct\Block\Product\Grouped\AssociatedProducts
* @var AssociatedProducts
*/
protected $block;

protected function setUp()
protected function setUp(): void
{
$this->contextMock = $this->createMock(\Magento\Backend\Block\Template\Context::class);
$this->block = new \Magento\GroupedProduct\Block\Product\Grouped\AssociatedProducts($this->contextMock);
$this->contextMock = $this->createMock(Context::class);
$this->block = new AssociatedProducts($this->contextMock);
}

/**
Expand Down
Loading

0 comments on commit 99e517f

Please sign in to comment.