Check Compatibility: Since this bundle is obsolete, verify if your project uses Behat 2.4+ (recommended). If so, replace this bundle with the Symfony2Extension. Run:
composer remove behat/behat-bundle
composer require --dev behat/symfony2-extension
Basic Configuration:
Update app/config/config.yml (or equivalent) to integrate the new extension:
behat:
extensions:
Behat\Symfony2Extension\Extension:
kernel:
environment: 'test'
debug: '%kernel.debug%'
First Use Case: Run a simple feature test:
vendor/bin/behat --config=features/bootstrap/behat.yml
Ensure your behat.yml includes:
default:
extensions:
Behat\Symfony2Extension\Extension:
bootstrap: features/bootstrap/bootstrap.php
Kernel Initialization: Use the extension to bootstrap the Symfony kernel in tests:
// features/bootstrap/bootstrap.php
use Behat\Symfony2Extension\ServiceContainer\ContainerInitializer;
$container = new ContainerInitializer($kernel);
Context Integration:
Extend Behat\Symfony2Extension\Context\KernelAwareContext for kernel-aware contexts:
use Behat\Symfony2Extension\Context\KernelAwareContext;
class FeatureContext extends KernelAwareContext {
protected function getKernel() {
return $this->getSymfonyKernel();
}
}
Service Injection: Access Symfony services in contexts:
$router = $this->getContainer()->get('router');
Environment Management:
Override environments per suite in behat.yml:
suites:
default:
contexts:
- FeatureContext
extensions:
Behat\Symfony2Extension\Extension:
kernel:
environment: 'test'
Behat\MinkExtension alongside for browser/database interactions.doctrine:fixtures:load in bootstrap.php:
$this->getKernel()->boot();
$this->getContainer()->get('doctrine')->getManager()->getConnection()->beginTransaction();
behat:
extensions:
Behat\Symfony2Extension\Extension:
kernel:
debug: true
cache_warmer: false
Deprecated Bundle:
symfony2-extension immediately.Class 'Behat\BehatBundle\BehatBundle' not found → Remove the bundle and install the extension.Kernel Bootstrapping:
$kernel->boot() before accessing services/database will cause:
No connection for service "doctrine.dbal.default_connection"
bootstrap.php includes:
$kernel->boot();
Environment Mismatch:
behat.yml config (e.g., test vs. dev).var_dump($kernel->getEnvironment()) in contexts to verify.Service Container Initialization:
$this->getContainer() before the kernel is booted throws:
Service not found: "service_id"
bootstrap.php after booting the kernel.debug: true in behat.yml to get verbose error messages.dump() or var_dump() in contexts to inspect objects:
use Symfony\Component\VarDumper\VarDumper;
VarDumper::dump($this->getContainer()->getParameter('some_param'));
$connection = $this->getContainer()->get('doctrine')->getManager()->getConnection();
$connection->beginTransaction();
// Test logic
$connection->rollBack();
AuthenticationContext).BeforeScenario/AfterScenario to manage test state:
use Behat\Behat\Hook\Scope\ScenarioScope;
/**
* @BeforeScenario
*/
public function clearDatabase(ScenarioScope $scope) {
$this->getContainer()->get('doctrine')->getManager()->getConnection()->beginTransaction();
}
Behat\MinkExtension for UI testing:
extensions:
Behat\MinkExtension:
base_url: 'http://localhost:8000'
Behat\Symfony2Extension\Extension:
kernel: ~
How can I help you explore Laravel packages today?