## Getting Started
### Minimal Setup
1. **Installation**:
```bash
composer require --dev behat/symfony2-extension
(Note: Prefer friends-of-behat/symfony-extension for new projects.)
Configure behat.yml:
default:
extensions:
Behat\Symfony2Extension: ~
suites:
default:
type: symfony_bundle
bundle: AppBundle
First Use Case:
Feature: Login
Scenario: Successful login
Given I am on "/login"
When I fill in "username" with "admin"
And I fill in "password" with "secret"
And I press "Sign in"
Then I should see "Welcome, admin"
services.yml includes:
services:
behat.context.service.container:
class: Behat\Symfony2Extension\ServiceContainer\ContainerAwareExtension
Context Integration:
Behat\Symfony2Extension\Context\KernelDictionary for kernel-aware steps:
use Behat\Symfony2Extension\Context\KernelDictionary;
class FeatureContext extends KernelDictionary {
protected function getKernel() {
return static::$kernel;
}
}
Route-Based Navigation:
I am on "<route_name>" or I am on "/path" with route resolution.Service Injection:
$this->getService('service_id').Database Testing:
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://localhost:8000
Event Dispatching:
$this->get('event_dispatcher')->dispatch('kernel.request', new GetResponseEvent($request, $this->getKernel()));
behat/mink for browser/HTTP testing.APP_ENV=test in .env.behat for isolated testing.AppBundleContext) for domain logic.Archived Status:
friends-of-behat/symfony-extension instead.PHPExpertsInc/SymfonyExtension) may introduce compatibility risks.Kernel Initialization:
static::$kernel is set in contexts. Override getKernel() if needed:
protected function getKernel() {
return static::$kernel ?: $this->getService('kernel');
}
Route Resolution:
php bin/console debug:router to verify.Service Container:
services.yml for injection.Database Transactions:
behat.yml:
Behat\Symfony2Extension:
transactional: true
Behat\Symfony2Extension:
debug: true
dump(static::$kernel) in contexts to verify kernel availability.mink and mink-browserkit-driver are installed for HTTP tests.Custom Step Definitions:
loadKernel() in contexts for custom kernel setup:
protected function loadKernel() {
static::$kernel = static::bootKernel(['env' => 'test']);
}
Event Listeners:
kernel.request) via EventDispatcher:
$dispatcher = $this->get('event_dispatcher');
$dispatcher->addListener('kernel.request', function() { /* ... */ });
Configuration Overrides:
Behat\Symfony2Extension\Configuration\Configuration for custom settings.Behat\Symfony2Extension:
transactional: false # For faster runs (but risk dirty state)
@BeforeScenario to cache heavy services (e.g., Doctrine EM).friends-of-behat/symfony-extension:
Behat\Symfony2Extension with FriendsOfBehat\SymfonyExtension.FriendsOfBehat\SymfonyExtension\Context\MinkContext or similar.behat.yml for the new extension’s syntax.
*(Note: Replace `AppBundle` with your actual bundle name and adjust paths/services as needed.)*
How can I help you explore Laravel packages today?