Skip to main content
Subscribd ships a FakeGateway driver that processes all billing operations in memory. You can create subscriptions, apply coupons, charge customers, and simulate failures without any external credentials or network calls. This makes it straightforward to write fast, deterministic tests in CI.

Configure the fake gateway

Set the default gateway to fake in your test bootstrap or base test case. No other configuration is required.
// In your test bootstrap, setUp(), or base TestCase:
config(['subscribd.default' => 'fake']);
The rest of your application code calls Subscribd::for($user)->... exactly as it would in production. The fake driver intercepts every operation transparently.

Create a subscription in a test

use Pixelworxio\Subscribd\Actions\CreateSubscription;
use Pixelworxio\Subscribd\Models\Plan;

config(['subscribd.default' => 'fake']);

$plan = Plan::query()->where('key', 'starter')->firstOrFail();
$subscription = app(CreateSubscription::class)->execute($user, $plan);

expect($subscription->active())->toBeTrue();

Simulate a charge failure

Call shouldFailNextCharge() on the fake gateway instance before the charge. The next charge attempt will throw a RuntimeException.
use Pixelworxio\Subscribd\Support\Money;

Subscribd::gateway('fake')->shouldFailNextCharge();

expect(fn () => Subscribd::for($user)->charge(new Money(1900, 'USD')))
    ->toThrow(RuntimeException::class);

Simulate a subscription creation failure

Call shouldFailNextSubscription() to make the next subscription creation throw:
Subscribd::gateway('fake')->shouldFailNextSubscription();

The FakeGateway is never cached

GatewayManager does not cache the fake driver — each call to Subscribd::gateway('fake') returns a fresh instance. If you need to set a failure flag before an action runs, store the instance first:
$fake = Subscribd::gateway('fake');
$fake->shouldFailNextCharge();

// Now run the action — it will use the same instance
expect(fn () => Subscribd::for($user)->charge(new Money(1900, 'USD')))
    ->toThrow(RuntimeException::class);
Do not chain shouldFailNextCharge() directly off Subscribd::gateway('fake') in one expression and then call the action separately — you will be setting the flag on a different instance. Always store the gateway reference first.
The FakeGateway processes all billing operations in memory with no external calls. It is safe to use in CI without any gateway credentials configured.