diff --git a/tests/unit/Billing/FakePaymentGatewayTest.php b/tests/unit/Billing/FakePaymentGatewayTest.php index f623a82..ab66b71 100644 --- a/tests/unit/Billing/FakePaymentGatewayTest.php +++ b/tests/unit/Billing/FakePaymentGatewayTest.php @@ -15,19 +15,6 @@ class FakePaymentGatewayTest extends TestCase return new FakePaymentGateway; } - /** @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() { diff --git a/tests/unit/Billing/PaymentGatewayContractTests.php b/tests/unit/Billing/PaymentGatewayContractTests.php index 1c3b4cb..04025db 100644 --- a/tests/unit/Billing/PaymentGatewayContractTests.php +++ b/tests/unit/Billing/PaymentGatewayContractTests.php @@ -1,5 +1,7 @@ assertEquals(2500, $newCharges->sum()); } + /** @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() { diff --git a/tests/unit/Billing/StripePaymentGatewayTest.php b/tests/unit/Billing/StripePaymentGatewayTest.php index 829a441..07ec889 100644 --- a/tests/unit/Billing/StripePaymentGatewayTest.php +++ b/tests/unit/Billing/StripePaymentGatewayTest.php @@ -10,58 +10,8 @@ class StripePaymentGatewayTest extends TestCase { use PaymentGatewayContractTests; - protected function setUp() - { - parent::setUp(); - $this->lastCharge = $this->lastCharge(); - } - protected function getPaymentGateway() { return new StripePaymentGateway(config('services.stripe.secret')); } - - /** @test */ - function charges_with_an_invalid_payment_token_fail() - { - try { - $paymentGateway = new StripePaymentGateway(config('services.stripe.secret')); - $paymentGateway->charge(2500, 'invalid-payment-token'); - } catch (PaymentFailedException $e) { - $this->assertCount(0, $this->newCharges()); - return; - } - - $this->fail("Charging with an invalid payment token did not throw a PaymentFailedException."); - } - - private function lastCharge() - { - return array_first(\Stripe\Charge::all( - ['limit' => 1], - ['api_key' => config('services.stripe.secret')] - )['data']); - } - - private function newCharges() - { - return \Stripe\Charge::all( - [ - 'ending_before' => $this->lastCharge ? $this->lastCharge->id : null, - ], - ['api_key' => config('services.stripe.secret')] - )['data']; - } - - private function validToken() - { - return \Stripe\Token::create([ - "card" => [ - "number" => "4242424242424242", - "exp_month" => 1, - "exp_year" => date('Y') + 1, - "cvc" => "123" - ] - ], ['api_key' => config('services.stripe.secret')])->id; - } }