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.
Laravel\Behat or custom Behat\Mink drivers).behat.yml in tests/Features/).TestContext in behat.yml or behat.php.laravel/browsing-testing or laravel/pint).TestContext to mock Laravel-specific services (e.g., App\Services\AuthService) in nested Behat runs."Then the response should be JSON").Then it should fail with "text" may misfire if Laravel’s error output (e.g., stack traces) includes dynamic data (e.g., UUIDs, timestamps).Str::of().vendor/ and node_modules/ in CI; use behat --no-interaction for faster runs.Laravel\Behat\ServiceContainer\LaravelExtension) may require mocking Laravel’s service container in nested Behat runs.TestContext's file setup to inject Laravel’s services.php or aliases.php into the nested config.behat.yml vs. behat.php.)actingAs(), assertDatabaseHas()) replace some Behat extension tests?"Given I am logged in as a user").Laravel\Behat\ServiceContainer\LaravelExtension loads correctly).| Component | Laravel Version | Behat Version | PHP Version | Notes |
|---|---|---|---|---|
friends-of-behat/test-context |
8.x–11.x | 3.x–4.x | 8.1+ | Full support |
| Laravel Behat Ext. | 8.x–11.x | 3.x | 8.0+ | May need mocking for nested runs |
| Mink Drivers | N/A | 3.x | 8.1+ | Test with laravel/browsing-testing |
tests/Features/Extensions/ directory.Feature: Laravel Auth Extension
Scenario: Login step works
Given a feature file with passing scenario
And a context file "bootstrap/AuthContext.php" containing:
"""
<?php
use Laravel\Behat\Context\AuthContext;
class AuthContext extends \Behat\Behat\Context\Context {}
"""
When I run Behat
Then it should pass
TestContext for extension-specific logic.App\Providers\AuthServiceProvider via Given a file).vendor/ and node_modules/ for nested Behat runs.--tags or Laravel’s parallel-tests package."Then the session contains 'laravel_session'").TestContext to inject Laravel’s services.php into nested configs:
Given a file "config/services.php" containing:
"""
<?php return [
'auth' => App\Services\AuthService::class,
];
"""
.env.testing via Given a file or use Laravel’s putenv() in a custom step.DatabaseMigrations or DatabaseTransactions in the outer test suite.TestContext alongside laravel/horizon or laravel/fortify (may conflict with nested Behat processes).--no-interaction and mock queues/auth in nested runs.behat.yml configured for Laravel extensions).behat.yml includes).[Laravel Core] → [Behat 3.x] → [friends-of-behat/test-context] → [Custom Extensions]
"Given a failing scenario")."Behat called from Behat").Auth::routes() → use Laravel\Fortify).Then it should end with "text" to debug output.How can I help you explore Laravel packages today?