The doubles ship in the runtime package (src/Testing/), so your suite uses them with no extra dependency and
no vendoring. They impose no test framework: everything returns data for you to assert on.
| Implementation | Description |
|---|---|
InMemoryProvider |
resolves from a map; reports FLAG_NOT_FOUND / TYPE_MISMATCH like a real provider |
RecordingProvider |
decorator that records every evaluation |
ThrowingProvider |
fails on demand, globally or per flag |
ControllableCircuitBreaker |
pin the circuit open or closed |
$provider = new InMemoryProvider(['new-checkout' => true, 'variant' => 'blue']);
$flags = Flipster::for($provider)
->withDefaults(['new-checkout' => false, 'variant' => 'control'])
->evaluator();It behaves like a real provider including when it fails, which is deliberate: a double that only models the
happy path lets the failure paths rot untested. An unseeded flag reports FLAG_NOT_FOUND; a wrongly typed one
reports TYPE_MISMATCH.
It is also the one deliberately mutable class in the library, because tests need a flag to change between assertions:
$provider->set('new-checkout', false); // a rollout being flipped mid-run
$provider->remove('new-checkout'); // the flag disappearing upstreamSeed an arbitrary reason to test your handling of a cached answer:
$provider->set('flag', true, reason: 'CACHED', variant: 'on');$recorder = new RecordingProvider(new InMemoryProvider(['a' => true]));
// ... exercise your code ...
$recorder->wasEvaluated('a'); // bool
$recorder->timesEvaluated('a'); // int
$recorder->evaluatedFlagKeys(); // ['a'] — exactly the flags touched, in order
$recorder->lastEvaluationOf('a')?->targetingKey();Being a decorator, it can sit inside the breaker — which is how you prove an open circuit never reached the provider:
self::assertSame(0, $recorder->timesEvaluated('a'));Pin the outage rather than driving a real breaker to it:
$breaker = new ControllableCircuitBreaker();
$flags = Flipster::for($provider)->withDefaults(['kill' => true])
->withBreaker($breaker, 'flags')->evaluator();
$breaker->open('flags');
self::assertTrue($flags->isEnabled('kill')); // the declared defaultDriving a real breaker means encoding its threshold, strategy, minimumRequests and timeWindow into a test
that is about fallback behaviour and does not care about any of it. Pin the state and test one thing.
The breaker also counts what it was asked, so you can assert the decorator's bookkeeping directly:
$breaker->failureCount('flags');
$breaker->successCount('flags');
$breaker->availabilityCheckCount('flags'); // one per evaluation that reached the breakerAnd to make the provider itself fail:
ThrowingProvider::always('backend down');
ThrowingProvider::forFlags(['flaky'], new InMemoryProvider(['steady' => true]));
ThrowingProvider::throwing(new MySdk\FlagNotFoundException('nope'));The per-flag mode matters more than it looks: it is how you verify that a flag-level exception from your provider's SDK does not trip the breaker for everything else.
None of these read the clock or sleep. A resilience suite that depends on timing fails in CI for reasons nobody investigates, and then gets muted.
If you need to test threshold behaviour rather than pinned state, inject time into your own breaker implementation rather than sleeping.
FlagEvaluator throws for undeclared flags, so a typo fails loudly at runtime. You can also check it up front:
$declared = Flipster::for($provider)->withDefaults($myMap)->defaults()->declaredKeys();
self::assertContains('new-checkout', $declared);