Level 16
Sorry to bump an old thread, but would love to find an answer to this as well.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've worked out how to create a token, and from there run tests against Cashier, but I'm not using Mocks so they take quite a while to run.
I create a token like this:
private function createToken($cardNum)
{
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$data = \Stripe\Token::create([
'card' => [
"number" => $cardNum,
"exp_month" => 11,
"exp_year" => 2036,
"cvc" => "314"
]
]);
return $data['id'];
}
Then I can create a new subscription like this:
$token = $this->createToken('4242424242424242');
$this->user->createAsStripeCustomer($token);
$this->user->newSubscription('default', 'standard')->create();
Would anyone know how I could use mocking so I don't hit the Stripe API to speed up these tests?
Please or to participate in this conversation.