Ok, I seem to have gotten a solution! This is my LaravelFeatureContext now:
/**
* Defines application features from the specific context.
*/
class LaravelFeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
/**
* @static
* @beforeSuite
*/
public static function bootstrapLaravel()
{
// Override environment when booting Laravel
Dotenv::setEnvironmentVariable('APP_ENV', 'functional');
require_once __DIR__.'/../../bootstrap/start.php';
Mail::pretend(true);
// Refresh database for the functional environment
Artisan::call('migrate:refresh', array('--env' => 'functional'));
Artisan::call('db:seed', array('--env' => 'functional'));
}
}
This will use the Dotenv override method. However I still need to manually set the environment when doing the migrate:refresh and db:seed because otherwise the default environment gets fired.
Further more I've set up Homestead to create a .test URL as well by modifying the serve.sh:
block="server {
listen 80;
server_name $1 ${1/.dev/.test};
root $2;
[...]
}
And I've updated the environment detection for Laravel like so:
$env = $app->detectEnvironment(function()
{
// Detect functional testing env
if(isset($_SERVER['HTTP_HOST']) && ends_with($_SERVER['HTTP_HOST'], '.test'))
{
return 'functional';
}
return getenv('APP_ENV') ?: 'production';
});