mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-17 14:54:04 +00:00
64 - Making the Tests Identical
This commit is contained in:
@@ -31,6 +31,13 @@ class FakePaymentGateway implements PaymentGateway
|
|||||||
$this->charges[] = $amount;
|
$this->charges[] = $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newChargesDuring($callback)
|
||||||
|
{
|
||||||
|
$chargesFrom = $this->charges->count();
|
||||||
|
$callback($this);
|
||||||
|
return $this->charges->slice($chargesFrom)->values();
|
||||||
|
}
|
||||||
|
|
||||||
public function totalCharges()
|
public function totalCharges()
|
||||||
{
|
{
|
||||||
return $this->charges->sum();
|
return $this->charges->sum();
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ interface PaymentGateway
|
|||||||
public function charge($amount, $token);
|
public function charge($amount, $token);
|
||||||
|
|
||||||
public function getValidTestToken();
|
public function getValidTestToken();
|
||||||
|
public function newChargesDuring($callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,14 +13,33 @@ class FakePaymentGatewayTest extends TestCase
|
|||||||
return new FakePaymentGateway;
|
return new FakePaymentGateway;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @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([4000, 5000], $newCharges->all());
|
||||||
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
function charges_with_a_valid_payment_token_are_successful()
|
function charges_with_a_valid_payment_token_are_successful()
|
||||||
{
|
{
|
||||||
$paymentGateway = $this->getPaymentGateway();
|
$paymentGateway = $this->getPaymentGateway();
|
||||||
|
|
||||||
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
|
$newCharges = $paymentGateway->newChargesDuring(function ($paymentGateway) {
|
||||||
|
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
|
||||||
|
});
|
||||||
|
|
||||||
$this->assertEquals(2500, $paymentGateway->totalCharges());
|
$this->assertCount(1, $newCharges);
|
||||||
|
$this->assertEquals(2500, $newCharges->sum());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|||||||
Reference in New Issue
Block a user