PHPackages                             cevinio/behat-laravel-extension - 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. cevinio/behat-laravel-extension

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

cevinio/behat-laravel-extension
===============================

Laravel extension for Behat

4.0.0(2y ago)475.3k↓20.3%1MITPHPPHP &gt;=8.1

Since Feb 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Cevinio/Behat-Laravel-Extension)[ Packagist](https://packagist.org/packages/cevinio/behat-laravel-extension)[ RSS](/packages/cevinio-behat-laravel-extension/feed)WikiDiscussions main Synced 1mo ago

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

This extension offers an incredibly simple (and fast) way to begin testing and driving your Laravel applications with Behat. Some benefits include:

- **Fast:** It doesn't depend on anything like Goutte, so it offers a super-fast way to test your UI. You don't even need to setup a host to run your tests.
- **Refresh:** Laravel is automatically rebooted before each scenario (so nothing like user sessions will be persisted).
- **Environments:** Specifying custom environment files (like the `.env` one) for different app environments is a little tricky in Laravel. This extension handles that for you automatically.
- **Access Laravel:** You instantly have access to Laravel (things like facades and such) from your `FeatureContext` file.

> This repository is forked from [laracasts/Behat-Laravel-Extension](https://github.com/laracasts/Behat-Laravel-Extension) because it was no longer being maintained.
> Credits go to [Jeffrey Way](https://github.com/JeffreyWay) for originally creating this extension.

1. Install
==========

[](#1-install)

Require the package as a dev dependency via Composer.

```
composer require --dev cevinio/behat-laravel-extension

```

This will also pull in Behat and Mink.

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:
        Cevinio\Behat:
            # bootstrap_path: ~
            # env_path: ~
        Behat\MinkExtension:
            default_session: laravel
            laravel: ~
            files_path: "%paths.base%/tests/"

```

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. The default is empty and will keep Laravel standard behavior to look for `.env`. If you want a special environment file you can set it for example to `.env.behat`. 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).

It is also possible to specify an alternative bootstrap file by setting the optional parameter `bootstrap_path` (this defaults to `bootstrap/app.php`). Behat's `%paths.base%` will always be prepended to this path.

3. Setting up FeatureContext
============================

[](#3-setting-up-featurecontext)

Run, from the root of your app

```
vendor/bin/behat --init

```

It should set

```
features/bootstrap/FeatureContext.php

```

At this point you should set it to extend `MinkContext` and implement `LaravelAwareContext`. You can use the `LaravelAware` trait to get access to the `Application` via `$this->app()`.

```
