Skip to content

Commit 24817ba

Browse files
committed
ACP2E-1120: update unit tests; fix static errors
1 parent 9dd5452 commit 24817ba

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

app/code/Magento/Payment/Model/Method/Free.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@
55
*/
66
namespace Magento\Payment\Model\Method;
77

8-
use Magento\Framework\Api\AttributeValueFactory;
9-
use Magento\Framework\Api\ExtensionAttributesFactory;
10-
use Magento\Framework\App\Config\ScopeConfigInterface;
118
use Magento\Framework\App\ObjectManager;
12-
use Magento\Framework\Data\Collection\AbstractDb;
13-
use Magento\Framework\Model\Context;
14-
use Magento\Framework\Model\ResourceModel\AbstractResource;
159
use Magento\Framework\Pricing\PriceCurrencyInterface;
16-
use Magento\Framework\Registry;
17-
use Magento\Payment\Helper\Data;
1810
use Magento\Sales\Model\Order\Config;
1911
use Magento\Sales\Model\Order\Status;
2012

@@ -26,21 +18,22 @@
2618
* Magento contains special flow for handling this payment method.
2719
* Inheritance is allowed to modify it behavior.
2820
*
21+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2922
* @api
3023
* @since 100.0.2
3124
*/
3225
class Free extends \Magento\Payment\Model\Method\AbstractMethod
3326
{
34-
const PAYMENT_METHOD_FREE_CODE = 'free';
27+
protected const PAYMENT_METHOD_FREE_CODE = 'free';
3528

3629
/**
3730
* XML Paths for configuration constants
3831
*/
39-
const XML_PATH_PAYMENT_FREE_ACTIVE = 'payment/free/active';
32+
protected const XML_PATH_PAYMENT_FREE_ACTIVE = 'payment/free/active';
4033

41-
const XML_PATH_PAYMENT_FREE_ORDER_STATUS = 'payment/free/order_status';
34+
protected const XML_PATH_PAYMENT_FREE_ORDER_STATUS = 'payment/free/order_status';
4235

43-
const XML_PATH_PAYMENT_FREE_PAYMENT_ACTION = 'payment/free/payment_action';
36+
protected const XML_PATH_PAYMENT_FREE_PAYMENT_ACTION = 'payment/free/payment_action';
4437

4538
/**
4639
* Payment Method features
@@ -146,6 +139,9 @@ public function getConfigPaymentAction()
146139
{
147140
$newStateStatuses = $this->config->getStateStatuses('new');
148141
$configNewOrderStatus = $this->getConfigData('order_status');
149-
return $configNewOrderStatus == 'pending' || array_key_exists($configNewOrderStatus, $newStateStatuses) ? null : parent::getConfigPaymentAction();
142+
return
143+
$configNewOrderStatus == 'pending' ||
144+
array_key_exists($configNewOrderStatus, $newStateStatuses) ?
145+
null : parent::getConfigPaymentAction();
150146
}
151147
}

app/code/Magento/Payment/Test/Unit/Model/Method/FreeTest.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Payment\Model\Method\Free;
1919
use Magento\Payment\Model\Method\Logger;
2020
use Magento\Quote\Model\Quote;
21+
use Magento\Sales\Model\Order\Config;
2122
use PHPUnit\Framework\MockObject\MockObject;
2223
use PHPUnit\Framework\TestCase;
2324
use Psr\Log\LoggerInterface;
@@ -42,6 +43,11 @@ class FreeTest extends TestCase
4243
*/
4344
protected $currencyPrice;
4445

46+
/**
47+
* @var MockObject
48+
*/
49+
protected $configMock;
50+
4551
/**
4652
* @inheritdoc
4753
*/
@@ -64,6 +70,8 @@ protected function setUp(): void
6470
->setConstructorArgs([$this->getMockForAbstractClass(LoggerInterface::class)])
6571
->getMock();
6672

73+
$this->configMock = $this->createMock(Config::class);
74+
6775
$this->methodFree = new Free(
6876
$context,
6977
$registry,
@@ -72,26 +80,32 @@ protected function setUp(): void
7280
$paymentData,
7381
$this->scopeConfig,
7482
$loggerMock,
75-
$this->currencyPrice
83+
$this->currencyPrice,
84+
null,
85+
null,
86+
[],
87+
$this->configMock
7688
);
7789
}
7890

7991
/**
8092
* @param string $orderStatus
8193
* @param string $paymentAction
8294
* @param mixed $result
95+
* @param array $stateStatuses
8396
*
8497
* @return void
8598
* @dataProvider getConfigPaymentActionProvider
8699
*/
87-
public function testGetConfigPaymentAction($orderStatus, $paymentAction, $result): void
100+
public function testGetConfigPaymentAction($orderStatus, $paymentAction, $result, $stateStatuses): void
88101
{
89-
90-
if ($orderStatus != 'pending') {
91-
$this->scopeConfig
92-
->method('getValue')
93-
->willReturnOnConsecutiveCalls($orderStatus, $paymentAction);
94-
}
102+
$this->configMock
103+
->method('getStateStatuses')
104+
->with('new')
105+
->willReturn($stateStatuses);
106+
$this->scopeConfig
107+
->method('getValue')
108+
->willReturnOnConsecutiveCalls($orderStatus, $paymentAction);
95109
$this->assertEquals($result, $this->methodFree->getConfigPaymentAction());
96110
}
97111

@@ -150,8 +164,10 @@ public function getIsAvailableProvider(): array
150164
public function getConfigPaymentActionProvider(): array
151165
{
152166
return [
153-
['pending', 'action', null],
154-
['processing', 'payment_action', 'payment_action']
167+
['pending', 'action', null, ['pending' => 'Pending']],
168+
['new', 'action', null, ['pending' => 'Pending', 'new' => 'New']],
169+
['new', 'payment_action', 'payment_action', ['pending' => 'Pending']],
170+
['processing', 'payment_action', 'payment_action', ['pending' => 'Pending']]
155171
];
156172
}
157173
}

0 commit comments

Comments
 (0)