Files
ticketbeast/tests/unit/Billing/FakePaymentGatewayTest.php
2017-01-17 19:57:34 -05:00

56 lines
1.6 KiB
PHP

<?php
use App\Billing\FakePaymentGateway;
use App\Billing\PaymentFailedException;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class FakePaymentGatewayTest extends TestCase
{
protected function getPaymentGateway()
{
return new FakePaymentGateway;
}
/** @test */
function charges_with_a_valid_payment_token_are_successful()
{
$paymentGateway = $this->getPaymentGateway();
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
$this->assertEquals(2500, $paymentGateway->totalCharges());
}
/** @test */
function charges_with_an_invalid_payment_token_fail()
{
try {
$paymentGateway = new FakePaymentGateway;
$paymentGateway->charge(2500, 'invalid-payment-token');
} catch (PaymentFailedException $e) {
return;
}
$this->fail();
}
/** @test */
function running_a_hook_before_the_first_charge()
{
$paymentGateway = new FakePaymentGateway;
$timesCallbackRan = 0;
$paymentGateway->beforeFirstCharge(function ($paymentGateway) use (&$timesCallbackRan) {
$timesCallbackRan++;
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
$this->assertEquals(2500, $paymentGateway->totalCharges());
});
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
$this->assertEquals(1, $timesCallbackRan);
$this->assertEquals(5000, $paymentGateway->totalCharges());
}
}