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 Weee module Tests for PHPUnit 8 #27819

Merged
merged 3 commits into from
Apr 15, 2020
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
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
Expand Down Expand Up @@ -92,7 +92,7 @@ class ContextPluginTest extends TestCase
*/
protected $contextPlugin;

protected function setUp()
protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);

Expand Down
33 changes: 22 additions & 11 deletions app/code/Magento/Weee/Test/Unit/Block/Element/Weee/TaxTest.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Weee\Test\Unit\Block\Element\Weee;

class TaxTest extends \PHPUnit\Framework\TestCase
use Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Weight;
use Magento\Framework\Data\Form\Element\CollectionFactory;
use Magento\Framework\Data\Form\Element\Factory;
use Magento\Framework\DataObject;
use Magento\Framework\Locale\Currency;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManager;
use Magento\Weee\Block\Element\Weee\Tax;
use PHPUnit\Framework\TestCase;

class TaxTest extends TestCase
{
/**
* @var \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Weight
* @var Weight
*/
protected $model;

public function testGetEscapedValue()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$objectManager = new ObjectManager($this);

$inputValue = [
['value' => '30000.4'],
];

$collectionFactory = $this->createPartialMock(
\Magento\Framework\Data\Form\Element\CollectionFactory::class,
CollectionFactory::class,
['create']
);

$storeManager = $this->createMock(\Magento\Store\Model\StoreManager::class);
$storeManager = $this->createMock(StoreManager::class);

$localeCurrency = $this->createMock(\Magento\Framework\Locale\Currency::class);
$localeCurrency = $this->createMock(Currency::class);

$currency = $this->createMock(\Magento\Framework\Currency::class);

Expand All @@ -43,18 +54,18 @@ public function testGetEscapedValue()
'getCurrency'
)->willReturn($currency);

$store = $this->createMock(\Magento\Store\Model\Store::class);
$store = $this->createMock(Store::class);

$storeManager->expects(
$this->any()
)->method(
'getStore'
)->willReturn($store);

$factory = $this->createMock(\Magento\Framework\Data\Form\Element\Factory::class);
$factory = $this->createMock(Factory::class);

