Skip to content

Instantly share code, notes, and snippets.

@mass6
Created October 12, 2015 13:30
Show Gist options
  • Save mass6/e64d94e360dee760298d to your computer and use it in GitHub Desktop.
Save mass6/e64d94e360dee760298d to your computer and use it in GitHub Desktop.
Laravel 5.1 Trait for working with Behat
<?php
use Illuminate\Foundation\Testing\ApplicationTrait;
use Illuminate\Foundation\Testing\AssertionsTrait;
use Illuminate\Foundation\Testing\CrawlerTrait;
use Illuminate\Support\Facades\Artisan;
trait LaravelTrait
{
/**
* Responsible for providing a Laravel app instance.
*/
use ApplicationTrait, AssertionsTrait, CrawlerTrait, PhpUnitAssertionsTrait;
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
protected $phpUnit;
/**
* @BeforeScenario
*/
public function setUp()
{
if ( ! $this->app) {
$this->refreshApplication();
}
// set the database connection to use for testing
$this->app->config->set('database.default', 'sqlite');
}
/**
* @BeforeScenario
*/
public function setupDatabase()
{
$this->artisan('migrate');
}
/**
* @AfterScenario
*/
public function cleanDatabase()
{
$this->artisan('migrate:reset');
}
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__ . '/../../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment