docteurklein/test-double-bundle
Symfony bundle to simplify creating test doubles. Replace services automatically with stubs or fakes via DI container tags, improving test isolation and speed (e.g., Behat). Access original implementations with .real for infrastructure tests.
config/bundles.php. No major refactoring needed.bindWhen or replace methods).KernelTestCase, ServiceTestCase) or PestPHP may offer similar functionality with better support.ServiceProvider hooks)..real suffix (e.g., service.real), which could be confusing if not documented clearly.Symfony Version Compatibility:
Laravel Adaptation Feasibility:
Testing Strategy Impact:
Maintenance Plan:
Team Adoption:
composer require docteurklein/test-double-bundle --dev
config/bundles.php):
TestDoubleBundle\TestDoubleBundle::class => ['env' => 'test'],
composer require --dev phpspec/prophecy
# config/services_test.yaml
services:
App\Service\GithubClient:
tags: ['test_double', { stub: 'GithubClient' }]
.prophecy services for assertions.use Behat\MinkExtension\Context\MinkContext;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FeatureContext extends MinkContext {
public function __construct(ContainerInterface $container) {
$this->container = $container;
}
}
@group infrastructure).partialMock, Mockery, or PestPHP).test_double).bindWhen or replace.// app/Providers/TestDoubleServiceProvider.php
public function register() {
$this->app->when(GithubClient::class)
->needs(GithubClient::class)
->give(function ($app) {
return new FakeGithubClient();
});
}
test_double). Requires unique tag names.How can I help you explore Laravel packages today?