$this->model = $objectManager->getObject(
\Magento\Weee\Block\Element\Weee\Tax::class,
Tax::class,
[
'factoryElement' => $factory,
'factoryCollection' => $collectionFactory,
Expand All @@ -64,7 +75,7 @@ public function testGetEscapedValue()
);

$this->model->setValue($inputValue);
$this->model->setEntityAttribute(new \Magento\Framework\DataObject(['store_id' => 1]));
$this->model->setEntityAttribute(new DataObject(['store_id' => 1]));

$return = $this->model->getEscapedValue();
$this->assertEquals(
Expand Down
31 changes: 19 additions & 12 deletions app/code/Magento/Weee/Test/Unit/Block/Item/Price/RendererTest.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Weee\Test\Unit\Block\Item\Price;

use Magento\Directory\Model\PriceCurrency;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Quote\Model\Quote\Item;
use Magento\Weee\Block\Item\Price\Renderer;
use Magento\Weee\Helper\Data;
use Magento\Weee\Model\Tax as WeeeDisplayConfig;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class RendererTest extends \PHPUnit\Framework\TestCase
class RendererTest extends TestCase
{
/**
* @var \Magento\Weee\Block\Item\Price\Renderer
* @var Renderer
*/
protected $renderer;

/**
* @var \Magento\Weee\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
* @var Data|MockObject
*/
protected $weeeHelper;

/**
* @var \Magento\Directory\Model\PriceCurrency|\PHPUnit_Framework_MockObject_MockObject
* @var PriceCurrency|MockObject
*/
protected $priceCurrency;

/**
* @var \Magento\Quote\Model\Quote\Item|\PHPUnit_Framework_MockObject_MockObject
* @var Item|MockObject
*/
protected $item;

const STORE_ID = 'store_id';
const ZONE = 'zone';

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

$this->weeeHelper = $this->getMockBuilder(\Magento\Weee\Helper\Data::class)
$this->weeeHelper = $this->getMockBuilder(Data::class)
->disableOriginalConstructor()
->setMethods([
'isEnabled',
Expand All @@ -48,12 +55,12 @@ protected function setUp()
])
->getMock();

$this->priceCurrency = $this->getMockBuilder(\Magento\Directory\Model\PriceCurrency::class)
$this->priceCurrency = $this->getMockBuilder(PriceCurrency::class)
->disableOriginalConstructor()
->setMethods(['format'])
->getMock();

$this->item = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item::class)
$this->item = $this->getMockBuilder(Item::class)
->disableOriginalConstructor()
->setMethods([
'__wakeup',
Expand All @@ -80,7 +87,7 @@ protected function setUp()
->will($this->returnValue(self::STORE_ID));

$this->renderer = $objectManager->getObject(
\Magento\Weee\Block\Item\Price\Renderer::class,
Renderer::class,
[
'weeeHelper' => $this->weeeHelper,
'priceCurrency' => $this->priceCurrency,
Expand Down
63 changes: 38 additions & 25 deletions app/code/Magento/Weee/Test/Unit/Helper/DataTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Weee\Test\Unit\Helper;

use Magento\Bundle\Model\Product\Type;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Type\Simple;
use Magento\Framework\DataObject;
use Magento\Framework\Registry;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Sales\Model\Order\Item;
use Magento\Store\Model\Store;
use Magento\Weee\Helper\Data as WeeeHelper;
use Magento\Weee\Model\Config;
use Magento\Weee\Model\Tax;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class DataTest extends \PHPUnit\Framework\TestCase
class DataTest extends TestCase
{
const ROW_AMOUNT_INVOICED = '200';
const BASE_ROW_AMOUNT_INVOICED = '400';
Expand All @@ -23,12 +36,12 @@ class DataTest extends \PHPUnit\Framework\TestCase
const BASE_TAX_AMOUNT_REFUNDED = '21';

/**
* @var \Magento\Catalog\Model\Product
* @var Product
*/
protected $product;

/**
* @var \Magento\Weee\Model\Tax
* @var Tax
*/
protected $weeeTax;

Expand All @@ -42,31 +55,31 @@ class DataTest extends \PHPUnit\Framework\TestCase
*/
protected $helperData;

/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
/** @var Json|MockObject */
private $serializerMock;

protected function setUp()
protected function setUp(): void
{
$this->product = $this->createMock(\Magento\Catalog\Model\Product::class);
$weeeConfig = $this->createMock(\Magento\Weee\Model\Config::class);
$this->product = $this->createMock(Product::class);
$weeeConfig = $this->createMock(Config::class);
$weeeConfig->expects($this->any())->method('isEnabled')->will($this->returnValue(true));
$weeeConfig->expects($this->any())->method('getListPriceDisplayType')->will($this->returnValue(1));
$this->weeeTax = $this->createMock(\Magento\Weee\Model\Tax::class);
$this->weeeTax = $this->createMock(Tax::class);
$this->weeeTax->expects($this->any())->method('getWeeeAmount')->will($this->returnValue('11.26'));
$this->taxData = $this->createPartialMock(
\Magento\Tax\Helper\Data::class,
['getPriceDisplayType', 'priceIncludesTax']
);

$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)->getMock();
$this->serializerMock = $this->getMockBuilder(Json::class)->getMock();

$arguments = [
'weeeConfig' => $weeeConfig,
'weeeTax' => $this->weeeTax,
'taxData' => $this->taxData,
'serializer' => $this->serializerMock
];
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$helper = new ObjectManager($this);
$this->helperData = $helper->getObject(\Magento\Weee\Helper\Data::class, $arguments);
}

Expand All @@ -79,11 +92,11 @@ public function testGetAmount()
}

/**
* @return \Magento\Sales\Model\Order\Item|\PHPUnit_Framework_MockObject_MockObject
* @return Item|MockObject
*/
private function setupOrderItem()
{
$orderItem = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class)
$orderItem = $this->getMockBuilder(Item::class)
->disableOriginalConstructor()
->setMethods(['__wakeup'])
->getMock();
Expand Down Expand Up @@ -192,31 +205,31 @@ public function testGetWeeeAttributesForBundle($priceDisplay, $priceIncludesTax,
$fptCode1 = 'fpt' . $prodId1;
$fptCode2 = 'fpt' . $prodId2;

$weeeObject1 = new \Magento\Framework\DataObject(
$weeeObject1 = new DataObject(
[
'code' => $fptCode1,
'amount' => '15',
'amount_excl_tax' => '15.0000',
'tax_amount' => '1'
]
);
$weeeObject2 = new \Magento\Framework\DataObject(
$weeeObject2 = new DataObject(
[
'code' => $fptCode2,
'amount' => '10',
'amount_excl_tax' => '10.0000',
'tax_amount' => '5'
]
);
$expectedObject1 = new \Magento\Framework\DataObject(
$expectedObject1 = new DataObject(
[
'code' => $fptCode1,
'amount' => $expectedAmount[0],
'amount_excl_tax' => '15.0000',
'tax_amount' => '1'
]
);
$expectedObject2 = new \Magento\Framework\DataObject(
$expectedObject2 = new DataObject(
[
'code' => $fptCode2,
'amount' => $expectedAmount[1],
Expand All @@ -236,23 +249,23 @@ public function testGetWeeeAttributesForBundle($priceDisplay, $priceIncludesTax,
->method('priceIncludesTax')
->willReturn($priceIncludesTax);

$productSimple = $this->createPartialMock(\Magento\Catalog\Model\Product\Type\Simple::class, ['getId']);
$productSimple = $this->createPartialMock(Simple::class, ['getId']);
$productSimple->expects($this->at(0))
->method('getId')
->will($this->returnValue($prodId1));
$productSimple->expects($this->at(1))
->method('getId')
->will($this->returnValue($prodId2));

$productInstance = $this->createMock(\Magento\Bundle\Model\Product\Type::class);
$productInstance = $this->createMock(Type::class);
$productInstance->expects($this->any())
->method('getSelectionsCollection')
->will($this->returnValue([$productSimple]));

$store=$this->createMock(\Magento\Store\Model\Store::class);
/** @var \Magento\Catalog\Model\Product $product */
$store=$this->createMock(Store::class);
/** @var Product $product */
$product = $this->createPartialMock(
\Magento\Catalog\Model\Product::class,
Product::class,
['getTypeInstance', 'getStoreId', 'getStore', 'getTypeId']
);
$product->expects($this->any())
Expand All @@ -268,7 +281,7 @@ public function testGetWeeeAttributesForBundle($priceDisplay, $priceIncludesTax,
->method('getTypeId')
->will($this->returnValue('bundle'));

$registry=$this->createMock(\Magento\Framework\Registry::class);
$registry=$this->createMock(Registry::class);
$registry->expects($this->any())
->method('registry')
->with('current_product')
Expand Down Expand Up @@ -431,7 +444,7 @@ public function testGetRecursiveAmountBundle()

public function testGetProductWeeeAttributesForDisplay()
{
$store = $this->createMock(\Magento\Store\Model\Store::class);
$store = $this->createMock(Store::class);
$this->product->expects($this->any())
->method('getStore')
->will($this->returnValue($store));
Expand All @@ -448,7 +461,7 @@ public function testGetTaxDisplayConfig()
$arguments = [
'taxData' => $taxData,
];
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$helper = new ObjectManager($this);
$helperData = $helper->getObject(\Magento\Weee\Helper\Data::class, $arguments);

$this->assertEquals($expected, $helperData->getTaxDisplayConfig());
Expand Down
Loading