Skip to content

Commit 96d28b3

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

19 files changed

+240
-412
lines changed

app/code/Magento/Vault/Test/Unit/Block/Customer/AccountTokensTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ protected function setUp(): void
3838
{
3939
$this->objectManager = new ObjectManager($this);
4040

41-
$this->tokenManagement = $this->getMockBuilder(CustomerTokenManagement::class)
42-
->disableOriginalConstructor()
43-
->onlyMethods(['getCustomerSessionTokens'])
44-
->getMock();
41+
$this->tokenManagement = $this->createMock(CustomerTokenManagement::class);
4542

4643
$this->block = $this->objectManager->getObject(AccountTokens::class, [
4744
'customerTokenManagement' => $this->tokenManagement

app/code/Magento/Vault/Test/Unit/Model/AccountPaymentTokenFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function setUp(): void
4949
];
5050

5151
$this->paymentToken = $objectManager->getObject(PaymentToken::class);
52-
$this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class);
52+
$this->objectManager = $this->createMock(ObjectManagerInterface::class);
5353

5454
$this->paymentTokenFactory = new PaymentTokenFactory($this->objectManager, $tokenTypes);
5555
$this->factory = new AccountPaymentTokenFactory($this->objectManager, $this->paymentTokenFactory);

app/code/Magento/Vault/Test/Unit/Model/CreditCardTokenFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function setUp(): void
4444
];
4545

4646
$this->paymentToken = $objectManager->getObject(PaymentToken::class);
47-
$this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class);
47+
$this->objectManager = $this->createMock(ObjectManagerInterface::class);
4848

4949
$paymentTokenFactory = new PaymentTokenFactory($this->objectManager, $tokenTypes);
5050
$this->factory = new CreditCardTokenFactory($this->objectManager, $paymentTokenFactory);

app/code/Magento/Vault/Test/Unit/Model/CustomerTokenManagementTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Vault\Api\Data\PaymentTokenInterface;
1212
use Magento\Vault\Model\CustomerTokenManagement;
1313
use Magento\Vault\Model\PaymentTokenManagement;
14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\MockObject\MockObject;
1516
use PHPUnit\Framework\TestCase;
1617

@@ -33,12 +34,8 @@ class CustomerTokenManagementTest extends TestCase
3334

3435
protected function setUp(): void
3536
{
36-
$this->paymentTokenManagement = $this->getMockBuilder(PaymentTokenManagement::class)
37-
->disableOriginalConstructor()
38-
->getMock();
39-
$this->customerSession = $this->getMockBuilder(Session::class)
40-
->disableOriginalConstructor()
41-
->getMock();
37+
$this->paymentTokenManagement = $this->createMock(PaymentTokenManagement::class);
38+
$this->customerSession = $this->createMock(Session::class);
4239

4340
$this->tokenManagement = new CustomerTokenManagement(
4441
$this->paymentTokenManagement,
@@ -50,8 +47,8 @@ protected function setUp(): void
5047
* @param int|null $customerId
5148
* @param bool $isLoggedCustomer
5249
* @return void
53-
* @dataProvider getCustomerSessionTokensNegativeDataProvider
5450
*/
51+
#[DataProvider('getCustomerSessionTokensNegativeDataProvider')]
5552
public function testGetCustomerSessionTokensNegative($customerId, bool $isLoggedCustomer)
5653
{
5754
$this->customerSession->method('getCustomerId')->willReturn($customerId);
@@ -75,7 +72,7 @@ public static function getCustomerSessionTokensNegativeDataProvider()
7572
public function testGetCustomerSessionTokens()
7673
{
7774
$customerId = 1;
78-
$token = $this->getMockForAbstractClass(PaymentTokenInterface::class);
75+
$token = $this->createMock(PaymentTokenInterface::class);
7976
$expectation = [$token];
8077

8178
$this->customerSession->expects(static::once())

app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
use Magento\Sales\Api\Data\OrderPaymentExtensionInterface;
2121
use Magento\Sales\Api\Data\TransactionInterface;
2222
use Magento\Sales\Model\Order\Payment;
23+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
2324
use Magento\Vault\Api\Data\PaymentTokenInterface;
2425
use Magento\Vault\Api\PaymentTokenManagementInterface;
2526
use Magento\Vault\Model\Method\Vault;
2627
use Magento\Vault\Model\VaultPaymentInterface;
28+
use PHPUnit\Framework\Attributes\DataProvider;
2729
use PHPUnit\Framework\MockObject\MockObject;
2830
use PHPUnit\Framework\TestCase;
2931

@@ -32,6 +34,8 @@
3234
*/
3335
class VaultTest extends TestCase
3436
{
37+
use MockCreationTrait;
38+
3539
/**
3640
* @var ObjectManager
3741
*/
@@ -53,15 +57,15 @@ class VaultTest extends TestCase
5357
protected function setUp(): void
5458
{
5559
$this->objectManager = new ObjectManager($this);
56-
$this->vaultProvider = $this->getMockForAbstractClass(MethodInterface::class);
60+
$this->vaultProvider = $this->createMock(MethodInterface::class);
5761
$this->jsonSerializer = $this->createMock(Json::class);
5862
}
5963

6064
public function testAuthorizeNotOrderPayment()
6165
{
6266
$this->expectException('DomainException');
6367
$this->expectExceptionMessage('Not implemented');
64-
$paymentModel = $this->getMockForAbstractClass(InfoInterface::class);
68+
$paymentModel = $this->createMock(InfoInterface::class);
6569

6670
/** @var Vault $model */
6771
$model = $this->objectManager->getObject(Vault::class);
@@ -70,15 +74,13 @@ public function testAuthorizeNotOrderPayment()
7074

7175
/**
7276
* @param array $additionalInfo
73-
* @dataProvider additionalInfoDataProvider
7477
*/
78+
#[DataProvider('additionalInfoDataProvider')]
7579
public function testAuthorizeNoTokenMetadata(array $additionalInfo)
7680
{
7781
$this->expectException('LogicException');
7882
$this->expectExceptionMessage('Public hash should be defined');
79-
$paymentModel = $this->getMockBuilder(Payment::class)
80-
->disableOriginalConstructor()
81-
->getMock();
83+
$paymentModel = $this->createMock(Payment::class);
8284

8385
$paymentModel->expects(static::once())
8486
->method('getAdditionalInformation')
@@ -109,10 +111,8 @@ public function testAuthorizeNoToken()
109111
$customerId = 1;
110112
$publicHash = 'token_public_hash';
111113

112-
$paymentModel = $this->getMockBuilder(Payment::class)
113-
->disableOriginalConstructor()
114-
->getMock();
115-
$tokenManagement = $this->getMockForAbstractClass(PaymentTokenManagementInterface::class);
114+
$paymentModel = $this->createMock(Payment::class);
115+
$tokenManagement = $this->createMock(PaymentTokenManagementInterface::class);
116116

117117
$paymentModel->expects(static::once())
118118
->method('getAdditionalInformation')
@@ -144,18 +144,17 @@ public function testAuthorize()
144144
$vaultProviderCode = 'vault_provider_code';
145145
$amount = 10.01;
146146

147-
$paymentModel = $this->getMockBuilder(Payment::class)
148-
->disableOriginalConstructor()
149-
->getMock();
150-
$extensionAttributes = $this->getMockBuilder(OrderPaymentExtensionInterface::class)
151-
->addMethods(['setVaultPaymentToken', 'getVaultPaymentToken'])
152-
->getMockForAbstractClass();
147+
$paymentModel = $this->createMock(Payment::class);
148+
$extensionAttributes = $this->createPartialMockWithReflection(
149+
OrderPaymentExtensionInterface::class,
150+
['setVaultPaymentToken', 'getVaultPaymentToken']
151+
);
153152

154-
$commandManagerPool = $this->getMockForAbstractClass(CommandManagerPoolInterface::class);
155-
$commandManager = $this->getMockForAbstractClass(CommandManagerInterface::class);
153+
$commandManagerPool = $this->createMock(CommandManagerPoolInterface::class);
154+
$commandManager = $this->createMock(CommandManagerInterface::class);
156155

157-
$tokenManagement = $this->getMockForAbstractClass(PaymentTokenManagementInterface::class);
158-
$token = $this->getMockForAbstractClass(PaymentTokenInterface::class);
156+
$tokenManagement = $this->createMock(PaymentTokenManagementInterface::class);
157+
$token = $this->createMock(PaymentTokenInterface::class);
159158

160159
$tokenDetails = [
161160
'cc_last4' => '1111',
@@ -226,7 +225,7 @@ public function testCaptureNotOrderPayment()
226225
{
227226
$this->expectException('DomainException');
228227
$this->expectExceptionMessage('Not implemented');
229-
$paymentModel = $this->getMockForAbstractClass(InfoInterface::class);
228+
$paymentModel = $this->createMock(InfoInterface::class);
230229

231230
/** @var Vault $model */
232231
$model = $this->objectManager->getObject(Vault::class);
@@ -237,11 +236,9 @@ public function testCapture()
237236
{
238237
$this->expectException('DomainException');
239238
$this->expectExceptionMessage('Capture can not be performed through vault');
240-
$paymentModel = $this->getMockBuilder(Payment::class)
241-
->disableOriginalConstructor()
242-
->getMock();
239+
$paymentModel = $this->createMock(Payment::class);
243240

244-
$authorizationTransaction = $this->getMockForAbstractClass(TransactionInterface::class);
241+
$authorizationTransaction = $this->createMock(TransactionInterface::class);
245242
$paymentModel->expects(static::once())
246243
->method('getAuthorizationTransaction')
247244
->willReturn($authorizationTransaction);
@@ -253,13 +250,13 @@ public function testCapture()
253250

254251
/**
255252
* @covers \Magento\Vault\Model\Method\Vault::isAvailable
256-
* @dataProvider isAvailableDataProvider
257253
*/
254+
#[DataProvider('isAvailableDataProvider')]
258255
public function testIsAvailable($isAvailableProvider, $isActive, $expected)
259256
{
260257
$storeId = 1;
261-
$quote = $this->getMockForAbstractClass(CartInterface::class);
262-
$config = $this->getMockForAbstractClass(ConfigInterface::class);
258+
$quote = $this->createMock(CartInterface::class);
259+
$config = $this->createMock(ConfigInterface::class);
263260

264261
$this->vaultProvider->expects(static::once())
265262
->method('isAvailable')
@@ -310,7 +307,7 @@ public static function isAvailableDataProvider()
310307
public function testIsAvailableWithoutQuote()
311308
{
312309
$quote = null;
313-
$config = $this->getMockForAbstractClass(ConfigInterface::class);
310+
$config = $this->createMock(ConfigInterface::class);
314311

315312
$this->vaultProvider->expects(static::once())
316313
->method('isAvailable')
@@ -341,12 +338,12 @@ public function testIsAvailableWithoutQuote()
341338
* @param bool|null $configValue
342339
* @param bool|null $paymentValue
343340
* @param bool $expected
344-
* @dataProvider internalUsageDataProvider
345341
*/
342+
#[DataProvider('internalUsageDataProvider')]
346343
public function testCanUseInternal($configValue, $paymentValue, $expected)
347344
{
348-
$handlerPool = $this->getMockForAbstractClass(ValueHandlerPoolInterface::class);
349-
$handler = $this->getMockForAbstractClass(ValueHandlerInterface::class);
345+
$handlerPool = $this->createMock(ValueHandlerPoolInterface::class);
346+
$handler = $this->createMock(ValueHandlerInterface::class);
350347

351348
$handlerPool->expects(static::once())
352349
->method('get')

app/code/Magento/Vault/Test/Unit/Model/PaymentMethodListTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ class PaymentMethodListTest extends TestCase
3535

3636
protected function setUp(): void
3737
{
38-
$this->paymentMethodList = $this->getMockForAbstractClass(PaymentMethodListInterface::class);
39-
$this->instanceFactory = $this->getMockBuilder(InstanceFactory::class)
40-
->disableOriginalConstructor()
41-
->onlyMethods(['create'])
42-
->getMock();
38+
$this->paymentMethodList = $this->createMock(PaymentMethodListInterface::class);
39+
$this->instanceFactory = $this->createMock(InstanceFactory::class);
4340

4441
$this->vaultPaymentList = new PaymentMethodList($this->paymentMethodList, $this->instanceFactory);
4542
}
@@ -50,9 +47,9 @@ protected function setUp(): void
5047
public function testGetActivePaymentList()
5148
{
5249
$storeId = 1;
53-
$vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class);
54-
$paymentMethodInterface1 = $this->getMockForAbstractClass(PaymentMethodInterface::class);
55-
$paymentMethodInterface2 = $this->getMockForAbstractClass(PaymentMethodInterface::class);
50+
$vaultPayment = $this->createMock(VaultPaymentInterface::class);
51+
$paymentMethodInterface1 = $this->createMock(PaymentMethodInterface::class);
52+
$paymentMethodInterface2 = $this->createMock(PaymentMethodInterface::class);
5653
$activePayments = [
5754
$paymentMethodInterface1,
5855
$paymentMethodInterface2
@@ -66,7 +63,7 @@ public function testGetActivePaymentList()
6663
$this->instanceFactory->expects(static::exactly(2))
6764
->method('create')
6865
->willReturnMap([
69-
[$paymentMethodInterface1, $this->getMockForAbstractClass(MethodInterface::class)],
66+
[$paymentMethodInterface1, $this->createMock(MethodInterface::class)],
7067
[$paymentMethodInterface2, $vaultPayment]
7168
]);
7269

0 commit comments

Comments
 (0)