Skip to content

Commit b60f1b0

Browse files
committed
AC-15105:[CE] PHPUnit 12: Upgrade Payment & Shipping related test cases
1 parent 8e52879 commit b60f1b0

File tree

57 files changed

+665
-993
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+665
-993
lines changed

app/code/Magento/Paypal/Test/Unit/Model/AbstractConfigTest.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Payment\Model\MethodInterface;
1414
use Magento\Store\Model\ScopeInterface;
1515
use Magento\Store\Model\ScopeInterface as ModelScopeInterface;
16+
use PHPUnit\Framework\Attributes\DataProvider;
1617
use PHPUnit\Framework\MockObject\MockObject;
1718
use PHPUnit\Framework\TestCase;
1819

@@ -34,18 +35,16 @@ class AbstractConfigTest extends TestCase
3435

3536
protected function setUp(): void
3637
{
37-
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
38-
->onlyMethods(['getValue', 'isSetFlag'])
39-
->getMockForAbstractClass();
38+
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
4039

4140
$this->config = new AbstractConfigTesting($this->scopeConfigMock);
4241
}
4342

4443
/**
4544
* @param string|MethodInterface $method
4645
* @param $expected
47-
* @dataProvider setMethodDataProvider
4846
*/
47+
#[DataProvider('setMethodDataProvider')]
4948
public function testSetMethod($method, $expected)
5049
{
5150
if (is_callable($method)) {
@@ -58,14 +57,13 @@ public function testSetMethod($method, $expected)
5857
public function testSetMethodInstance()
5958
{
6059
/** @var MethodInterface $methodInterfaceMock */
61-
$methodInterfaceMock = $this->getMockBuilder(MethodInterface::class)
62-
->getMockForAbstractClass();
60+
$methodInterfaceMock = $this->createMock(MethodInterface::class);
6361
$this->assertSame($this->config, $this->config->setMethodInstance($methodInterfaceMock));
6462
}
6563

66-
protected function getMockForMethodInterface() {
67-
$methodInterfaceMock = $this->getMockBuilder(MethodInterface::class)
68-
->getMockForAbstractClass();
64+
protected function getMockForMethodInterface()
65+
{
66+
$methodInterfaceMock = $this->createMock(MethodInterface::class);
6967
$methodInterfaceMock->expects($this->once())
7068
->method('getCode')
7169
->willReturn('payment_code');
@@ -106,9 +104,8 @@ public function testSetStoreId()
106104
* @param string $method
107105
* @param array $returnMap
108106
* @param string $expectedValue
109-
*
110-
* @dataProvider getValueDataProvider
111107
*/
108+
#[DataProvider('getValueDataProvider')]
112109
public function testGetValue($key, $method, $returnMap, $expectedValue)
113110
{
114111
$this->config->setMethod($method);
@@ -198,9 +195,8 @@ public static function getValueDataProvider()
198195
/**
199196
* @param array $returnMap
200197
* @param bool $expectedValue
201-
*
202-
* @dataProvider isWppApiAvailabeDataProvider
203198
*/
199+
#[DataProvider('isWppApiAvailabeDataProvider')]
204200
public function testIsWppApiAvailable($returnMap, $expectedValue)
205201
{
206202
$this->config->setMethod('paypal_express');
@@ -272,9 +268,8 @@ public static function isWppApiAvailabeDataProvider()
272268
/**
273269
* @param string|null $methodCode
274270
* @param bool $expectedFlag
275-
*
276-
* @dataProvider isMethodAvailableDataProvider
277271
*/
272+
#[DataProvider('isMethodAvailableDataProvider')]
278273
public function testIsMethodAvailable($methodCode, $expectedFlag)
279274
{
280275
$this->config->setMethod('settedMethod');
@@ -311,9 +306,8 @@ public function testIsMethodActive()
311306
* @param string|null $disableFundingOptions
312307
* @param int $expressBml
313308
* @param bool $expectedValue
314-
*
315-
* @dataProvider isMethodActiveBmlDataProvider
316309
*/
310+
#[DataProvider('isMethodActiveBmlDataProvider')]
317311
public function testIsMethodActiveBml(
318312
$disableFundingOptions,
319313
$expressBml,
@@ -366,9 +360,7 @@ public static function isMethodActiveBmlDataProvider()
366360
*/
367361
public function testGetBuildNotationCode()
368362
{
369-
$productMetadata = $this->getMockBuilder(ProductMetadataInterface::class)
370-
->disableOriginalConstructor()
371-
->getMockForAbstractClass();
363+
$productMetadata = $this->createMock(ProductMetadataInterface::class);
372364
$productMetadata->method('getEdition')
373365
->willReturn('SomeEdition');
374366

app/code/Magento/Paypal/Test/Unit/Model/Adminhtml/ExpressTest.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
namespace Magento\Paypal\Test\Unit\Model\Adminhtml;
99

10+
use Magento\Directory\Helper\Data as DirectoryHelper;
1011
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\Json\Helper\Data as JsonHelper;
13+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1114
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1215
use Magento\Payment\Model\MethodInterface;
1316
use Magento\Paypal\Model\Adminhtml\Express;
@@ -18,6 +21,7 @@
1821
use Magento\Sales\Model\Order\Payment;
1922
use Magento\Sales\Model\Order\Payment\Transaction;
2023
use Magento\Sales\Model\Order\Payment\Transaction\Repository as TransactionRepository;
24+
use PHPUnit\Framework\Attributes\DataProvider;
2125
use PHPUnit\Framework\MockObject\MockObject;
2226
use PHPUnit\Framework\TestCase;
2327

@@ -26,6 +30,8 @@
2630
*/
2731
class ExpressTest extends TestCase
2832
{
33+
use MockCreationTrait;
34+
2935
/**
3036
* @var Express
3137
*/
@@ -69,11 +75,19 @@ class ExpressTest extends TestCase
6975
protected function setUp(): void
7076
{
7177
$objectManager = new ObjectManager($this);
72-
$this->nvp = $this->getMockBuilder(Nvp::class)
73-
->addMethods(['setProcessableErrors'])
74-
->onlyMethods(['getData', 'callDoAuthorization'])
75-
->disableOriginalConstructor()
76-
->getMock();
78+
79+
$jsonHelper = $this->createMock(JsonHelper::class);
80+
$directoryHelper = $this->createMock(DirectoryHelper::class);
81+
82+
$objectManager->prepareObjectManager([
83+
[JsonHelper::class, $jsonHelper],
84+
[DirectoryHelper::class, $directoryHelper]
85+
]);
86+
87+
$this->nvp = $this->createPartialMockWithReflection(
88+
Nvp::class,
89+
['setProcessableErrors', 'getData', 'callDoAuthorization']
90+
);
7791
$this->nvp->method('getData')->willReturn([]);
7892
$this->nvp->method('setProcessableErrors')->willReturnSelf();
7993

@@ -83,7 +97,7 @@ protected function setUp(): void
8397
);
8498
$this->pro->method('getApi')->willReturn($this->nvp);
8599

86-
$this->transaction = $this->getMockForAbstractClass(TransactionInterface::class);
100+
$this->transaction = $this->createMock(TransactionInterface::class);
87101
$this->transactionRepository = $this->createPartialMock(
88102
TransactionRepository::class,
89103
['getByTransactionType']
@@ -98,7 +112,7 @@ protected function setUp(): void
98112
]
99113
);
100114

101-
$this->paymentInstance = $this->getMockForAbstractClass(MethodInterface::class);
115+
$this->paymentInstance = $this->createMock(MethodInterface::class);
102116
$this->payment = $this->createPartialMock(
103117
Payment::class,
104118
[
@@ -181,8 +195,8 @@ public function testAuthorizeOrder()
181195
* @param float $authorizedAmount
182196
* @param bool $isAuthAllowed
183197
* @throws LocalizedException
184-
* @dataProvider paymentDataProvider
185198
*/
199+
#[DataProvider('paymentDataProvider')]
186200
public function testIsOrderAuthorizationAllowed(
187201
string $method,
188202
string $action,

app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Paypal\Model\Api\ProcessableExceptionFactory;
2323
use Magento\Paypal\Model\Config;
2424
use Magento\Paypal\Model\Info;
25+
use PHPUnit\Framework\Attributes\DataProvider;
2526
use PHPUnit\Framework\MockObject\MockObject;
2627
use PHPUnit\Framework\TestCase;
2728
use Psr\Log\LoggerInterface;
@@ -70,12 +71,9 @@ class NvpTest extends TestCase
7071
protected function setUp(): void
7172
{
7273
$this->customerAddressHelper = $this->createMock(Address::class);
73-
$this->logger = $this->getMockForAbstractClass(LoggerInterface::class);
74-
$this->customLoggerMock = $this->getMockBuilder(Logger::class)
75-
->setConstructorArgs([$this->getMockForAbstractClass(LoggerInterface::class)])
76-
->onlyMethods(['debug'])
77-
->getMock();
78-
$this->resolver = $this->getMockForAbstractClass(ResolverInterface::class);
74+
$this->logger = $this->createMock(LoggerInterface::class);
75+
$this->customLoggerMock = $this->createMock(Logger::class);
76+
$this->resolver = $this->createMock(ResolverInterface::class);
7977
$this->regionFactory = $this->createMock(RegionFactory::class);
8078
$this->countryFactory = $this->createMock(CountryFactory::class);
8179
$processableExceptionFactory = $this->createPartialMock(
@@ -86,9 +84,9 @@ protected function setUp(): void
8684
->method('create')
8785
->willReturnCallback(
8886
function ($arguments) {
89-
$this->processableException = $this->getMockBuilder(
90-
ProcessableException::class
91-
)->setConstructorArgs([$arguments['phrase'], null, $arguments['code']])->getMock();
87+
$this->processableException = $this->getMockBuilder(ProcessableException::class)
88+
->setConstructorArgs([$arguments['phrase'], null, $arguments['code']])
89+
->getMock();
9290
return $this->processableException;
9391
}
9492
);
@@ -149,8 +147,8 @@ protected function _invokeNvpProperty(Nvp $nvpObject, $property)
149147
* @param null|string $exception
150148
* @param string $exceptionMessage
151149
* @param null|int $exceptionCode
152-
* @dataProvider callDataProvider
153150
*/
151+
#[DataProvider('callDataProvider')]
154152
public function testCall($response, $processableErrors, $exception, $exceptionMessage = '', $exceptionCode = null)
155153
{
156154
if (isset($exception)) {
@@ -212,8 +210,8 @@ public static function callDataProvider()
212210
*
213211
* @param $input
214212
* @param $expected
215-
* @dataProvider callGetExpressCheckoutDetailsDataProvider
216213
*/
214+
#[DataProvider('callGetExpressCheckoutDetailsDataProvider')]
217215
public function testCallGetExpressCheckoutDetails($input, $expected)
218216
{
219217
$this->curl->expects($this->once())

app/code/Magento/Paypal/Test/Unit/Model/Api/ProcessableExceptionTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
namespace Magento\Paypal\Test\Unit\Model\Api;
99

1010
use Magento\Paypal\Model\Api\ProcessableException;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112
use PHPUnit\Framework\TestCase;
1213

1314
class ProcessableExceptionTest extends TestCase
1415
{
15-
const UNKNOWN_CODE = 10411;
16+
private const UNKNOWN_CODE = 10411;
1617

1718
/**
1819
* @var ProcessableException
@@ -23,8 +24,8 @@ class ProcessableExceptionTest extends TestCase
2324
* @param int $code
2425
* @param string $msg
2526
* @return void
26-
* @dataProvider getUserMessageDataProvider
2727
*/
28+
#[DataProvider('getUserMessageDataProvider')]
2829
public function testGetUserMessage($code, $msg)
2930
{
3031
$this->model = new ProcessableException(__($msg), null, $code);

app/code/Magento/Paypal/Test/Unit/Model/Billing/AbstractAgreementTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ protected function setUp(): void
3030
{
3131
$objectManager = new ObjectManager($this);
3232

33-
$this->paymentDataMock = $this->getMockBuilder(Data::class)
34-
->disableOriginalConstructor()
35-
->getMock();
33+
$this->paymentDataMock = $this->createMock(Data::class);
3634

3735
$this->model = $objectManager->getObject(
3836
Agreement::class,
@@ -44,8 +42,7 @@ public function testGetPaymentMethodInstance()
4442
{
4543
$paymentMethodInstance = $this->getMockBuilder(AbstractMethod::class)
4644
->disableOriginalConstructor()
47-
->onlyMethods(['setStore'])
48-
->getMockForAbstractClass();
45+
->getMock();
4946

5047
$paymentMethodInstance->expects($this->once())
5148
->method('setStore');

app/code/Magento/Paypal/Test/Unit/Model/Billing/AgreementTest.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Paypal\Test\Unit\Model\Billing;
99

10+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1011
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1112
use Magento\Payment\Helper\Data;
1213
use Magento\Payment\Model\Method\AbstractMethod;
@@ -18,6 +19,8 @@
1819

1920
class AgreementTest extends TestCase
2021
{
22+
use MockCreationTrait;
23+
2124
/**
2225
* @var Agreement
2326
*/
@@ -37,26 +40,21 @@ protected function setUp(): void
3740
{
3841
$objectManager = new ObjectManager($this);
3942

40-
$this->paymentDataMock = $this->getMockBuilder(Data::class)
41-
->disableOriginalConstructor()
42-
->onlyMethods(['getMethodInstance'])
43-
->getMock();
43+
$this->paymentDataMock = $this->createMock(Data::class);
4444

45-
$this->paymentMethodInstanceMock = $this->getMockBuilder(AbstractMethod::class)
46-
->disableOriginalConstructor()
47-
->addMethods([
45+
$this->paymentMethodInstanceMock = $this->createPartialMockWithReflection(
46+
AbstractMethod::class,
47+
[
4848
'initBillingAgreementToken',
4949
'getBillingAgreementTokenInfo',
50-
'placeBillingAgreement'
51-
])
52-
->onlyMethods([
50+
'placeBillingAgreement',
5351
'setStore',
5452
'getCode',
5553
'getFormBlockType',
5654
'getTitle',
5755
'getStore'
58-
])
59-
->getMock();
56+
]
57+
);
6058

6159
$this->model = $objectManager->getObject(
6260
Agreement::class,
@@ -114,19 +112,15 @@ public function testImportOrderPaymentWithoutMethodCode()
114112
*/
115113
private function importOrderPaymentCommonPart($baData)
116114
{
117-
$paymentMock = $this->getMockBuilder(Payment::class)
118-
->disableOriginalConstructor()
119-
->addMethods(['getBillingAgreementData'])
120-
->onlyMethods(['getMethodInstance', 'getOrder'])
121-
->getMock();
115+
$paymentMock = $this->createPartialMockWithReflection(
116+
Payment::class,
117+
['getBillingAgreementData', 'getMethodInstance', 'getOrder']
118+
);
122119

123120
$storeId = null;
124121
$customerId = 2;
125122

126-
$order = $this->getMockBuilder(Order::class)
127-
->disableOriginalConstructor()
128-
->onlyMethods(['getCustomerId'])
129-
->getMock();
123+
$order = $this->createMock(Order::class);
130124

131125
$order->expects($this->once())
132126
->method('getCustomerId')

app/code/Magento/Paypal/Test/Unit/Model/BillingAgreementConfigProviderTest.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class BillingAgreementConfigProviderTest extends TestCase
3434

3535
protected function setUp(): void
3636
{
37-
$this->currentCustomerMock = $this->getMockBuilder(CurrentCustomer::class)
38-
->onlyMethods(['getCustomerId'])
39-
->disableOriginalConstructor()
40-
->getMock();
37+
$this->currentCustomerMock = $this->createPartialMock(
38+
CurrentCustomer::class,
39+
['getCustomerId']
40+
);
4141

42-
$this->agreementFactoryMock = $this->getMockBuilder(AgreementFactory::class)
43-
->onlyMethods(['create'])
44-
->disableOriginalConstructor()
45-
->getMock();
42+
$this->agreementFactoryMock = $this->createPartialMock(
43+
AgreementFactory::class,
44+
['create']
45+
);
4646

4747
$this->configProvider = new BillingAgreementConfigProvider(
4848
$this->currentCustomerMock,
@@ -72,9 +72,7 @@ public function testGetConfig()
7272

7373
$this->currentCustomerMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
7474

75-
$agreementMock = $this->getMockBuilder(Agreement::class)
76-
->disableOriginalConstructor()
77-
->getMock();
75+
$agreementMock = $this->createMock(Agreement::class);
7876

7977
$agreementMock->expects($this->once())
8078
->method('getAvailableCustomerBillingAgreements')

0 commit comments

Comments
 (0)