Files
ticketbeast/tests/unit/Billing/FakePaymentGatewayTest.php
2016-11-19 20:50:31 -05:00

50 lines
1.4 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
{
/** @test */
function charges_with_a_valid_payment_token_are_successful()
{
$paymentGateway = new FakePaymentGateway;
$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;
$callbackRan = false;
$paymentGateway->beforeFirstCharge(function ($paymentGateway) use (&$callbackRan) {
$callbackRan = true;
$this->assertEquals(0, $paymentGateway->totalCharges());
});
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
$this->assertTrue($callbackRan);
$this->assertEquals(2500, $paymentGateway->totalCharges());
}
}