Created
October 17, 2014 14:19
-
-
Save Gisleburt/62ce3507eb792c42dfae to your computer and use it in GitHub Desktop.
Use Laravel's Artisan to set the fixtures for your tests
This file contains 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
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