Created
October 12, 2015 13:30
-
-
Save mass6/e64d94e360dee760298d to your computer and use it in GitHub Desktop.
Laravel 5.1 Trait for working with Behat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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