2020use Magento \Sales \Api \Data \OrderPaymentExtensionInterface ;
2121use Magento \Sales \Api \Data \TransactionInterface ;
2222use Magento \Sales \Model \Order \Payment ;
23+ use Magento \Framework \TestFramework \Unit \Helper \MockCreationTrait ;
2324use Magento \Vault \Api \Data \PaymentTokenInterface ;
2425use Magento \Vault \Api \PaymentTokenManagementInterface ;
2526use Magento \Vault \Model \Method \Vault ;
2627use Magento \Vault \Model \VaultPaymentInterface ;
28+ use PHPUnit \Framework \Attributes \DataProvider ;
2729use PHPUnit \Framework \MockObject \MockObject ;
2830use PHPUnit \Framework \TestCase ;
2931
3234 */
3335class 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 ' )
0 commit comments