PHPackages                             soulcodex/laravel-behat - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. soulcodex/laravel-behat

ActiveBehat-extension[Testing &amp; Quality](/categories/testing)

soulcodex/laravel-behat
=======================

Laravel Extension for easy integration with Behat

1.0.7(1y ago)1765.7k↓55.8%4[1 issues](https://github.com/soulcodex/laravel-behat/issues)MITPHPPHP ^8.0

Since Feb 6Pushed 1y ago4 watchersCompare

[ Source](https://github.com/soulcodex/laravel-behat)[ Packagist](https://packagist.org/packages/soulcodex/laravel-behat)[ Docs](https://github.com/soulcodex/laravel-behat)[ RSS](/packages/soulcodex-laravel-behat/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (4)Dependencies (9)Versions (11)Used By (0)

   [![Project icon](./doc/behat.png)](./doc/behat.png) [![Project icon](./doc/laravel.png)](./doc/laravel.png)Laravel Behat Extension
=======================

[](#laravel-behat-extension)

A powerfully extension to integrate laravel with behat from scratch and start writing great feature histories.

Getting started
===============

[](#getting-started)

1. Install Dependencies
-----------------------

[](#1-install-dependencies)

As always, we need to pull in some dependencies through Composer.

```
composer require behat/behat behat/mink friends-of-behat/mink-extension soulcodex/laravel-behat --dev
```

This will give us access to Behat, Mink, and, of course, the Laravel extension.

2. Create the Behat.yml Configuration File
------------------------------------------

[](#2-create-the-behatyml-configuration-file)

Next, within your project root, create a `behat.yml` file, and add:

```
default:
    extensions:
        Soulcodex\Behat:
            kernel: # Default values
                bootstrap_path: '/bootstrap/app.php'
                environment_path: '.env.behat'
        Behat\MinkExtension: # Default mink extension configuration
            default_session: laravel
            laravel: ~

    # Your test suites here
    suites:
        user:
            paths: [ '%paths.base%/path/to/your/features/tests/files' ]
            # The context needed by your features tests
            contexts: ~
```

Here, is where we reference the Laravel extension, and tell Behat to use it as our default session. You may pass an optional parameter, `env_path` (currently commented out above) to specify the name of the environment file that should be referenced from your tests. By default, it'll look for a `.env.behat` file.

This file should, like the standard `.env` file in your project root, contain any special environment variables for your tests (such as a special acceptance test-specific database).

3. Setting up a new context
---------------------------

[](#3-setting-up-a-new-context)

Create a new one context in the directory specified in the `paths` configuration property **using**[the base context](src/Addon/Context.php) and register the [RootContext class](src/Addon/RootContext.php) like this:

*behat.yaml*

```
suites:
    user:
        paths: [ '%paths.base%/app/User/Test/Feature/' ]
        # The context needed by your features tests
        contexts:
            -   Soulcodex\Behat\Addon\RootContext: ~
            -   App\User\Test\Feature\UserContext:
                    userRepository: '@App\User\Infrastructure\Persistence\Eloquent\EloquentMySqlUserRepository'
```

*app/User/Test/Feature/UserContext.php*

```
