Laravel test, no such table, sqlite

I am running Laravel on OS X using MAMP and I am trying to run some unit tests using PHPUnit and sqlite, however when I run my tests I get an error

General error: 1 there is no such table: users

I tried running the wizard to manually migrate the database using the --env = check, which works fine, however, I still get the error. I even call Artisan::call('migrate');SetUp in the method.

/app/config/testing/database.php

return [
    'default' => 'sqlite',

    'connections' => [
        'sqlite' => [
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => ''
        ],
    ]
];

EDIT: Migration file:

Schema::create('users', function($table) {
    $table->increments('id');
    $table->string('email', 32)->unique();
    $table->string('password', 64);
    $table->string('username', 32)->unique();
    $table->dateTime('birthdate');
    $table->enum('status', array('ACTIVE', 'INACTIVE'));
    $table->timestamps();
});

Schema::create('roles', function($table) {
    $table->increments('id');
    $table->string('name', 32);
});

Schema::create('role_user', function ($table) {
    $table->increments('id');

    $table->unsignedInteger('user_id');
    $table->unsignedInteger('role_id');

    $table->foreign('user_id')->references('id')->on('users');
    $table->foreign('role_id')->references('id')->on('roles');

});
+4
source share
2 answers

SQLite does not support type ENUM: http://www.sqlite.org/datatype3.html

. MySQL ENUM.

+6

, , , , , , , .

, , , TestCase - :

<?php

class TestCase extends Illuminate\Foundation\Testing\TestCase {

  public function createApplication()
  {
      $unitTesting = true;
      $testEnvironment = 'testing';
      return require __DIR__.'/../../bootstrap/start.php';
  }

  public function setUp()
  {
      parent::setUp();
      $this->prepareForTests();
  }
  private function prepareForTests()
  {
      Artisan::call('migrate');
      Artisan::call('db:seed');
  }
  public function tearDown()
  {
      parent::tearDown();
  }
}
+1

Source: https://habr.com/ru/post/1528032/


All Articles