Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Symfony2 Extension Laravel Package

behat/symfony2-extension

View on GitHub
Deep Wiki
Context7
## Getting Started

### Minimal Setup
1. **Installation**:
   ```bash
   composer require --dev behat/symfony2-extension

(Note: Prefer friends-of-behat/symfony-extension for new projects.)

  1. Configure behat.yml:

    default:
      extensions:
        Behat\Symfony2Extension: ~
      suites:
        default:
          type: symfony_bundle
          bundle: AppBundle
    
  2. First Use Case:

    • Run a basic feature file targeting Symfony routes:
      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"
      
    • Ensure services.yml includes:
      services:
        behat.context.service.container:
          class: Behat\Symfony2Extension\ServiceContainer\ContainerAwareExtension
      

Implementation Patterns

Common Workflows

  1. Context Integration:

    • Extend Behat\Symfony2Extension\Context\KernelDictionary for kernel-aware steps:
      use Behat\Symfony2Extension\Context\KernelDictionary;
      
      class FeatureContext extends KernelDictionary {
          protected function getKernel() {
              return static::$kernel;
          }
      }
      
  2. Route-Based Navigation:

    • Use I am on "<route_name>" or I am on "/path" with route resolution.
  3. Service Injection:

    • Access Symfony services in contexts via $this->getService('service_id').
  4. Database Testing:

    • Reset the database between scenarios:
      extensions:
        Behat\Symfony2Extension: ~
        Behat\MinkExtension:
          base_url: http://localhost:8000
      
  5. Event Dispatching:

    • Trigger Symfony events in steps:
      $this->get('event_dispatcher')->dispatch('kernel.request', new GetResponseEvent($request, $this->getKernel()));
      

Integration Tips

  • Leverage Mink: Combine with behat/mink for browser/HTTP testing.
  • Environment Awareness: Use APP_ENV=test in .env.behat for isolated testing.
  • Custom Contexts: Create bundle-specific contexts (e.g., AppBundleContext) for domain logic.

Gotchas and Tips

Pitfalls

  1. Archived Status:

    • Avoid new projects; use friends-of-behat/symfony-extension instead.
    • The fork (PHPExpertsInc/SymfonyExtension) may introduce compatibility risks.
  2. Kernel Initialization:

    • Ensure static::$kernel is set in contexts. Override getKernel() if needed:
      protected function getKernel() {
          return static::$kernel ?: $this->getService('kernel');
      }
      
  3. Route Resolution:

    • Routes must exist in the test environment. Use php bin/console debug:router to verify.
  4. Service Container:

    • Services must be tagged as public or explicitly defined in services.yml for injection.
  5. Database Transactions:

    • Enable Doctrine transactions in behat.yml:
      Behat\Symfony2Extension:
          transactional: true
      

Debugging

  • Enable Debug Mode:
    Behat\Symfony2Extension:
       debug: true
    
  • Check Kernel Boot:
    • Add dump(static::$kernel) in contexts to verify kernel availability.
  • Mink Driver Issues:
    • Ensure mink and mink-browserkit-driver are installed for HTTP tests.

Extension Points

  1. Custom Step Definitions:

    • Override loadKernel() in contexts for custom kernel setup:
      protected function loadKernel() {
          static::$kernel = static::bootKernel(['env' => 'test']);
      }
      
  2. Event Listeners:

    • Attach to Symfony events (e.g., kernel.request) via EventDispatcher:
      $dispatcher = $this->get('event_dispatcher');
      $dispatcher->addListener('kernel.request', function() { /* ... */ });
      
  3. Configuration Overrides:

    • Extend Behat\Symfony2Extension\Configuration\Configuration for custom settings.

Performance

  • Disable Transactions for CI:
    Behat\Symfony2Extension:
       transactional: false  # For faster runs (but risk dirty state)
    
  • Cache Contexts:
    • Use @BeforeScenario to cache heavy services (e.g., Doctrine EM).

Migration Path

  • To friends-of-behat/symfony-extension:
    1. Replace Behat\Symfony2Extension with FriendsOfBehat\SymfonyExtension.
    2. Update contexts to extend FriendsOfBehat\SymfonyExtension\Context\MinkContext or similar.
    3. Reconfigure behat.yml for the new extension’s syntax.

*(Note: Replace `AppBundle` with your actual bundle name and adjust paths/services as needed.)*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui