Skip to content

Commit

Permalink
Using a mock intent
Browse files Browse the repository at this point in the history
  • Loading branch information
RadoslavGeorgiev committed Oct 24, 2023
1 parent bffca58 commit b277785
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/unit/src/Internal/Payment/State/InitialStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit_Utils;
use WC_Order;
use WC_Payments_API_Payment_Intention;
use WC_Payments_Customer_Service;
use WCPay\Core\Exceptions\Server\Request\Invalid_Request_Parameter_Exception;
use WCPay\Internal\Payment\State\InitialState;
Expand Down Expand Up @@ -179,11 +180,13 @@ public function test_processing_will_transition_to_auth_required_state() {
$mock_request = $this->createMock( PaymentRequest::class );
$mock_auth_state = $this->createMock( AuthenticationRequiredState::class );

$intent = WC_Helper_Intention::create_intention( [ 'status' => Intent_Status::REQUIRES_ACTION ] );
// Create an intent, and make sure it will be returned by the service.
$mock_intent = $this->createMock( WC_Payments_API_Payment_Intention::class );
$mock_intent->expects( $this->once() )->method( 'get_status' )->willReturn( Intent_Status::REQUIRES_ACTION );
$this->mock_payment_request_service->expects( $this->once() )
->method( 'create_intent' )
->with( $this->mock_context )
->willReturn( $intent );
->willReturn( $mock_intent );

// Let's mock these services in order to prevent real execution of them.
$this->mocked_sut->expects( $this->once() )->method( 'populate_context_from_request' )->with( $mock_request );
Expand All @@ -195,7 +198,7 @@ public function test_processing_will_transition_to_auth_required_state() {
->willReturn( $order_id );
$this->mock_order_service->expects( $this->once() )
->method( 'update_order_from_intent_that_requires_action' )
->with( $order_id, $intent, $this->mock_context );
->with( $order_id, $mock_intent, $this->mock_context );

$this->mock_state_factory->expects( $this->once() )
->method( 'create_state' )
Expand Down

0 comments on commit b277785

Please sign in to comment.