Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Gisleburt
Created October 17, 2014 14:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gisleburt/62ce3507eb792c42dfae to your computer and use it in GitHub Desktop.
Save Gisleburt/62ce3507eb792c42dfae to your computer and use it in GitHub Desktop.
Use Laravel's Artisan to set the fixtures for your tests
class AbstractBehatContext extends MinkContext {
/**
* Slight hack to put beforeSuite code into beforeScenario
* @var bool
*/
protected static $databaseReady = false;
/**
* @BeforeScenario
*/
public function setupDatabase() {
// Check if we already did this
if(!self::$databaseReady) {
// Find the host
$baseUrl = $this->getMinkParameter('base_url');
$urlParts = parse_url($baseUrl);
$_SERVER['HTTP_HOST'] = $urlParts['host'];
// Now call start.php
require_once 'bootstrap/start.php';
// Call Artisan
Artisan::call(
'migrate:refresh',
[
'--seed' => true,
]
);
// Flag this as done
self::$databaseReady = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment