2017-05-15 4 views
0

私は多くのことを試しましたが、私はこの問題に固執しています。 私は自分のアプリケーションでテストしようとしています(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'); 
} 
+0

あなたは '使用DatabaseMigrationsを追加していることを確認してください;'あなたのテストに –

+0

https://laravel.com/docs/5.3/database-testingドキュメントごとに、私はちょうどショーの初めのための私の投稿を編集つもり私のファイルの一つ。 – Exarkun

答えて

0

の 初め。

use Illuminate\Foundation\Testing\DatabaseMigrations; 
use Illuminate\Foundation\Testing\DatabaseTransactions; 
+0

私はUserTest.php、ExampleTestなどの各ファイルで特性を使用します – Exarkun

0

phpunit.xmlファイルにsqliteデータベース情報をセットアップしましたか?

<php> 
    <env name="APP_ENV" value="testing"/> 
    <env name="CACHE_DRIVER" value="array"/> 
    <env name="SESSION_DRIVER" value="array"/> 
    <env name="QUEUE_DRIVER" value="sync"/> 
    <env name="DB_CONNECTION" value="sqlite"/> 
    <env name="DB_DATABASE" value=":memory:"/> 
</php> 
+0

はい私のphpunit.xmlにはこの設定があります – Exarkun

+0

テストを実行すると、失敗した場合、職人の呼び出しでエラーがスローされません。テストの前に移行とシードが成功したかどうかを確認してください。 – Sandeesh

関連する問題