You are here

function PaymentCaptureFormTest::testSubmitFormWithCompletionResponse in Payment 8.2

@covers ::submitForm

File

tests/src/Unit/Entity/Payment/PaymentCaptureFormTest.php, line 116

Class

PaymentCaptureFormTest
@coversDefaultClass \Drupal\payment\Entity\Payment\PaymentCaptureForm

Namespace

Drupal\Tests\payment\Unit\Entity\Payment

Code

function testSubmitFormWithCompletionResponse() {
  $response = $this
    ->getMockBuilder(Response::class)
    ->disableOriginalConstructor()
    ->getMock();
  $completion_response = $this
    ->createMock(ResponseInterface::class);
  $completion_response
    ->expects($this
    ->atLeastOnce())
    ->method('getResponse')
    ->willReturn($response);
  $operation_result = $this
    ->createMock(OperationResultInterface::class);
  $operation_result
    ->expects($this
    ->atLeastOnce())
    ->method('getCompletionResponse')
    ->willReturn($completion_response);
  $operation_result
    ->expects($this
    ->atLeastOnce())
    ->method('isCompleted')
    ->willReturn(FALSE);
  $payment_method = $this
    ->createMock(PaymentMethodCapturePaymentInterface::class);
  $payment_method
    ->expects($this
    ->once())
    ->method('capturePayment')
    ->willReturn($operation_result);
  $this->payment
    ->expects($this
    ->atLeastOnce())
    ->method('getPaymentMethod')
    ->willReturn($payment_method);
  $form = [];
  $form_state = $this
    ->createMock(FormStateInterface::class);
  $form_state
    ->expects($this
    ->atLeastOnce())
    ->method('setResponse')
    ->with($response);
  $this->sut
    ->submitForm($form, $form_state);
}