I'm having trouble loading the correct ENV file for Laravel 5.1 integration testing.
I found when I create a user/rollback DB, etc... It is acting on my app local database, and not my test database.
I am setting the env
on ApplicationCreation with $app->loadEnvironmentFrom('.env.testing');
, and it seems to be properly setting:
die('environment ' . $app->environment());
Outputs "testing".
So I'm not sure why it's running my test suite CRUD operations on my local DB, and not the testing environment.
TestCase.php:
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
protected $baseUrl = 'http://ift.tt/1Ml506V';
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
$app->loadEnvironmentFrom('.env.testing');
die('environment ' . $app->environment()); //"testing"
return $app;
}
...
.env.testing:
APP_ENV=testing
APP_DEBUG=true
APP_KEY=my_key
DB_HOST=localhost
DB_DATABASE=testbench
DB_USERNAME=root
DB_PASSWORD=''
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
UserTest:
class UserTest extends TestCase
{
public function setUp()
{
parent::setUp();
Artisan::call('migrate:reset');
Artisan::call('migrate');
Artisan::call('db:seed');
}
... test functions here
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire