DBにクエリを更新するメソッドがあります。要求がユーザーインターフェイスから送信された場合はすべて正常ですが、単体テストからの要求が次にデータベースのレコードが更新されない場合。ユニットテストでDBが更新されないのはなぜですか?
mthod内部の更新クエリは、この
$game_periods_table = DB::table('game_periods')->where('id', $id);
$current_update_array = [];
if(array_key_exists('A', $count_throws)){
$current_update_array['count_throws_a'] = $count_throws['A'];
}
if(array_key_exists('B', $count_throws)){
$current_update_array['count_throws_b'] = $count_throws['B'];
}
$current_update_array['updated_at'] = date('Y-m-d H:i:s');
$game_periods_table->update($current_update_array);
のように見え、私のユニットテストは
protected $bgame;
protected $game_id = 95;
public function setUp(){
parent::setUp();
$game = new Game();
$game = $game::find($this->game_id);
if(is_null($game)){
$this->fail('Game is not found!');
}
$this->bgame = new BGame($game);
}
public function testUpdateThrows(){
$test_array = [
'first_period_throws' => ['A' => 1, 'B' => 2],
'second_period_throws' => ['A' => 3, 'B' => 4],
'third_period_throws' => ['A' => 5, 'B' => 6],
'ot_period_throws' => ['A' => 7, 'B' => 8],
];
$this->assertTrue($this->bgame->updateThrows($test_array));
}`
テスト結果がOKであるように見えますが、なぜ私の記録はdoesnの `tの更新はありますか?
ユニットテストでは、私はtest dbを使用しますが、それはまさにmain dbと同じです。
あなたは 'DatabaseMigrations'を使用しています?そうすると、テストごとにテストDBがクリアされ、データは保持されません。 'DatabaseTransactions'と同じですが、テスト完了後にレコードをリセットします。 – Sandeesh