私は多くのことを試しましたが、私はこの問題に固執しています。 私は自分のアプリケーションでテストしようとしています(Laravel5.3を使って作業しています)。 私のDB for developementはMysqlですが、私はsqliteの "メモリ"データベースでテストしたいです。Laravel PhpUnitこのようなテーブルはありません
私はこのエラーを持っているテストを起動しようとするたび: 一般的なエラー:1いいえ、そのような表:groupe_userは
ITSはSQLiteのデータベース内のテーブルを移行しないように見えます。 私は何が間違っているのか分かりません。
ここに私のtestCaseファイルとマイグレーションがあります。もし誰かが私を助けてくれれば素晴らしいでしょう。
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();
}
}
そして、そのピボットテーブルでの移行ファイル:
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');
}
}視聴に
感謝。
EDIT:あなたは、データベースのトランザクションをテストする場合Traits in your testcaseを使用する必要が私の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');
}
あなたは '使用DatabaseMigrationsを追加していることを確認してください;'あなたのテストに –
https://laravel.com/docs/5.3/database-testingドキュメントごとに、私はちょうどショーの初めのための私の投稿を編集つもり私のファイルの一つ。 – Exarkun