Laravel: Lightning Fast Testing for Subscription Payments With Stripe

I should have a base test suite that can run without an internet connection, and it should be super fast. Both of them, at the same time.

Burak Karakan
Level Up Coding
Published in
6 min readJul 7, 2020

--

Laravel has been my go-to framework for all of my side projects thanks to its ease of use, but while integrating Cashier into Nana recently, I have seen that there is no easy way of testing the subscription creation flows when using Cashier. The docs suggest that you do real calls against the Stripe’s test APIs:

When testing an application that uses Cashier, you may mock the actual HTTP requests to the Stripe API; however, this requires you to partially re-implement Cashier’s own behavior. Therefore, we recommend allowing your tests to hit the actual Stripe API.

This might be good advice for certain cases, and would definitely provide a good way to test the flow end-to-end, and it has some advantages:

  • The flow can be tested end-to-end, along with the API contracts and the endpoints in the application.
  • The tests have overall better confidence due to being able to test multiple units within a single test case, such as auth, database interactions, Cashier, payment flows, and more.

--

--