mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-04 08:48:35 +00:00
(rename unit folder back as Unit)
This commit is contained in:
33
tests/Unit/Billing/FakePaymentGatewayTest.php
Normal file
33
tests/Unit/Billing/FakePaymentGatewayTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Billing;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Billing\FakePaymentGateway;
|
||||
|
||||
class FakePaymentGatewayTest extends TestCase
|
||||
{
|
||||
use PaymentGatewayContractTests;
|
||||
|
||||
protected function getPaymentGateway()
|
||||
{
|
||||
return new FakePaymentGateway;
|
||||
}
|
||||
|
||||
/** @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());
|
||||
}
|
||||
}
|
||||
68
tests/Unit/Billing/PaymentGatewayContractTests.php
Normal file
68
tests/Unit/Billing/PaymentGatewayContractTests.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Billing;
|
||||
|
||||
use App\Billing\PaymentFailedException;
|
||||
|
||||
trait PaymentGatewayContractTests
|
||||
{
|
||||
abstract protected function getPaymentGateway();
|
||||
|
||||
/** @test */
|
||||
function charges_with_a_valid_payment_token_are_successful()
|
||||
{
|
||||
$paymentGateway = $this->getPaymentGateway();
|
||||
|
||||
$newCharges = $paymentGateway->newChargesDuring(function ($paymentGateway) {
|
||||
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
|
||||
});
|
||||
|
||||
$this->assertCount(1, $newCharges);
|
||||
$this->assertEquals(2500, $newCharges->map->amount()->sum());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function can_get_details_about_a_successful_charge()
|
||||
{
|
||||
$paymentGateway = $this->getPaymentGateway();
|
||||
|
||||
$charge = $paymentGateway->charge(2500, $paymentGateway->getValidTestToken($paymentGateway::TEST_CARD_NUMBER));
|
||||
|
||||
$this->assertEquals(substr($paymentGateway::TEST_CARD_NUMBER, -4), $charge->cardLastFour());
|
||||
$this->assertEquals(2500, $charge->amount());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function charges_with_an_invalid_payment_token_fail()
|
||||
{
|
||||
$paymentGateway = $this->getPaymentGateway();
|
||||
|
||||
$newCharges = $paymentGateway->newChargesDuring(function ($paymentGateway) {
|
||||
try {
|
||||
$paymentGateway->charge(2500, 'invalid-payment-token');
|
||||
} catch (PaymentFailedException $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fail("Charging with an invalid payment token did not throw a PaymentFailedException.");
|
||||
});
|
||||
|
||||
$this->assertCount(0, $newCharges);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function can_fetch_charges_created_during_a_callback()
|
||||
{
|
||||
$paymentGateway = $this->getPaymentGateway();
|
||||
$paymentGateway->charge(2000, $paymentGateway->getValidTestToken());
|
||||
$paymentGateway->charge(3000, $paymentGateway->getValidTestToken());
|
||||
|
||||
$newCharges = $paymentGateway->newChargesDuring(function ($paymentGateway) {
|
||||
$paymentGateway->charge(4000, $paymentGateway->getValidTestToken());
|
||||
$paymentGateway->charge(5000, $paymentGateway->getValidTestToken());
|
||||
});
|
||||
|
||||
$this->assertCount(2, $newCharges);
|
||||
$this->assertEquals([5000, 4000], $newCharges->map->amount()->all());
|
||||
}
|
||||
}
|
||||
19
tests/Unit/Billing/StripePaymentGatewayTest.php
Normal file
19
tests/Unit/Billing/StripePaymentGatewayTest.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Billing;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Billing\StripePaymentGateway;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class StripePaymentGatewayTest extends TestCase
|
||||
{
|
||||
use PaymentGatewayContractTests;
|
||||
|
||||
protected function getPaymentGateway()
|
||||
{
|
||||
return new StripePaymentGateway(config('services.stripe.secret'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user