Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active August 23, 2023 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsee/191cee3a71132501564cdb58abef27a7 to your computer and use it in GitHub Desktop.
Save mcsee/191cee3a71132501564cdb58abef27a7 to your computer and use it in GitHub Desktop.
<?
class PaymentTest extends TestCase
{
public function testProcessPaymentReturnsTrueOnSuccessfulPayment()
{
$paymentDetails = array(
'amount' => 123.99,
'card_num' => '4111-1111-1111-1111',
'exp_date' => '03/2013',
);
$payment = $this->getMockBuilder('Payment')
->setConstructorArgs(array())
->getMock();
// You should not mock a business object!
$authorizeNet = new AuthorizeNetAIM(
$payment::API_ID, $payment::TRANS_KEY);
// This is an external and coupled system.
// You have no control over it so tests become fragile
$paymentProcessResult = $payment->processPayment(
$authorizeNet, $paymentDetails);
$this->assertTrue($paymentProcessResult);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment