Core
Overrides and Testing
How to override framework bindings safely and register test doubles.
Override strategy
Rebinding same id is the supported extension mechanism. Existing singleton instance is invalidated when binding is replaced.
// framework default
$container->singleton(CacheInterface::class, FileCache::class);
// app override
$container->singleton(CacheInterface::class, RedisCache::class);
Testing
In tests, register fake/spies before resolving system under test.
$container->singleton(MailerInterface::class, FakeMailer::class);
$service = $container->get(CheckoutService::class);