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
Test Context

Test Context Laravel Package

friends-of-behat/test-context

Reusable Behat context for testing Behat extensions by running “Behat inside Behat”. Creates isolated temp projects per scenario, writes configs/features/contexts, runs a real Behat process, and lets you assert on exit codes and output.

View on GitHub
Deep Wiki
Context7

:mortar_board: Provides reusable context that helps in testing Behat extensions.

Frequently asked questions about Test Context
How do I install friends-of-behat/test-context for Laravel Behat testing?
Run `composer require friends-of-behat/test-context --dev` in your Laravel project. No Laravel-specific setup is needed—just register the `TestContext` in your `behat.yml` or `behat.php` configuration file.
Does this package work with Laravel’s built-in Behat extensions like Laravel\Behat?
Yes, it fully supports Laravel Behat extensions. The package’s isolated temporary directories allow you to test extensions like `Laravel\Behat` in nested Behat runs, though you may need to mock Laravel-specific services for full functionality.
Can I use this to test Laravel-specific Behat step definitions (e.g., auth or API steps)?
Absolutely. The package lets you define custom step definitions in nested Behat runs, including Laravel-specific assertions. For example, you can test steps like ‘Given I am logged in as a user’ by injecting Laravel’s auth logic into the temporary config.
Will this slow down my Laravel CI pipeline if I have many Behat tests?
Yes, spawning Behat processes per scenario adds ~50–200ms per test. Mitigate this by caching `vendor/` and `node_modules/` in CI, using `behat --no-interaction`, or running tests in parallel if your CI supports it.
How do I handle Laravel’s dynamic data (e.g., UUIDs, timestamps) in Behat assertions?
Use regex patterns in your assertions (e.g., `Then it should fail with /error.*[a-f0-9]{8}/`) or preprocess output with Laravel’s `Str::of()` helper to normalize dynamic values before matching them in assertions.
Does friends-of-behat/test-context support Behat 4.x, or only 3.x?
The package supports both Behat 3.x and 4.x, but the configuration syntax differs (e.g., `behat.yml` for 3.x vs. `behat.php` for 4.x). Laravel projects typically use Behat 3.x, so ensure your `behat.yml` is properly configured.
Can I mock Laravel’s service container (e.g., for testing auth or database steps) in nested Behat runs?
Yes, leverage the package’s file setup to inject Laravel’s `services.php` or `aliases.php` into the nested Behat configuration. This allows you to mock services like `AuthService` or database connections in isolated test environments.
Is there a performance difference between testing simple extensions vs. complex Laravel-coupled ones?
Complex extensions (e.g., those requiring database queries or auth) may need additional setup (like mocking services), which adds minor overhead. However, the package’s isolation ensures clean environments, so performance impact remains consistent regardless of extension complexity.
What alternatives exist for testing Behat extensions in Laravel without this package?
You could use Laravel’s native testing helpers (e.g., `actingAs()`, `assertDatabaseHas()`) for simple assertions, but they don’t provide the full Behat environment isolation. Other alternatives include writing custom PHPUnit tests or using Docker containers for Behat runs, though these lack the convenience of nested Behat execution.
How do I test Laravel-specific Behat configurations (e.g., behat.yml with Laravel extensions) with this package?
Define your Laravel-specific `behat.yml` or `behat.php` in the temporary directory per scenario. The package allows you to write configurations dynamically, so you can include Laravel extensions like `Laravel\Behat\ServiceContainer\LaravelExtension` and validate their setup.
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle