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

Symfony Behat Context Bundle Laravel Package

cubicmushroom/symfony-behat-context-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your Symfony project via Composer:

    composer require cubicmushroom/symfony-behat-context-bundle
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        CubicMushroom\SymfonyBehatContextBundle\CubicMushroomSymfonyBehatContextBundle::class => ['all' => true],
    ];
    
  2. First Use Case Enable the bundle’s default context in your Behat behat.yml:

    default:
      suites:
        default:
          contexts:
            - CubicMushroom\SymfonyBehatContextBundle\Context\SymfonyContext
    

    Use it in a feature file:

    Feature: Symfony Context Example
      Scenario: Check Symfony container service
        Given I have a service "router" from the Symfony container
        Then I should see "router" in the container
    

Implementation Patterns

Common Workflows

  1. Service Access Use the I have a service step to fetch Symfony services in tests:

    Given I have a service "security.token_storage" from the Symfony container
    
  2. Request/Response Testing Leverage the I make a request step for HTTP interactions:

    Given I make a request to "/api/users"
    Then the response status code should be 200
    
  3. Event Dispatching Simulate events with I dispatch an event:

    Given I dispatch an event "kernel.request" with data {"_route": "homepage"}
    

Integration Tips

  • Custom Contexts: Extend SymfonyContext to add project-specific steps:

    namespace App\Tests\Context;
    
    use CubicMushroom\SymfonyBehatContextBundle\Context\SymfonyContext;
    
    class CustomSymfonyContext extends SymfonyContext {
        public function someCustomStep() {
            // Logic here
        }
    }
    

    Register it in behat.yml:

    contexts:
      - App\Tests\Context\CustomSymfonyContext
    
  • Dependency Injection: Use the container directly in steps:

    $this->getContainer()->get('service_id');
    

Gotchas and Tips

Pitfalls

  1. Container Initialization Ensure the Symfony kernel is bootstrapped before using the context. Add this to your FeatureContext:

    use Symfony\Component\HttpKernel\KernelInterface;
    
    class FeatureContext implements AfterScenarioInterface {
        public function afterScenario(Scenario $scenario) {
            // Reset container if needed (e.g., for isolated tests)
        }
    }
    
  2. Service Unavailability Steps like I have a service will fail if the service isn’t registered. Verify services exist in config/services.yaml or are tagged correctly.

  3. Event Dispatching Events must match Symfony’s event names exactly (e.g., kernel.request, not kernel.request.event).

Debugging

  • Enable Debug Mode: Set APP_ENV=dev in .env to get detailed error messages.
  • Log Context Steps: Add debug output in custom contexts:
    $this->getContainer()->get('logger')->debug('Step executed');
    

Extension Points

  1. Custom Steps Override or extend existing steps by redefining methods in a child context class.

  2. Configuration Modify bundle behavior via config/packages/cubicmushroom_symfony_behat_context.yaml (if supported in future versions).

  3. Mocking Services Use PHPUnit’s mocking tools to replace real services in tests:

    $this->getContainer()->set('service_id', $this->createMock(ServiceInterface::class));
    
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope