paymentDOMock = $this->createMock(PaymentDataObjectInterface::class); $this->paymentMock = $this->createMock(Payment::class); $this->paymentDOMock->method('getPayment') ->willReturn($this->paymentMock); $this->builder = new PaymentResponseHandler(new SubjectReader()); } public function testHandleDefaultResponse() { $this->paymentMock->method('getAdditionalInformation') ->with('ccLast4') ->willReturn('1234'); // Assert the avs code is saved $this->paymentMock->expects($this->once()) ->method('setCcAvsStatus') ->with('avshurray'); $this->paymentMock->expects($this->once()) ->method('setCcLast4') ->with('1234'); $this->paymentMock->expects($this->once()) ->method('setIsTransactionClosed') ->with(false); $response = [ 'transactionResponse' => [ 'avsResultCode' => 'avshurray', 'responseCode' => self::RESPONSE_CODE_APPROVED, ] ]; $subject = [ 'payment' => $this->paymentDOMock ]; $this->builder->handle($subject, $response); // Assertions are part of mocking above } public function testHandleHeldResponse() { // Assert the avs code is saved $this->paymentMock->expects($this->once()) ->method('setCcAvsStatus') ->with('avshurray'); $this->paymentMock->expects($this->once()) ->method('setIsTransactionClosed') ->with(false); // opaque data wasn't provided $this->paymentMock->expects($this->never()) ->method('setAdditionalInformation'); // Assert the payment is flagged for review $this->paymentMock->expects($this->once()) ->method('setIsTransactionPending') ->with(true) ->willReturnSelf(); $this->paymentMock->expects($this->once()) ->method('setIsFraudDetected') ->with(true); $response = [ 'transactionResponse' => [ 'avsResultCode' => 'avshurray', 'responseCode' => self::RESPONSE_CODE_HELD, ] ]; $subject = [ 'payment' => $this->paymentDOMock ]; $this->builder->handle($subject, $response); // Assertions are part of mocking above } }