mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-08 01:50:30 +00:00
6.7 - Replicating the Failure at the Unit Level
This commit is contained in:
@@ -20,7 +20,9 @@ class FakePaymentGateway implements PaymentGateway
|
|||||||
public function charge($amount, $token)
|
public function charge($amount, $token)
|
||||||
{
|
{
|
||||||
if ($this->beforeFirstChargeCallback !== null) {
|
if ($this->beforeFirstChargeCallback !== null) {
|
||||||
$this->beforeFirstChargeCallback->__invoke($this);
|
$callback = $this->beforeFirstChargeCallback;
|
||||||
|
$this->beforeFirstChargeCallback = null;
|
||||||
|
$callback($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($token !== $this->getValidTestToken()) {
|
if ($token !== $this->getValidTestToken()) {
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ class PurchaseTicketsTest extends TestCase
|
|||||||
/** @test */
|
/** @test */
|
||||||
function cannot_purchase_tickets_another_customer_is_already_trying_to_purchase()
|
function cannot_purchase_tickets_another_customer_is_already_trying_to_purchase()
|
||||||
{
|
{
|
||||||
|
$this->disableExceptionHandling();
|
||||||
|
|
||||||
$concert = factory(Concert::class)->states('published')->create([
|
$concert = factory(Concert::class)->states('published')->create([
|
||||||
'ticket_price' => 1200
|
'ticket_price' => 1200
|
||||||
])->addTickets(3);
|
])->addTickets(3);
|
||||||
|
|||||||
@@ -35,15 +35,16 @@ class FakePaymentGatewayTest extends TestCase
|
|||||||
function running_a_hook_before_the_first_charge()
|
function running_a_hook_before_the_first_charge()
|
||||||
{
|
{
|
||||||
$paymentGateway = new FakePaymentGateway;
|
$paymentGateway = new FakePaymentGateway;
|
||||||
$callbackRan = false;
|
$timesCallbackRan = 0;
|
||||||
|
|
||||||
$paymentGateway->beforeFirstCharge(function ($paymentGateway) use (&$callbackRan) {
|
$paymentGateway->beforeFirstCharge(function ($paymentGateway) use (&$timesCallbackRan) {
|
||||||
$callbackRan = true;
|
$timesCallbackRan++;
|
||||||
$this->assertEquals(0, $paymentGateway->totalCharges());
|
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
|
||||||
|
$this->assertEquals(2500, $paymentGateway->totalCharges());
|
||||||
});
|
});
|
||||||
|
|
||||||
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
|
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
|
||||||
$this->assertTrue($callbackRan);
|
$this->assertEquals(1, $timesCallbackRan);
|
||||||
$this->assertEquals(2500, $paymentGateway->totalCharges());
|
$this->assertEquals(5000, $paymentGateway->totalCharges());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user