polishsymfonycommunity/mockery-bundle
Symfony bundle that integrates Mockery into the dependency injection container. Autowire the Mockery service, build container-aware mocks, and simplify test doubles in unit and functional tests without manual setup or boilerplate.
This is a Symfony bundle, not a Laravel package. There is no service provider, no config/mockery-bundle.php, and no Laravel container integration. If you are a Laravel developer reaching for this because of the "Mockery" in the name, stop here and use Laravel's built-in $this->mock() instead (see below). The bundle exists to let Behat scenarios swap a compiled Symfony DI service for a Mockery mock.
Minimal steps if you are genuinely on Symfony + Behat:
composer require --dev polishsymfonycommunity/mockery-bundle (expect Symfony 2.x/3.x era constraints; check composer.json before assuming it installs at all on a modern app).new PSS\Bundle\MockeryBundle\PSSMockeryBundle() in app/AppKernel.php (legacy) or config/bundles.php (Symfony 4+, if compatible).src/ — specifically the Behat context class and the console command that performs the service swap. Those two files define the entire public surface area.*.feature file, mock an external collaborator (mailer, HTTP client, payment gateway) so a scenario can assert interactions without hitting the real thing, then run bin/behat as usual.If you are on Laravel, the equivalent first step is: use Mockery; is already available via laravel/framework, and a first use case is $this->mock(StripeClient::class, fn ($m) => $m->shouldReceive('charge')->once()) inside a feature or unit test.
Behat + Symfony (the intended path):
@BeforeScenario/@AfterScenario hook that calls Mockery's close() or Mockery::close() and re-registers the container override.shouldReceive(...)->once() style expectations; if you only need a stub, a plain test double is lighter weight.Given the payment gateway will decline.Laravel equivalent (since this package will not work there):
$this->mock(Service::class) in feature tests — it resolves from the container and integrates with the app's lifecycle.$this->swap(Interface::class, $fake) when you need to replace an already-bound singleton before the code under test resolves it.$this->instance() for value objects or config objects that are not mockable.$this->app->bind(...)) for narrow integration tests rather than mocking everything.BeforeScenario hook via $this->app->instance(...) — you will be writing that yourself; this bundle does not help.Integration tips:
Container::get() calls to private services are much harder to override.public: true or a test-only service definition.ServiceProvider, no facade, and no config publishing. Composer may resolve it, but nothing will wire it up. Use $this->mock() / $this->swap() from Illuminate\Foundation\Testing.composer.json for symfony/symfony or symfony/framework-bundle version ranges before planning anything; 15 stars and 0 dependents strongly suggests it has not tracked modern Symfony.$container->set() a service in a booted Symfony app and expect it everywhere — the container may have already inlined the original into consuming services. The bundle's command-based swap exists precisely to work around this; do not bypass it with raw set() calls and expect consistency.Mockery::close() must run after every scenario, or expectation failures silently pile up and the next scenario fails with a confusing message. This is the single most common source of "works alone, fails in suite" bugs.shouldReceive('x')->with(exact args) couples scenarios to implementation. Prefer asserting on outcomes (return values, state) unless the interaction is the requirement.get_class($service)) inside the scenario to confirm the swap took effect; verify Mockery expectations with Mockery::getContainer()->mockery_getExpectationCount().friends-of-behat/service-container-extension or Symfony's KernelTestCase-style override instead — this bundle is the ancestor of those approaches for legacy Symfony 2/3.How can I help you explore Laravel packages today?