From d256f607a87aab251ae78aa6ee4d6c2308dce998 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Wed, 27 Dec 2023 13:26:48 +0100 Subject: [PATCH] further tests cleanup --- ...-class-wc-rest-payments-tos-controller.php | 5 +- .../test-class-upe-payment-gateway.php | 201 ++++-------------- .../test-class-upe-split-payment-gateway.php | 95 --------- ...wc-payment-gateway-wcpay-payment-types.php | 6 +- ...-payment-gateway-wcpay-process-payment.php | 9 +- ...c-payment-gateway-wcpay-process-refund.php | 5 +- ...ubscriptions-payment-method-order-note.php | 2 - ...ay-wcpay-subscriptions-process-payment.php | 10 +- ...wc-payment-gateway-wcpay-subscriptions.php | 11 - .../test-class-wc-payment-gateway-wcpay.php | 2 - ...xpress-checkout-button-display-handler.php | 5 +- ...ayments-payment-request-button-handler.php | 5 +- ...lass-wc-payments-woopay-button-handler.php | 7 +- 13 files changed, 48 insertions(+), 315 deletions(-) diff --git a/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php b/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php index 0e4e31790f6..9597390a9a0 100644 --- a/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php +++ b/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php @@ -64,10 +64,7 @@ public function set_up() { $order_service = new WC_Payments_Order_Service( $this->createMock( WC_Payments_API_Client::class ) ); $action_scheduler_service = new WC_Payments_Action_Scheduler_Service( $mock_api_client, $order_service ); $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - $mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class ) - ->setConstructorArgs( [ $token_service ] ) - ->onlyMethods( [ 'is_subscription_item_in_cart' ] ) - ->getMock(); + $mock_payment_method = $this->createMock( CC_Payment_Method::class ); $this->gateway = new WC_Payment_Gateway_WCPay( $mock_api_client, diff --git a/tests/unit/payment-methods/test-class-upe-payment-gateway.php b/tests/unit/payment-methods/test-class-upe-payment-gateway.php index 8ef3ea9a6c2..7c013e2b858 100644 --- a/tests/unit/payment-methods/test-class-upe-payment-gateway.php +++ b/tests/unit/payment-methods/test-class-upe-payment-gateway.php @@ -13,7 +13,6 @@ use WCPay\Constants\Intent_Status; use WCPay\Core\Server\Request\Get_Intention; use WCPay\Core\Server\Request\Get_Setup_Intention; -use WCPay\Core\Server\Request\Update_Intention; use WCPay\Exceptions\Process_Payment_Exception; use WCPay\WooPay\WooPay_Utilities; use WCPay\Session_Rate_Limiter; @@ -54,7 +53,7 @@ class UPE_Payment_Gateway_Test extends WCPAY_UnitTestCase { * * @var WC_Payment_Gateway_WCPay */ - private $mock_upe_gateway; + private $mock_gateway; /** * Mock WC_Payments_Customer_Service. @@ -182,7 +181,7 @@ public function set_up() { // Note that we cannot use createStub here since it's not defined in PHPUnit 6.5. $this->mock_api_client = $this->getMockBuilder( 'WC_Payments_API_Client' ) ->disableOriginalConstructor() - ->setMethods( + ->onlyMethods( [ 'get_payment_method', 'is_server_connected', @@ -221,7 +220,7 @@ public function set_up() { // Arrange: Mock WC_Payments_Customer_Service so its methods aren't called directly. $this->mock_token_service = $this->getMockBuilder( 'WC_Payments_Token_Service' ) ->disableOriginalConstructor() - ->setMethods( [ 'add_payment_method_to_user' ] ) + ->onlyMethods( [ 'add_payment_method_to_user' ] ) ->getMock(); // Arrange: Mock WC_Payments_Action_Scheduler_Service so its methods aren't called directly. @@ -254,7 +253,7 @@ public function set_up() { foreach ( $payment_method_classes as $payment_method_class ) { $mock_payment_method = $this->getMockBuilder( $payment_method_class ) ->setConstructorArgs( [ $this->mock_token_service ] ) - ->setMethods( [ 'is_subscription_item_in_cart', 'get_icon' ] ) + ->onlyMethods( [ 'is_subscription_item_in_cart', 'get_icon' ] ) ->getMock(); $this->mock_payment_methods[ $mock_payment_method->get_id() ] = $mock_payment_method; } @@ -265,7 +264,7 @@ public function set_up() { $this->mock_api_client, ] ) - ->setMethods( + ->onlyMethods( [ 'get_payment_method_id_for_order', ] @@ -280,7 +279,7 @@ public function set_up() { // Arrange: Mock WC_Payment_Gateway_WCPay so that some of its methods can be // mocked, and their return values can be used for testing. - $this->mock_upe_gateway = $this->getMockBuilder( WC_Payment_Gateway_WCPay::class ) + $this->mock_gateway = $this->getMockBuilder( WC_Payment_Gateway_WCPay::class ) ->setConstructorArgs( [ $this->mock_api_client, @@ -309,13 +308,13 @@ public function set_up() { ->getMock(); // Arrange: Set the return value of get_return_url() so it can be used in a test later. - $this->mock_upe_gateway + $this->mock_gateway ->expects( $this->any() ) ->method( 'get_return_url' ) ->will( $this->returnValue( $this->return_url ) ); - $this->mock_upe_gateway + $this->mock_gateway ->expects( $this->any() ) ->method( 'parent_process_payment' ) ->will( @@ -355,11 +354,12 @@ public function tear_down() { wcpay_get_test_container()->reset_all_replacements(); } - public function test_process_payment_returns_correct_redirect_when_using_payment_request() { - $order = WC_Helper_Order::create_order(); - $intent = WC_Helper_Intention::create_intention(); - $_POST['payment_request_type'] = 'google_pay'; - $this->mock_upe_gateway->expects( $this->once() ) + public function test_process_payment_returns_correct_redirect_when_using_saved_payment() { + $order = WC_Helper_Order::create_order(); + $_POST = $this->setup_saved_payment_method(); + $intent = WC_Helper_Intention::create_intention(); + + $this->mock_gateway->expects( $this->once() ) ->method( 'manage_customer_details_for_order' ) ->will( $this->returnValue( [ wp_get_current_user(), 'cus_123' ] ) @@ -371,144 +371,36 @@ public function test_process_payment_returns_correct_redirect_when_using_payment $this->set_cart_contains_subscription_items( false ); - $result = $this->mock_upe_gateway->process_payment( $order->get_id() ); + $result = $this->mock_gateway->process_payment( $order->get_id() ); - $this->mock_upe_gateway - ->expects( $this->never() ) - ->method( 'manage_customer_details_for_order' ); $this->assertEquals( 'success', $result['result'] ); $this->assertEquals( $this->return_url, $result['redirect'] ); } - public function test_upe_process_payment_check_session_order_redirect_to_previous_order() { - $_POST['wc_payment_intent_id'] = 'pi_mock'; - - $response = [ - 'dummy_result' => 'xyz', - ]; - - // Arrange the order is being processed. - $current_order = WC_Helper_Order::create_order(); - $current_order_id = $current_order->get_id(); - - // Arrange the DPPS to return an order from the session. - $this->mock_dpps->expects( $this->once() ) - ->method( 'check_against_session_processing_order' ) - ->with( wc_get_order( $current_order ) ) - ->willReturn( $response ); - - // Assert: no call to the server to confirm the payment. - $this->mock_wcpay_request( Update_Intention::class, 0, 'pi_XXXXX' ); - - // Act: process the order but redirect to the previous/session paid order. - $result = $this->mock_upe_gateway->process_payment( $current_order_id ); - - // Assert: the result of check_against_session_processing_order. - $this->assertSame( $response, $result ); - } - - public function test_upe_process_payment_check_session_with_failed_intent_then_order_id_saved_to_session() { - $_POST['wc_payment_intent_id'] = 'pi_mock'; - $this->mock_upe_gateway->expects( $this->once() ) - ->method( 'manage_customer_details_for_order' ) - ->will( - $this->returnValue( [ wp_get_current_user(), 'cus_123' ] ) - ); - - // Arrange the order is being processed. - $current_order = WC_Helper_Order::create_order(); - $current_order_id = $current_order->get_id(); - - // Arrange a failed intention. - $intent = WC_Helper_Intention::create_intention( [ 'status' => 'failed' ] ); - - // Assert. - $update_request = $this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1, $intent->get_id() ); - $update_request->expects( $this->once() ) - ->method( 'format_response' ) - ->willReturn( $intent ); - - // Arrange the DPPS not to return an order from the session. - $this->mock_dpps->expects( $this->once() ) - ->method( 'check_against_session_processing_order' ) - ->with( wc_get_order( $current_order ) ) - ->willReturn( null ); - - // Assert: maybe_update_session_processing_order takes action and its value is kept. - $this->mock_dpps->expects( $this->once() ) - ->method( 'maybe_update_session_processing_order' ) - ->with( $current_order_id ); - - // Act: process the order but redirect to the previous/session paid order. - $this->mock_upe_gateway->process_payment( $current_order_id ); - } - - public function test_upe_process_payment_check_session_and_continue_processing() { - $_POST['wc_payment_intent_id'] = 'pi_mock'; + public function test_process_payment_returns_correct_redirect_when_using_payment_request() { + $order = WC_Helper_Order::create_order(); + $intent = WC_Helper_Intention::create_intention(); + $_POST['payment_request_type'] = 'google_pay'; - $this->mock_upe_gateway->expects( $this->once() ) + $this->mock_gateway->expects( $this->once() ) ->method( 'manage_customer_details_for_order' ) ->will( $this->returnValue( [ wp_get_current_user(), 'cus_123' ] ) ); - - // Arrange the order is being processed. - $order = WC_Helper_Order::create_order(); - $order_id = $order->get_id(); - - // Arrange a successful intention. - $intent = WC_Helper_Intention::create_intention(); - - // Arrange the DPPS not to return an order from the session. - $this->mock_dpps->expects( $this->once() ) - ->method( 'check_against_session_processing_order' ) - ->with( wc_get_order( $order ) ) - ->willReturn( null ); - - // Assert: Order is removed from the session. - $this->mock_dpps->expects( $this->once() ) - ->method( 'remove_session_processing_order' ) - ->with( $order_id ); - - // Assert: the payment process continues. $this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1, $intent->get_id() ) ->expects( $this->once() ) ->method( 'format_response' ) ->willReturn( $intent ); + $this->set_cart_contains_subscription_items( false ); - // Act. - $this->mock_upe_gateway->process_payment( $order_id ); - } - - public function test_upe_check_payment_intent_attached_to_order_succeeded_return_redirection() { - $_POST['wc_payment_intent_id'] = 'pi_mock'; - - $response = [ - 'dummy_result' => 'xyz', - ]; - - // Arrange order. - $order = WC_Helper_Order::create_order(); - $order_id = $order->get_id(); - - // Arrange the DPPS to return a prepared response. - $this->mock_dpps->expects( $this->once() ) - ->method( 'check_payment_intent_attached_to_order_succeeded' ) - ->with( wc_get_order( $order ) ) - ->willReturn( $response ); - - // Assert: no more call to the server to update the intention. - $this->mock_wcpay_request( Update_Intention::class, 0 ); - - // Act: process the order but redirect to the order. - $result = $this->mock_upe_gateway->process_payment( $order_id ); + $result = $this->mock_gateway->process_payment( $order->get_id() ); - // Assert: the result of check_intent_attached_to_order_succeeded. - $this->assertSame( $response, $result ); + $this->assertEquals( 'success', $result['result'] ); + $this->assertEquals( $this->return_url, $result['redirect'] ); } public function is_proper_intent_used_with_order_returns_false() { - $this->assertFalse( $this->mock_upe_gateway->is_proper_intent_used_with_order( WC_Helper_Order::create_order(), 'wrong_intent_id' ) ); + $this->assertFalse( $this->mock_gateway->is_proper_intent_used_with_order( WC_Helper_Order::create_order(), 'wrong_intent_id' ) ); } public function test_process_redirect_payment_intent_processing() { @@ -534,7 +426,7 @@ public function test_process_redirect_payment_intent_processing() { ] ); - $this->mock_upe_gateway->expects( $this->once() ) + $this->mock_gateway->expects( $this->once() ) ->method( 'manage_customer_details_for_order' ) ->will( $this->returnValue( [ $user, $customer_id ] ) @@ -548,7 +440,7 @@ public function test_process_redirect_payment_intent_processing() { $this->set_cart_contains_subscription_items( false ); - $this->mock_upe_gateway->process_redirect_payment( $order, $intent_id, $save_payment_method ); + $this->mock_gateway->process_redirect_payment( $order, $intent_id, $save_payment_method ); $result_order = wc_get_order( $order_id ); $note = wc_get_order_notes( @@ -590,7 +482,7 @@ public function test_process_redirect_payment_intent_succeded() { ] ); - $this->mock_upe_gateway->expects( $this->once() ) + $this->mock_gateway->expects( $this->once() ) ->method( 'manage_customer_details_for_order' ) ->will( $this->returnValue( [ $user, $customer_id ] ) @@ -604,7 +496,7 @@ public function test_process_redirect_payment_intent_succeded() { $this->set_cart_contains_subscription_items( false ); - $this->mock_upe_gateway->process_redirect_payment( $order, $intent_id, $save_payment_method ); + $this->mock_gateway->process_redirect_payment( $order, $intent_id, $save_payment_method ); $result_order = wc_get_order( $order_id ); @@ -624,7 +516,7 @@ public function test_validate_order_id_received_vs_intent_meta_order_id_throw_ex $this->expectExceptionMessage( "We're not able to process this payment due to the order ID mismatch. Please try again later." ); \PHPUnit_Utils::call_method( - $this->mock_upe_gateway, + $this->mock_gateway, 'validate_order_id_received_vs_intent_meta_order_id', [ $order, $intent_metadata ] ); @@ -635,7 +527,7 @@ public function test_validate_order_id_received_vs_intent_meta_order_id_returnin $intent_metadata = [ 'order_id' => (string) ( $order->get_id() ) ]; $res = \PHPUnit_Utils::call_method( - $this->mock_upe_gateway, + $this->mock_gateway, 'validate_order_id_received_vs_intent_meta_order_id', [ $order, $intent_metadata ] ); @@ -721,7 +613,7 @@ public function test_correct_payment_method_title_for_order() { ]; foreach ( $charge_payment_method_details as $i => $payment_method_details ) { - $this->mock_upe_gateway->set_payment_method_title_for_order( $order, $payment_method_details['type'], $payment_method_details ); + $this->mock_gateway->set_payment_method_title_for_order( $order, $payment_method_details['type'], $payment_method_details ); $this->assertEquals( $expected_payment_method_titles[ $i ], $order->get_payment_method_title() ); } } @@ -1019,24 +911,7 @@ public function test_create_token_from_setup_intent_adds_token() { $this->returnValue( $mock_token ) ); - $this->assertEquals( $mock_token, $this->mock_upe_gateway->create_token_from_setup_intent( $mock_setup_intent_id, $mock_user ) ); - } - - public function test_process_payment_rejects_with_cached_minimum_acount() { - $order = WC_Helper_Order::create_order(); - $order->set_currency( 'USD' ); - $order->set_total( 0.45 ); - $order->save(); - - set_transient( 'wcpay_minimum_amount_usd', '50', DAY_IN_SECONDS ); - $_POST['wc_payment_intent_id'] = 'pi_mock'; - - // Make sure that the payment was not actually processed. - $price = wp_strip_all_tags( html_entity_decode( wc_price( 0.5, [ 'currency' => 'USD' ] ) ) ); - $message = 'The selected payment method requires a total amount of at least ' . $price . '.'; - $this->expectException( Exception::class ); - $this->expectExceptionMessage( $message ); - $this->mock_upe_gateway->process_payment( $order->get_id() ); + $this->assertEquals( $mock_token, $this->mock_gateway->create_token_from_setup_intent( $mock_setup_intent_id, $mock_user ) ); } public function test_exception_will_be_thrown_if_phone_number_is_invalid() { @@ -1045,20 +920,20 @@ public function test_exception_will_be_thrown_if_phone_number_is_invalid() { $order->save(); $this->expectException( Exception::class ); $this->expectExceptionMessage( 'Invalid phone number.' ); - $this->mock_upe_gateway->process_payment( $order->get_id() ); + $this->mock_gateway->process_payment( $order->get_id() ); } public function test_remove_link_payment_method_if_card_disabled() { - $this->mock_upe_gateway->settings['upe_enabled_payment_method_ids'] = [ 'link' ]; + $this->mock_gateway->settings['upe_enabled_payment_method_ids'] = [ 'link' ]; - $this->mock_upe_gateway + $this->mock_gateway ->expects( $this->once() ) ->method( 'get_upe_enabled_payment_method_statuses' ) ->will( $this->returnValue( [ 'link_payments' => [ 'status' => 'active' ] ] ) ); - $this->assertSame( $this->mock_upe_gateway->get_payment_method_ids_enabled_at_checkout(), [] ); + $this->assertSame( $this->mock_gateway->get_payment_method_ids_enabled_at_checkout(), [] ); } /** @@ -1143,7 +1018,7 @@ private function set_get_upe_enabled_payment_method_statuses_return_value( $retu ], ]; } - $this->mock_upe_gateway + $this->mock_gateway ->expects( $this->any() ) ->method( 'get_upe_enabled_payment_method_statuses' ) ->will( $this->returnValue( $return_value ) ); diff --git a/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php b/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php index 40073536fd0..e788e467a14 100644 --- a/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php +++ b/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php @@ -410,101 +410,6 @@ public function test_non_reusable_payment_method_is_not_available_when_subscript $this->assertFalse( $payment_gateway->is_available() ); } - public function test_process_payment_returns_correct_redirect_url() { - $order = WC_Helper_Order::create_order(); - $user = wp_get_current_user(); - $customer_id = 'cus_mock'; - - $payment_intent = WC_Helper_Intention::create_intention( [ 'status' => Intent_Status::PROCESSING ] ); - - $this->set_cart_contains_subscription_items( false ); - - foreach ( $this->mock_payment_gateways as $mock_payment_gateway ) { - $mock_payment_gateway - ->method( 'manage_customer_details_for_order' ) - ->will( - $this->returnValue( [ $user, $customer_id ] ) - ); - $mock_payment_gateway->expects( $this->any() ) - ->method( 'get_upe_enabled_payment_method_ids' ) - ->will( - $this->returnValue( [ Payment_Method::CARD ] ) - ); - $this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1, $payment_intent->get_id() ) - ->expects( $this->once() ) - ->method( 'format_response' ) - ->willReturn( $payment_intent ); - - $result = $mock_payment_gateway->process_payment( $order->get_id() ); - $this->assertEquals( 'success', $result['result'] ); - $this->assertEquals( $this->return_url, $result['redirect'] ); - } - } - - public function test_process_subscription_payment_passes_save_payment_method() { - $order = WC_Helper_Order::create_order(); - $mock_card_payment_gateway = $this->mock_payment_gateways[ Payment_Method::CARD ]; - $mock_sepa_payment_gateway = $this->mock_payment_gateways[ Payment_Method::SEPA ]; - $user = wp_get_current_user(); - $customer_id = 'cus_mock'; - - $mock_card_payment_gateway->expects( $this->once() ) - ->method( 'manage_customer_details_for_order' ) - ->will( - $this->returnValue( [ $user, $customer_id ] ) - ); - $mock_sepa_payment_gateway->expects( $this->once() ) - ->method( 'manage_customer_details_for_order' ) - ->will( - $this->returnValue( [ $user, $customer_id ] ) - ); - $mock_card_payment_gateway->expects( $this->any() ) - ->method( 'get_upe_enabled_payment_method_ids' ) - ->will( - $this->returnValue( [ Payment_Method::CARD ] ) - ); - - // assertion for both card and SEPA. - $this->mock_token_service - ->expects( $this->exactly( 2 ) ) - ->method( 'add_payment_method_to_user' ) - ->willReturn( new WC_Payment_Token_CC() ); - - $payment_intent = WC_Helper_Intention::create_intention( [ 'status' => Intent_Status::PROCESSING ] ); - - // Test card. - $this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1, $payment_intent->get_id() ) - ->expects( $this->once() ) - ->method( 'format_response' ) - ->willReturn( - $payment_intent - ); - $mock_card_payment_gateway - ->expects( $this->once() ) - ->method( 'is_payment_recurring' ) - ->willReturn( true ); - - $result = $mock_card_payment_gateway->process_payment( $order->get_id() ); - $this->assertEquals( 'success', $result['result'] ); - $this->assertEquals( $this->return_url, $result['redirect'] ); - - // Test SEPA. - $this->mock_wcpay_request( Create_And_Confirm_Intention::class, 1, $payment_intent->get_id() ) - ->expects( $this->once() ) - ->method( 'format_response' ) - ->willReturn( - $payment_intent - ); - - $mock_sepa_payment_gateway - ->expects( $this->once() ) - ->method( 'is_payment_recurring' ) - ->willReturn( true ); - $result = $mock_sepa_payment_gateway->process_payment( $order->get_id() ); - $this->assertEquals( 'success', $result['result'] ); - $this->assertEquals( $this->return_url, $result['redirect'] ); - } - public function test_process_payment_returns_correct_redirect_when_using_saved_payment() { $mock_card_payment_gateway = $this->mock_payment_gateways[ Payment_Method::CARD ]; $user = wp_get_current_user(); diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php b/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php index 26ebfdbdb26..8cd1668986d 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php @@ -11,7 +11,6 @@ use WCPay\Duplicate_Payment_Prevention_Service; use WCPay\Session_Rate_Limiter; use WCPay\Fraud_Prevention\Fraud_Prevention_Service; -use WCPay\Internal\Service\OrderService; use WCPay\Payment_Methods\CC_Payment_Method; /** @@ -135,10 +134,7 @@ public function set_up() { $this->mock_order_service = $this->createMock( WC_Payments_Order_Service::class ); $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - $mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class ) - ->setConstructorArgs( [ $this->mock_token_service ] ) - ->onlyMethods( [ 'is_subscription_item_in_cart' ] ) - ->getMock(); + $mock_payment_method = $this->createMock( CC_Payment_Method::class ); // Arrange: Mock WC_Payment_Gateway_WCPay so that some of its methods can be // mocked, and their return values can be used for testing. diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php b/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php index 17763edad48..1ce7132f420 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php @@ -6,14 +6,10 @@ */ use WCPay\Core\Server\Request\Create_And_Confirm_Intention; -use WCPay\Core\Server\Request\WooPay_Create_And_Confirm_Intention; use WCPay\Core\Server\Request\Create_And_Confirm_Setup_Intention; use WCPay\Core\Server\Request\Get_Charge; -use WCPay\Core\Server\Response; use WCPay\Constants\Order_Status; use WCPay\Constants\Intent_Status; -use WCPay\Core\Server\Request\Get_Intention; -use WCPay\Core\Server\Request\Update_Intention; use WCPay\Duplicate_Payment_Prevention_Service; use WCPay\Exceptions\API_Exception; use WCPay\Exceptions\Connection_Exception; @@ -152,10 +148,7 @@ public function set_up() { $this->mock_order_service = $this->createMock( WC_Payments_Order_Service::class ); $this->mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - $mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class ) - ->setConstructorArgs( [ $this->mock_token_service ] ) - ->onlyMethods( [ 'is_subscription_item_in_cart' ] ) - ->getMock(); + $mock_payment_method = $this->createMock( CC_Payment_Method::class ); // Arrange: Mock WC_Payment_Gateway_WCPay so that some of its methods can be // mocked, and their return values can be used for testing. diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php b/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php index 0ee85f7c78c..7350621aedc 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php @@ -90,10 +90,7 @@ public function set_up() { $this->mock_rate_limiter = $this->createMock( Session_Rate_Limiter::class ); $this->mock_order_service = $this->createMock( WC_Payments_Order_Service::class ); $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - $mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class ) - ->setConstructorArgs( [ $this->mock_token_service ] ) - ->onlyMethods( [ 'is_subscription_item_in_cart' ] ) - ->getMock(); + $mock_payment_method = $this->createMock( CC_Payment_Method::class ); $this->wcpay_gateway = new WC_Payment_Gateway_WCPay( $this->mock_api_client, diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php index 3321445d269..9715d61a193 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php @@ -6,7 +6,6 @@ */ use WCPay\Duplicate_Payment_Prevention_Service; -use WCPay\Exceptions\API_Exception; use WCPay\Payment_Methods\CC_Payment_Method; use WCPay\Session_Rate_Limiter; @@ -143,7 +142,6 @@ public function set_up() { $this->createMock( WC_Payments_Fraud_Service::class ) ); $this->wcpay_gateway->init_hooks(); - WC_Payments::set_gateway( $this->wcpay_gateway ); $this->renewal_order = WC_Helper_Order::create_order( self::USER_ID ); diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php index bd642135bb5..168349f902d 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php @@ -7,7 +7,6 @@ use WCPay\Core\Server\Request\Create_And_Confirm_Intention; use WCPay\Core\Server\Request\Create_And_Confirm_Setup_Intention; -use WCPay\Core\Server\Response; use WCPay\Constants\Order_Status; use WCPay\Constants\Intent_Status; use WCPay\Duplicate_Payment_Prevention_Service; @@ -143,12 +142,8 @@ public function set_up() { $this->order_service = new WC_Payments_Order_Service( $this->mock_api_client ); - $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - - $mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class ) - ->setConstructorArgs( [ $this->mock_token_service ] ) - ->onlyMethods( [ 'is_subscription_item_in_cart' ] ) - ->getMock(); + $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); + $mock_payment_method = $this->createMock( CC_Payment_Method::class ); $this->mock_wcpay_gateway = $this->getMockBuilder( '\WC_Payment_Gateway_WCPay' ) ->setConstructorArgs( @@ -176,7 +171,6 @@ public function set_up() { ] ) ->getMock(); - WC_Payments::set_gateway( $this->mock_wcpay_gateway ); $this->mock_customer_service ->expects( $this->once() ) diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php index 54cbb997f41..a5b33c1581c 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php @@ -11,18 +11,7 @@ use WCPay\Exceptions\API_Exception; use WCPay\Internal\Service\Level3Service; use WCPay\Internal\Service\OrderService; -use WCPay\Payment_Methods\Affirm_Payment_Method; -use WCPay\Payment_Methods\Afterpay_Payment_Method; -use WCPay\Payment_Methods\Bancontact_Payment_Method; -use WCPay\Payment_Methods\Becs_Payment_Method; use WCPay\Payment_Methods\CC_Payment_Method; -use WCPay\Payment_Methods\Eps_Payment_Method; -use WCPay\Payment_Methods\Giropay_Payment_Method; -use WCPay\Payment_Methods\Ideal_Payment_Method; -use WCPay\Payment_Methods\Link_Payment_Method; -use WCPay\Payment_Methods\P24_Payment_Method; -use WCPay\Payment_Methods\Sepa_Payment_Method; -use WCPay\Payment_Methods\Sofort_Payment_Method; use WCPay\Session_Rate_Limiter; /** diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay.php b/tests/unit/test-class-wc-payment-gateway-wcpay.php index fd2449fb57d..02505f94d51 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay.php @@ -13,9 +13,7 @@ use WCPay\Core\Server\Request\Get_Charge; use WCPay\Core\Server\Request\Get_Intention; use WCPay\Core\Server\Request\Get_Setup_Intention; -use WCPay\Core\Server\Request\Update_Intention; use WCPay\Constants\Order_Status; -use WCPay\Constants\Payment_Type; use WCPay\Constants\Intent_Status; use WCPay\Duplicate_Payment_Prevention_Service; use WCPay\Exceptions\Amount_Too_Small_Exception; diff --git a/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php b/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php index 172a40b5ddf..899e530aa67 100644 --- a/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php +++ b/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php @@ -149,10 +149,7 @@ private function make_wcpay_gateway() { $mock_rate_limiter = $this->createMock( Session_Rate_Limiter::class ); $mock_order_service = $this->createMock( WC_Payments_Order_Service::class ); $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - $mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class ) - ->setConstructorArgs( [ $mock_token_service ] ) - ->onlyMethods( [ 'is_subscription_item_in_cart' ] ) - ->getMock(); + $mock_payment_method = $this->createMock( CC_Payment_Method::class ); return new WC_Payment_Gateway_WCPay( $this->mock_api_client, diff --git a/tests/unit/test-class-wc-payments-payment-request-button-handler.php b/tests/unit/test-class-wc-payments-payment-request-button-handler.php index 85a998ad034..e4d7412bf15 100644 --- a/tests/unit/test-class-wc-payments-payment-request-button-handler.php +++ b/tests/unit/test-class-wc-payments-payment-request-button-handler.php @@ -199,10 +199,7 @@ private function make_wcpay_gateway() { $mock_rate_limiter = $this->createMock( Session_Rate_Limiter::class ); $mock_order_service = $this->createMock( WC_Payments_Order_Service::class ); $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - $mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class ) - ->setConstructorArgs( [ $mock_token_service ] ) - ->onlyMethods( [ 'is_subscription_item_in_cart' ] ) - ->getMock(); + $mock_payment_method = $this->createMock( CC_Payment_Method::class ); return new WC_Payment_Gateway_WCPay( $this->mock_api_client, diff --git a/tests/unit/test-class-wc-payments-woopay-button-handler.php b/tests/unit/test-class-wc-payments-woopay-button-handler.php index a5bd84c7c39..161c5796101 100644 --- a/tests/unit/test-class-wc-payments-woopay-button-handler.php +++ b/tests/unit/test-class-wc-payments-woopay-button-handler.php @@ -13,7 +13,7 @@ /** * WC_Payments_WooPay_Button_Handler_Test class. */ -class WC_Payments_TK_Test extends WCPAY_UnitTestCase { +class WC_Payments_WooPay_Button_Handler_Test extends WCPAY_UnitTestCase { /** * Mock WC_Payments_API_Client. * @@ -128,10 +128,7 @@ private function make_wcpay_gateway() { $mock_rate_limiter = $this->createMock( Session_Rate_Limiter::class ); $mock_order_service = $this->createMock( WC_Payments_Order_Service::class ); $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - $mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class ) - ->setConstructorArgs( [ $mock_token_service ] ) - ->onlyMethods( [ 'is_subscription_item_in_cart' ] ) - ->getMock(); + $mock_payment_method = $this->createMock( CC_Payment_Method::class ); return new WC_Payment_Gateway_WCPay( $this->mock_api_client,