Skip to content

Commit

Permalink
fix tests V
Browse files Browse the repository at this point in the history
  • Loading branch information
Timur Karimov committed Apr 29, 2024
1 parent bc17874 commit a9f9249
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
17 changes: 12 additions & 5 deletions tests/unit/payment-methods/test-class-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ class UPE_Payment_Gateway_Test extends WCPAY_UnitTestCase {
*/
private $mock_fraud_service;

/**
* Mock Duplicates Detection Service.
*
* @var Duplicates_Detection_Service
*/
private $mock_duplicates_detection_service;

/**
* Pre-test setup
*/
Expand Down Expand Up @@ -231,8 +238,9 @@ public function set_up() {

$this->mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class );

$this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
$this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
$this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
$this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
$this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class );

$this->mock_payment_methods = [];
$payment_method_classes = [
Expand Down Expand Up @@ -295,7 +303,7 @@ public function set_up() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$this->createMock( Duplicates_Detection_Service::class ),
$this->mock_duplicates_detection_service,
]
)
->setMethods(
Expand Down Expand Up @@ -950,7 +958,6 @@ public function test_get_upe_available_payment_methods( $payment_methods, $expec
->expects( $this->any() )
->method( 'get_fees' )
->willReturn( $payment_methods );
$mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class );

$gateway = new WC_Payment_Gateway_WCPay(
$this->mock_api_client,
Expand All @@ -965,7 +972,7 @@ public function test_get_upe_available_payment_methods( $payment_methods, $expec
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$mock_duplicates_detection_service
$this->mock_duplicates_detection_service
);

$this->assertEquals( $expected_result, $gateway->get_upe_available_payment_methods() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ class UPE_Split_Payment_Gateway_Test extends WCPAY_UnitTestCase {
*/
private $mock_fraud_service;

/**
* Mock Duplicates Detection Service.
*
* @var Duplicates_Detection_Service
*/
private $mock_duplicates_detection_service;

/**
* Mapping for payment ID to payment method.
*
Expand Down Expand Up @@ -248,8 +255,9 @@ public function set_up() {

$this->mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class );

$this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
$this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
$this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
$this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
$this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class );

// Arrange: Define a $_POST array which includes the payment method,
// so that get_payment_method_from_request() does not throw error.
Expand Down Expand Up @@ -282,7 +290,7 @@ public function set_up() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$this->createMock( Duplicates_Detection_Service::class ),
$this->mock_duplicates_detection_service,
]
)
->setMethods(
Expand Down Expand Up @@ -1062,7 +1070,7 @@ public function test_get_payment_methods_with_request_context() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$this->createMock( Duplicates_Detection_Service::class ),
$this->mock_duplicates_detection_service,
]
)
->setMethods( [ 'get_payment_methods_from_gateway_id' ] )
Expand Down Expand Up @@ -1108,7 +1116,7 @@ public function test_get_payment_methods_without_request_context() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$this->createMock( Duplicates_Detection_Service::class ),
$this->mock_duplicates_detection_service,
]
)
->setMethods( [ 'get_payment_methods_from_gateway_id' ] )
Expand Down Expand Up @@ -1153,7 +1161,7 @@ public function test_get_payment_methods_without_request_context_or_token() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$this->createMock( Duplicates_Detection_Service::class ),
$this->mock_duplicates_detection_service,
]
)
->setMethods(
Expand Down Expand Up @@ -1207,7 +1215,7 @@ public function test_get_payment_methods_from_gateway_id_upe() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$this->createMock( Duplicates_Detection_Service::class ),
$this->mock_duplicates_detection_service,
]
)
->onlyMethods(
Expand Down
20 changes: 15 additions & 5 deletions tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ class WC_Payment_Gateway_WCPay_Subscriptions_Test extends WCPAY_UnitTestCase {
*/
private $mock_fraud_service;

/**
* Mock Duplicates Detection Service.
*
* @var Duplicates_Detection_Service
*/
private $mock_duplicates_detection_service;

public function set_up() {
parent::set_up();

Expand Down Expand Up @@ -137,8 +144,9 @@ public function set_up() {

$this->mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class );

$this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
$this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
$this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
$this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
$this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class );

$mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class )
->setConstructorArgs( [ $this->mock_token_service ] )
Expand All @@ -158,7 +166,7 @@ public function set_up() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$this->createMock( Duplicates_Detection_Service::class ),
$this->mock_duplicates_detection_service,
);
$this->wcpay_gateway->init_hooks();
WC_Payments::set_gateway( $this->wcpay_gateway );
Expand Down Expand Up @@ -832,7 +840,8 @@ public function test_adds_custom_payment_meta_input_fallback_until_subs_3_0_7()
$this->order_service,
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service
$this->mock_fraud_service,
$this->mock_duplicates_detection_service,
);

// Ensure the has_attached_integration_hooks property is set to false so callbacks can be attached in maybe_init_subscriptions().
Expand Down Expand Up @@ -866,7 +875,8 @@ public function test_does_not_add_custom_payment_meta_input_fallback_for_subs_3_
$this->order_service,
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service
$this->mock_fraud_service,
$this->mock_duplicates_detection_service,
);

$this->assertFalse( has_action( 'woocommerce_admin_order_data_after_billing_address' ) );
Expand Down
18 changes: 13 additions & 5 deletions tests/unit/test-class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ class WC_Payment_Gateway_WCPay_Test extends WCPAY_UnitTestCase {
*/
private $mock_fraud_service;

/**
* Mock Duplicates Detection Service.
*
* @var Duplicates_Detection_Service
*/
private $mock_duplicates_detection_service;

/**
* Pre-test setup
*/
Expand Down Expand Up @@ -230,7 +237,8 @@ public function set_up() {
'currency_code' => 'usd',
]
);
$this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
$this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
$this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class );

$this->mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class )
->setConstructorArgs( [ $this->mock_token_service ] )
Expand Down Expand Up @@ -898,7 +906,7 @@ public function test_process_redirect_setup_intent_succeded() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$this->createMock( Duplicates_Detection_Service::class ),
$this->mock_duplicates_detection_service,
]
)
->onlyMethods(
Expand Down Expand Up @@ -1006,7 +1014,7 @@ public function test_process_redirect_payment_save_payment_token() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$this->createMock( Duplicates_Detection_Service::class ),
$this->mock_duplicates_detection_service,
]
)
->onlyMethods(
Expand Down Expand Up @@ -3206,7 +3214,7 @@ private function get_partial_mock_for_gateway( array $methods = [], array $const
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$this->createMock( Duplicates_Detection_Service::class ),
$this->mock_duplicates_detection_service,
];

foreach ( $constructor_replacement as $key => $value ) {
Expand Down Expand Up @@ -3693,7 +3701,7 @@ private function init_gateways() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
$this->createMock( Duplicates_Detection_Service::class )
$this->mock_duplicates_detection_service
);
}

Expand Down

0 comments on commit a9f9249

Please sign in to comment.