(rename unit folder back as Unit)

This commit is contained in:
Adam Wathan
2017-05-02 15:42:41 -04:00
parent 1d8dfb6cf2
commit 0bcdd67a81
10 changed files with 0 additions and 0 deletions

View 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());
}
}

View 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());
}
}

View 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'));
}
}