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

magento/magento2#27500 - Replace deprecated constructs from OfflinePa… #27627

Merged
merged 4 commits into from
Apr 10, 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
Expand Up @@ -3,34 +3,41 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\OfflinePayments\Test\Unit\Block\Form;

class AbstractInstructionTest extends \PHPUnit\Framework\TestCase
use Magento\Framework\View\Element\Template\Context;
use Magento\OfflinePayments\Block\Form\AbstractInstruction;
use Magento\Payment\Model\MethodInterface;
use PHPUnit\Framework\TestCase;

class AbstractInstructionTest extends TestCase
{
/**
* @var \Magento\OfflinePayments\Block\Form\AbstractInstruction
* @var AbstractInstruction
*/
protected $_model;
protected $model;

protected function setUp()
protected function setUp(): void
{
$context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
$this->_model = $this->getMockForAbstractClass(
\Magento\OfflinePayments\Block\Form\AbstractInstruction::class,
$context = $this->createMock(Context::class);
$this->model = $this->getMockForAbstractClass(
AbstractInstruction::class,
['context' => $context]
);
}

public function testGetInstructions()
{
$method = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
$method = $this->getMockBuilder(MethodInterface::class)
->getMockForAbstractClass();

$method->expects($this->once())
->method('getConfigData')
->willReturn('instructions');
$this->_model->setData('method', $method);
$this->model->setData('method', $method);

$this->assertEquals('instructions', $this->_model->getInstructions());
$this->assertEquals('instructions', $this->model->getInstructions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

cristiano-pacheco marked this conversation as resolved.
Show resolved Hide resolved
namespace Magento\OfflinePayments\Test\Unit\Block\Info;

use Magento\Framework\View\Element\Template\Context;
use Magento\OfflinePayments\Block\Info\Checkmo;
use Magento\Payment\Model\Info;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* CheckmoTest contains list of test for block methods testing
*/
class CheckmoTest extends \PHPUnit\Framework\TestCase
class CheckmoTest extends TestCase
{
/**
* @var Info|MockObject
*/
private $info;
private $infoMock;

/**
* @var Checkmo
Expand All @@ -28,14 +31,14 @@ class CheckmoTest extends \PHPUnit\Framework\TestCase
/**
* @inheritdoc
*/
protected function setUp()
protected function setUp(): void
{
$context = $this->getMockBuilder(Context::class)
->disableOriginalConstructor()
->setMethods([])
->getMock();

$this->info = $this->getMockBuilder(Info::class)
$this->infoMock = $this->getMockBuilder(Info::class)
->disableOriginalConstructor()
->setMethods(['getAdditionalInformation'])
->getMock();
Expand All @@ -51,11 +54,11 @@ protected function setUp()
*/
public function testGetPayableTo($details, $expected)
{
$this->info->expects(static::at(0))
$this->infoMock->expects(static::at(0))
->method('getAdditionalInformation')
->with('payable_to')
->willReturn($details);
$this->block->setData('info', $this->info);
$this->block->setData('info', $this->infoMock);

static::assertEquals($expected, $this->block->getPayableTo());
}
Expand All @@ -80,11 +83,11 @@ public function getPayableToDataProvider()
*/
public function testGetMailingAddress($details, $expected)
{
$this->info->expects(static::at(1))
$this->infoMock->expects(static::at(1))
->method('getAdditionalInformation')
->with('mailing_address')
->willReturn($details);
$this->block->setData('info', $this->info);
$this->block->setData('info', $this->infoMock);

static::assertEquals($expected, $this->block->getMailingAddress());
}
Expand All @@ -107,11 +110,11 @@ public function getMailingAddressDataProvider()
public function testConvertAdditionalDataIsNeverCalled()
{
$mailingAddress = 'blah@blah.com';
$this->info->expects(static::at(1))
$this->infoMock->expects(static::at(1))
->method('getAdditionalInformation')
->with('mailing_address')
->willReturn($mailingAddress);
$this->block->setData('info', $this->info);
$this->block->setData('info', $this->infoMock);

// First we set the property $this->_mailingAddress
$this->block->getMailingAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,49 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\OfflinePayments\Test\Unit\Model;

class BanktransferTest extends \PHPUnit\Framework\TestCase
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\OfflinePayments\Model\Banktransfer;
use Magento\Payment\Block\Info\Instructions;
use Magento\Payment\Helper\Data;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class BanktransferTest extends TestCase
{
/**
* @var \Magento\OfflinePayments\Model\Banktransfer
* @var Banktransfer
*/
protected $_object;
private $object;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var ScopeConfigInterface|MockObject
*/
protected $_scopeConfig;
private $scopeConfigMock;

protected function setUp()
protected function setUp(): void
{
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$eventManager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
$paymentDataMock = $this->createMock(\Magento\Payment\Helper\Data::class);
$this->_scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$this->_object = $objectManagerHelper->getObject(
\Magento\OfflinePayments\Model\Banktransfer::class,
$objectManagerHelper = new ObjectManager($this);
$eventManager = $this->createMock(ManagerInterface::class);
$paymentDataMock = $this->createMock(Data::class);
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
$this->object = $objectManagerHelper->getObject(
Banktransfer::class,
[
'eventManager' => $eventManager,
'paymentData' => $paymentDataMock,
'scopeConfig' => $this->_scopeConfig,
'scopeConfig' => $this->scopeConfigMock,
]
);
}

public function testGetInfoBlockType()
{
$this->assertEquals(\Magento\Payment\Block\Info\Instructions::class, $this->_object->getInfoBlockType());
$this->assertEquals(Instructions::class, $this->object->getInfoBlockType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,51 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\OfflinePayments\Test\Unit\Model;

class CashondeliveryTest extends \PHPUnit\Framework\TestCase
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\OfflinePayments\Model\Cashondelivery;
use Magento\Payment\Block\Info\Instructions;
use Magento\Payment\Helper\Data;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class CashondeliveryTest extends TestCase
{
/**
* @var \Magento\OfflinePayments\Model\Cashondelivery
* @var Cashondelivery
*/
protected $_object;
private $object;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var ScopeConfigInterface|MockObject
*/
protected $_scopeConfig;
private $scopeConfigMock;

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

$eventManager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
$paymentDataMock = $this->createMock(\Magento\Payment\Helper\Data::class);
$eventManager = $this->createMock(ManagerInterface::class);
$paymentDataMock = $this->createMock(Data::class);

$this->_scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$this->_object = $helper->getObject(
\Magento\OfflinePayments\Model\Cashondelivery::class,
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
$this->object = $helper->getObject(
Cashondelivery::class,
[
'eventManager' => $eventManager,
'paymentData' => $paymentDataMock,
'scopeConfig' => $this->_scopeConfig,
'scopeConfig' => $this->scopeConfigMock,
]
);
}

public function testGetInfoBlockType()
{
$this->assertEquals(\Magento\Payment\Block\Info\Instructions::class, $this->_object->getInfoBlockType());
$this->assertEquals(Instructions::class, $this->object->getInfoBlockType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,46 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

cristiano-pacheco marked this conversation as resolved.
Show resolved Hide resolved
namespace Magento\OfflinePayments\Test\Unit\Model;

use Magento\OfflinePayments\Model\CheckmoConfigProvider;
use Magento\OfflinePayments\Model\Checkmo;
use Magento\Framework\Escaper;
use Magento\OfflinePayments\Model\Checkmo;
use Magento\OfflinePayments\Model\CheckmoConfigProvider;
use Magento\Payment\Helper\Data as PaymentHelper;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class CheckmoConfigProviderTest extends \PHPUnit\Framework\TestCase
class CheckmoConfigProviderTest extends TestCase
{
/** @var CheckmoConfigProvider */
protected $model;
/**
* @var CheckmoConfigProvider
*/
private $model;

/** @var Checkmo|\PHPUnit_Framework_MockObject_MockObject */
protected $methodMock;
/**
* @var Checkmo|MockObject
*/
private $methodMock;

/** @var Escaper|\PHPUnit_Framework_MockObject_MockObject */
protected $escaperMock;
/**
* @var Escaper|MockObject
*/
private $escaperMock;

protected function setUp()
protected function setUp(): void
{
$this->methodMock = $this->createMock(\Magento\OfflinePayments\Model\Checkmo::class);
$this->methodMock = $this->createMock(Checkmo::class);

$paymentHelperMock = $this->createMock(\Magento\Payment\Helper\Data::class);
/** @var PaymentHelper|MockObject $paymentHelperMock */
$paymentHelperMock = $this->createMock(PaymentHelper::class);
$paymentHelperMock->expects($this->once())
->method('getMethodInstance')
->with(Checkmo::PAYMENT_METHOD_CHECKMO_CODE)
->willReturn($this->methodMock);

$this->escaperMock = $this->createMock(\Magento\Framework\Escaper::class);
$this->escaperMock = $this->createMock(Escaper::class);
$this->escaperMock->expects($this->any())
->method('escapeHtml')
->willReturnArgument(0);
Expand Down
Loading