I had try lot of things but i am stuck on this problem. I try to make test on my application (working with Laravel5.3). My DB for developement is Mysql , but i want test with the sqlite"memory" database.
Each time i try to launch a test i have this error: General error: 1 no such table: groupe_user
Its seem to don't migrate tables in the sqlite database. I don't see what i am doing wrong.
I put here my testCase file and the migrations if someone can help me , it would be great.
The TestCase.php :
<?php
abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$unitTesting = true;
$testEnvironment = 'testing';
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
public function setUp()
{
parent::setUp();
$this->createApplication();
$this->prepareForTests();
}
private function prepareForTests()
{
Artisan::call('migrate');
Artisan::call('db:seed');
}
public function tearDown()
{
parent::tearDown();
}
}
And the migration file with that pivot Table :
class CreateGroupesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('groupes', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 100);
$table->timestamps();
});
//Création de la table pivot groupe_user avec les cléfs étrangères
Schema::create('groupe_user', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned()->index()->nullable();
$table->integer('groupe_id')->unsigned()->index()->nullable();
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('groupe_id')->references('id')->on('groupes');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('groupes');
}
}
Thanks for watching.
EDIT: The begining of my AuthTest.php
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\User;
class AuthTest extends TestCase
{
use DatabaseMigrations;
public function testAuthLogin()
{
$user = factory(App\User::class)->create();
//Test du login
$this->visit('/login')
->see('Se Connecter')
->type('[email protected]', 'email')
->type('lorem85', 'password')
->press('Se connecter');
}
use DatabaseMigrations;
to your tests as per the docs laravel.com/docs/5.3/database-testing