PHPackages                             heybigname/phpspec-laravel - 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. heybigname/phpspec-laravel

ActiveLibrary[Testing &amp; Quality](/categories/testing)

heybigname/phpspec-laravel
==========================

Test your Laravel applications with PhpSpec

v4.0(8y ago)34.0k2[1 PRs](https://github.com/heybigname/phpspec-laravel/pulls)2MITPHPPHP ^7.1

Since Mar 24Pushed 5y ago2 watchersCompare

[ Source](https://github.com/heybigname/phpspec-laravel)[ Packagist](https://packagist.org/packages/heybigname/phpspec-laravel)[ Docs](http://github.com/heybigname/phpspec-laravel)[ RSS](/packages/heybigname-phpspec-laravel/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (17)Used By (2)

phpspec Laravel Extension
=========================

[](#phpspec-laravel-extension)

This extension is from Ben Constable but I forked it because it was no longer maintained.

> [phpspec](http://www.phpspec.net/) extension for testing [Laravel](http://laravel.com/)applications.

Versions
--------

[](#versions)

Depending on the version of Laravel and/or Phpspec you're using, you'll want to make sure that you're using the version of this package that's right for you. Use the table below to pick the right one.

Package VersionLaravel VersionPhpspec Version`^v1.2``^v4.1``^v2.0``^v2.0``v5.0-v5.3``^v2.1``^v3.0``^v5.1``^v3.0``^v4.0``^v5.6``^v4.3.0``^v5.0``v5.7.*``~v5.1.0`Installation
------------

[](#installation)

Install the package with composer:

```
composer require --dev "heybigname/phpspec-laravel"

```

then add this to your `phpspec.yml`:

```
extensions:
  PhpSpec\Laravel\Extension\LaravelExtension: ~
```

You can take a look at [`example.phpspec.yml`](https://github.com/heybigname/phpspec-laravel/blob/master/example.phpspec.yml)for a good set of sensible phpspec defaults for a Laravel project.

Why this extension?
-------------------

[](#why-this-extension)

This extension provides you with a bootstrapped Laravel environment when writing your phpspec tests.

It allows you to make use of some of the nice features that Laravel provides, like class aliases and helper functions, without being hindered by your testing framework.

This extension **is not** a swap-in replacement for Laravel's built in PHPUnit setup. If you'd like integration and/or functional tests, please use that, [Behat](http://behat.org/), or [Codeception](http://codeception.com/).

Configuration
-------------

[](#configuration)

### Testing environment

[](#testing-environment)

By default, the extension bootstraps Laravel in the `testing` environment. You can change this to production (or whatever you like) by setting:

```
extensions:
  PhpSpec\Laravel\Extension\LaravelExtension:
    testing_environment: "production"
```

in your `phpspec.yml`.

### App bootstrap path

[](#app-bootstrap-path)

By default, the extension will bootstrap your app by looking for `bootstrap/app.php`in the directory above `vendor/`. This is the default location that Laravel provides.

You can manually specify the path to the bootstrap file if you're using a non-standard installation, like so:

```
extensions:
  PhpSpec\Laravel\Extension\LaravelExtension:
    framework_path: "/non/standard/laravel/setup/app.php"
```

You can specify either an absolute path (use leading slash), or a path relative to the `vendor/` directory.

Usage
-----

[](#usage)

### Testing without Laravel

[](#testing-without-laravel)

If you're not using any code specific to the Laravel environment, then you don't need to do anything differently. Just write your phpspec tests as normal!

### Testing with Laravel

[](#testing-with-laravel)

If you want to take advantage of Laravel's aliases, or use some of its [helper functions](https://laravel.com/docs/5.4/helpers), extend your specs from `PhpSpec\Laravel\LaravelObjectBehavior`. This will prevent errors when testing.

**For example, this class uses an alias:**

```
