How do I test Laravel Cashier Checkout Redirect in PEST PHP tests?

49 views Asked by At

I have this subscribeToPlan method which will redirect the logged in user to Stripe's hosted checkout page.

public function subscribeToPlan(StripePlan $plan): \Laravel\Cashier\Checkout
{
    return auth()->user()->newSubscription('default', $plan->plan_id)->checkout([
        'success_url' => route('admin.plans.index'),
        'cancel_url' => route('admin.plans.index'),
    ]);
}

And this is the pest php test which I wrote:

test('User can subscribe to the Plan', function () {
    $plan = Plan::query()->first();
    $checkout = $this->actingAs($this->user)
        ->get(route('admin.plans.purchase', $plan));
   $this->assertInstanceOf(Checkout::class, $checkout);
});

But the problem is the subscribeToPlan method returns an instance of Illuminate\Http\RedirectResponse and not \Laravel\Cashier\Checkout instance. How do I write this test case without mocking anything?

0

There are 0 answers