Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active November 19, 2023 14:10
Show Gist options
  • Save mcsee/1a84f6cf33594a0b63f5171a13513439 to your computer and use it in GitHub Desktop.
Save mcsee/1a84f6cf33594a0b63f5171a13513439 to your computer and use it in GitHub Desktop.
<?php
namespace phpUnitTutorial\Test;
use phpUnitTutorial\Payment;
class PaymentTest extends \PHPUnit_Framework_TestCase
{
public function testProcessPaymentReturnsTrueOnSuccessfulPayment()
{
$paymentDetails = array(
'amount' => 123.99,
'card_num' => '4111-1111-1111-1111',
'exp_date' => '03/2013',
);
$payment = new Payment();
// Payment is a real one
$response = new \stdClass();
$response->approved = true;
$response->transaction_id = 123;
$authorizeNet = $this->getMockBuilder('\AuthorizeNetAIM')
->setConstructorArgs(
array($payment::API_ID, $payment::TRANS_KEY))
->getMock();
// External system is mocked
$authorizeNet->expects($this->once())
->method('authorizeAndCapture')
->will($this->returnValue($response));
$result = $payment->processPayment($authorizeNet, $paymentDetails);
$this->assertTrue($result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment