Skip to content

Commit c9f1ccc

Browse files
committed
AC-15105: [CE] PHPUnit 12: Upgrade Payment & Shipping related test cases
1 parent 9a62604 commit c9f1ccc

File tree

58 files changed

+414
-559
lines changed

Some content is hidden

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

58 files changed

+414
-559
lines changed

app/code/Magento/CardinalCommerce/Test/Unit/Model/JwtManagementTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\CardinalCommerce\Model\JwtManagement;
1111
use Magento\Framework\Serialize\Serializer\Json;
1212
use PHPUnit\Framework\TestCase;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314

1415
/**
1516
* Tests JWT encode and decode.
@@ -64,11 +65,11 @@ public function testDecode()
6465

6566
/**
6667
* Tests JWT decode.
67-
*
68+
*
6869
* @param string $jwt
6970
* @param string $errorMessage
70-
* @dataProvider decodeWithExceptionDataProvider
7171
*/
72+
#[DataProvider('decodeWithExceptionDataProvider')]
7273
public function testDecodeWithException(string $jwt, string $errorMessage)
7374
{
7475
$this->expectException(\InvalidArgumentException::class);

app/code/Magento/CardinalCommerce/Test/Unit/Model/Response/JwtParserTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1616
use PHPUnit\Framework\MockObject\MockObject;
1717
use PHPUnit\Framework\TestCase;
18+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1819

1920
class JwtParserTest extends TestCase
2021
{
22+
use MockCreationTrait;
23+
2124
/**
2225
* @var ObjectManager
2326
*/
@@ -50,20 +53,17 @@ protected function setUp(): void
5053
{
5154
$this->objectManager = new ObjectManager($this);
5255

53-
$this->configMock = $this->getMockBuilder(Config::class)
54-
->onlyMethods(['getApiKey', 'isDebugModeEnabled'])
55-
->disableOriginalConstructor()
56-
->getMock();
56+
$this->configMock = $this->createPartialMock(
57+
Config::class,
58+
['getApiKey', 'isDebugModeEnabled']
59+
);
5760

58-
$this->jwtManagementMock = $this->getMockBuilder(JwtManagement::class)
59-
->onlyMethods(['decode'])
60-
->disableOriginalConstructor()
61-
->getMock();
61+
$this->jwtManagementMock = $this->createPartialMock(
62+
JwtManagement::class,
63+
['decode']
64+
);
6265

63-
$this->jwtPayloadValidatorMock = $this->getMockBuilder(JwtPayloadValidatorInterface::class)
64-
->onlyMethods(['validate'])
65-
->disableOriginalConstructor()
66-
->getMockForAbstractClass();
66+
$this->jwtPayloadValidatorMock = $this->createMock(JwtPayloadValidatorInterface::class);
6767

6868
$this->model = $this->objectManager->getObject(
6969
JwtParser::class,

app/code/Magento/CardinalCommerce/Test/Unit/Model/Response/JwtPayloadValidatorTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\CardinalCommerce\Model\Response\JwtPayloadValidator;
1111
use Magento\Framework\Intl\DateTimeFactory;
1212
use PHPUnit\Framework\TestCase;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314

1415
class JwtPayloadValidatorTest extends TestCase
1516
{
@@ -28,10 +29,10 @@ protected function setUp(): void
2829

2930
/**
3031
* Tests successful cases.
31-
*
32+
*
3233
* @param array $token
33-
* @dataProvider validateSuccessDataProvider
3434
*/
35+
#[DataProvider('validateSuccessDataProvider')]
3536
public function testValidateSuccess(array $token)
3637
{
3738
$this->assertTrue(
@@ -61,10 +62,8 @@ public static function validateSuccessDataProvider()
6162

6263
/**
6364
* Case when 3DS authentication is either failed or could not be attempted.
64-
*
65-
* @param array $token
66-
* @dataProvider validationEciFailsDataProvider
6765
*/
66+
#[DataProvider('validationEciFailsDataProvider')]
6867
public function testValidationEciFails(array $token)
6968
{
7069
$this->assertFalse(
@@ -91,10 +90,10 @@ public static function validationEciFailsDataProvider(): array
9190

9291
/**
9392
* Case when resulting state of the transaction is negative.
94-
*
93+
*
9594
* @param array $token
96-
* @dataProvider validationActionCodeFailsDataProvider
9795
*/
96+
#[DataProvider('validationActionCodeFailsDataProvider')]
9897
public function testValidationActionCodeFails(array $token)
9998
{
10099
$this->assertFalse(

app/code/Magento/Payment/Test/Unit/Block/FormTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Payment\Model\Method\AbstractMethod;
1818
use Magento\Payment\Model\MethodInterface;
1919
use Magento\Store\Model\StoreManager;
20+
use PHPUnit\Framework\Attributes\DataProvider;
2021
use PHPUnit\Framework\MockObject\MockObject;
2122
use PHPUnit\Framework\TestCase;
2223

@@ -79,7 +80,7 @@ public function testGetMethodException()
7980

8081
public function testGetMethodCode()
8182
{
82-
$method = $this->getMockForAbstractClass(MethodInterface::class);
83+
$method = $this->createMock(MethodInterface::class);
8384
$method->expects($this->once())
8485
->method('getCode')
8586
->willReturn('method_code');
@@ -88,8 +89,8 @@ public function testGetMethodCode()
8889
}
8990

9091
/**
91-
* @dataProvider getInfoDataProvider
9292
*/
93+
#[DataProvider('getInfoDataProvider')]
9394
public function testGetInfoData($field, $value, $expected)
9495
{
9596
$methodInstance = $this->getMockBuilder(AbstractMethod::class)
@@ -102,7 +103,7 @@ public function testGetInfoData($field, $value, $expected)
102103
->willReturn($value);
103104
$method = $this->getMockBuilder(
104105
MethodInterface::class
105-
)->getMockForAbstractClass();
106+
)->getMock();
106107
$method->expects($this->any())
107108
->method('getInfoInstance')
108109
->willReturn($methodInstance);
@@ -129,7 +130,7 @@ public static function getInfoDataProvider()
129130
public function testSetMethod()
130131
{
131132
$methodInterfaceMock = $this->getMockBuilder(MethodInterface::class)
132-
->getMockForAbstractClass();
133+
->getMock();
133134

134135
$this->assertSame($this->_object, $this->_object->setMethod($methodInterfaceMock));
135136
}

app/code/Magento/Payment/Test/Unit/Block/Info/CcTest.php

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1212
use Magento\Framework\View\Element\Template\Context;
1313
use Magento\Payment\Block\Info\Cc;
14+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1415
use Magento\Payment\Model\Config;
1516
use Magento\Payment\Model\Info;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1618
use PHPUnit\Framework\MockObject\MockObject;
1719
use PHPUnit\Framework\TestCase;
1820

1921
class CcTest extends TestCase
2022
{
23+
use MockCreationTrait;
2124
/**
2225
* @var Cc
2326
*/
@@ -42,7 +45,7 @@ protected function setUp(): void
4245
{
4346
$this->objectManager = new ObjectManager($this);
4447
$this->paymentConfig = $this->createMock(Config::class);
45-
$this->localeDate = $this->getMockForAbstractClass(TimezoneInterface::class);
48+
$this->localeDate = $this->createMock(TimezoneInterface::class);
4649
$context = $this->createPartialMock(Context::class, ['getLocaleDate']);
4750
$context->expects($this->any())
4851
->method('getLocaleDate')
@@ -56,18 +59,16 @@ protected function setUp(): void
5659
);
5760
}
5861

59-
/**
60-
* @dataProvider getCcTypeNameDataProvider
61-
*/
62+
#[DataProvider('getCcTypeNameDataProvider')]
6263
public function testGetCcTypeName($configCcTypes, $ccType, $expected)
6364
{
6465
$this->paymentConfig->expects($this->any())
6566
->method('getCcTypes')
6667
->willReturn($configCcTypes);
67-
$paymentInfo = $this->getMockBuilder(Info::class)
68-
->addMethods(['getCcType'])
69-
->disableOriginalConstructor()
70-
->getMock();
68+
$paymentInfo = $this->createPartialMockWithReflection(
69+
Info::class,
70+
['getCcType']
71+
);
7172
$paymentInfo->expects($this->any())
7273
->method('getCcType')
7374
->willReturn($ccType);
@@ -87,15 +88,13 @@ public static function getCcTypeNameDataProvider()
8788
];
8889
}
8990

90-
/**
91-
* @dataProvider hasCcExpDateDataProvider
92-
*/
91+
#[DataProvider('hasCcExpDateDataProvider')]
9392
public function testHasCcExpDate($ccExpMonth, $ccExpYear, $expected)
9493
{
95-
$paymentInfo = $this->getMockBuilder(Info::class)
96-
->addMethods(['getCcExpMonth', 'getCcExpYear'])
97-
->disableOriginalConstructor()
98-
->getMock();
94+
$paymentInfo = $this->createPartialMockWithReflection(
95+
Info::class,
96+
['getCcExpMonth', 'getCcExpYear']
97+
);
9998
$paymentInfo->expects($this->any())
10099
->method('getCcExpMonth')
101100
->willReturn($ccExpMonth);
@@ -118,15 +117,13 @@ public static function hasCcExpDateDataProvider()
118117
];
119118
}
120119

121-
/**
122-
* @dataProvider ccExpMonthDataProvider
123-
*/
120+
#[DataProvider('ccExpMonthDataProvider')]
124121
public function testGetCcExpMonth($ccExpMonth, $expected)
125122
{
126-
$paymentInfo = $this->getMockBuilder(Info::class)
127-
->addMethods(['getCcExpMonth'])
128-
->disableOriginalConstructor()
129-
->getMock();
123+
$paymentInfo = $this->createPartialMockWithReflection(
124+
Info::class,
125+
['getCcExpMonth']
126+
);
130127
$paymentInfo->expects($this->any())
131128
->method('getCcExpMonth')
132129
->willReturn($ccExpMonth);
@@ -145,15 +142,13 @@ public static function ccExpMonthDataProvider()
145142
];
146143
}
147144

148-
/**
149-
* @dataProvider getCcExpDateDataProvider
150-
*/
145+
#[DataProvider('getCcExpDateDataProvider')]
151146
public function testGetCcExpDate($ccExpMonth, $ccExpYear)
152147
{
153-
$paymentInfo = $this->getMockBuilder(Info::class)
154-
->addMethods(['getCcExpMonth', 'getCcExpYear'])
155-
->disableOriginalConstructor()
156-
->getMock();
148+
$paymentInfo = $this->createPartialMockWithReflection(
149+
Info::class,
150+
['getCcExpMonth', 'getCcExpYear']
151+
);
157152
$paymentInfo
158153
->expects($this->any())
159154
->method('getCcExpMonth')

app/code/Magento/Payment/Test/Unit/Block/Info/InstructionsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testGetInstruction()
5353
{
5454
$methodInstance = $this->getMockBuilder(
5555
MethodInterface::class
56-
)->getMockForAbstractClass();
56+
)->getMock();
5757
$methodInstance->expects($this->once())
5858
->method('getConfigData')
5959
->with('instructions')

app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function testBeforeToHtml()
137137
)->disableOriginalConstructor()->getMock();
138138
$methodMock = $this->getMockBuilder(
139139
MethodInterface::class
140-
)->getMockForAbstractClass();
140+
)->getMock();
141141
$infoMock->expects($this->once())->method('getMethodInstance')->willReturn($methodMock);
142142
$this->block->setInfo($infoMock);
143143

app/code/Magento/Payment/Test/Unit/Block/InfoTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Payment\Model\Method\AbstractMethod;
1818
use Magento\Store\Model\Store;
1919
use Magento\Store\Model\StoreManager;
20+
use PHPUnit\Framework\Attributes\DataProvider;
2021
use PHPUnit\Framework\MockObject\MockObject;
2122
use PHPUnit\Framework\TestCase;
2223

@@ -73,13 +74,13 @@ protected function setUp(): void
7374
}
7475

7576
/**
76-
* @dataProvider getIsSecureModeDataProvider
7777
* @param bool $isSecureMode
7878
* @param bool $methodInstance
7979
* @param bool $store
8080
* @param string $storeCode
8181
* @param bool $expectedResult
8282
*/
83+
#[DataProvider('getIsSecureModeDataProvider')]
8384
public function testGetIsSecureMode($isSecureMode, $methodInstance, $store, $storeCode, $expectedResult)
8485
{
8586
if (isset($store)) {
@@ -164,9 +165,7 @@ public function testGetSpecificInformation()
164165
$this->assertNotNull($result);
165166
}
166167

167-
/**
168-
* @dataProvider getValueAsArrayDataProvider
169-
*/
168+
#[DataProvider('getValueAsArrayDataProvider')]
170169
public function testGetValueAsArray($value, $escapeHtml, $expected)
171170
{
172171
$result = $this->_object->getValueAsArray($value, $escapeHtml);

app/code/Magento/Payment/Test/Unit/Block/Transparent/FormTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Payment\Model\MethodInterface;
2020
use Magento\Quote\Model\Quote;
2121
use Magento\Quote\Model\Quote\Payment;
22+
use PHPUnit\Framework\Attributes\DataProvider;
2223
use PHPUnit\Framework\MockObject\MockObject;
2324
use PHPUnit\Framework\TestCase;
2425

@@ -56,13 +57,9 @@ protected function setUp(): void
5657
{
5758
$objectManagerHelper = new ObjectManager($this);
5859

59-
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
60-
->onlyMethods(['getParam'])
61-
->getMockForAbstractClass();
60+
$this->requestMock = $this->createMock(RequestInterface::class);
6261

63-
$this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)
64-
->onlyMethods(['getUrl'])
65-
->getMockForAbstractClass();
62+
$this->urlBuilderMock = $this->createMock(UrlInterface::class);
6663

6764
$context = $objectManagerHelper->getObject(
6865
Context::class,
@@ -106,8 +103,8 @@ public function testIsAjaxRequest()
106103
* @param mixed $fieldValue
107104
* @param mixed $expected
108105
*
109-
* @dataProvider getMethodConfigDataDataProvider
110106
*/
107+
#[DataProvider('getMethodConfigDataDataProvider')]
111108
public function testGetMethodConfigData($fieldName, $fieldValue, $expected)
112109
{
113110
$this->initializeMethodWithConfigMock([[$fieldName, null, $fieldValue]]);
@@ -155,13 +152,13 @@ public static function getMethodConfigDataDataProvider()
155152
}
156153

157154
/**
158-
* @dataProvider getCgiUrlDataProvider
159155
*
160156
* @param $sandboxFlag
161157
* @param $cgiUrlTestMode
162158
* @param $cgiUrl
163159
* @param $expectedUrl
164160
*/
161+
#[DataProvider('getCgiUrlDataProvider')]
165162
public function testGetCgiUrl($sandboxFlag, $cgiUrlTestMode, $cgiUrl, $expectedUrl)
166163
{
167164
$this->initializeMethodWithConfigMock(
@@ -302,7 +299,7 @@ public function testGetMethodNotTransparentInterface()
302299
$this->expectExceptionMessage((string)__('We cannot retrieve the transparent payment method model object.'));
303300

304301
$methodMock = $this->getMockBuilder(MethodInterface::class)
305-
->getMockForAbstractClass();
302+
->getMock();
306303

307304
$this->form->setMethod($methodMock);
308305
$this->form->getMethod();

app/code/Magento/Payment/Test/Unit/Block/Transparent/RedirectTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Payment\Test\Unit\Block\Transparent;
99

1010
use Magento\Payment\Block\Transparent\Redirect;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112
use PHPUnit\Framework\TestCase;
1213
use PHPUnit\Framework\MockObject\MockObject;
1314

@@ -50,8 +51,8 @@ protected function setUp(): void
5051
/**
5152
* @param array $postData
5253
* @param array $expected
53-
* @dataProvider getPostParamsDataProvider
5454
*/
55+
#[DataProvider('getPostParamsDataProvider')]
5556
public function testGetPostParams(array $postData, array $expected): void
5657
{
5758
$this->request->method('getPostValue')

0 commit comments

Comments
 (0)