1 month ago

Mocking Cashier methods

Posted 1 month ago by bwrigley


I'm sure I'm missing something obvious here. I'm using Cashier and Stripe for billing and I have a simple method for showing invoices retrieved from Stripe.

I want to write a really simple test to ensure my method is working correctly, Obviously, I'm not trying to test Cashier as that's not mine.

So my test is simply:

    public function test_index_method(): void

and my method is

    public function index(User $user): View
        $invoices = $user->invoices();

        return view('invoices.index', compact('invoices'));

The trouble is that invoices() is on the Billable trait and so it cannot be mocked.

I'd be interested if anyone has a good solution to this? Thanks

Please sign in or create an account to participate in this conversation.