2016-06-16 8 views
6

アカウントを確認するシステムを持つアプリケーションがあります(登録 - >有効にするためのリンク付き電子メールを取得 - >アカウント確認済み)。その検証フローはオプションで、設定値をオフにすることができます。Laravel unit tests - テスト方法に応じて設定値を変更する

// config/auth.php 
return [ 
    // ... 
    'enable_verification' => true 
]; 

は私が登録コントローラをテストしたい:

  • が、それは両方のケースでホームページにリダイレクトする必要が
  • 検証がオンの場合、ホームページに「メール送信済み」メッセージが表示されます。
  • 確認がオフの場合、ホームページに「アカウント作成済み」メッセージが表示されます。
  • など

私の試験方法:デバッグは、私が気づい

public function test_UserProperlyCreated_WithVerificationDisabled() 
{ 
    $this->app['config']->set('auth.verification.enabled', false); 

    $this 
     ->visit(route('frontend.auth.register.form')) 
     ->type('Test', 'name') 
     ->type('[email protected]', 'email') 
     ->type('123123', 'password') 
     ->type('123123', 'password_confirmation') 
     ->press('Register'); 

    $this 
     ->seePageIs('/') 
     ->see(trans('auth.registration.complete')); 
} 

public function test_UserProperlyCreated_WithVerificationEnabled() 
{ 
    $this->app['config']->set('auth.verification.enabled', true); 

    $this 
     ->visit(route('frontend.auth.register.form')) 
     ->type('Test', 'name') 
     ->type('[email protected]', 'email') 
     ->type('123123', 'password') 
     ->type('123123', 'password_confirmation') 
     ->press('Register'); 

    $this 
     ->seePageIs('/') 
     ->see(trans('auth.registration.needs_verification')); 
} 

そのコントローラのメソッド内で、常に関係なく、私は私の$this->app['config']->set...で設定したもの、configファイル内の値に設定されていない設定値

ユーザのリポジトリ自体について、検証が有効または無効の両方で動作することを確認するためのテストがあります。そしてテストは期待通りに動作します。

なぜコントローラで失敗するのか、それを修正する方法はありますか?私はあなたの質問の権利を理解していれば

答えて

3

- あなたは、あなたが使用することができ、「どのように設定のparamを設定する」を探してConfig::set($key, $value)

関連する問題