2

単体テスト中にLaravelでいくつかのファサードをモックしようとしていますが、テストは常に成功しているようです。

たとえば、次の例は Laravel のドキュメントから抜粋したものです。

Event::shouldReceive('fire')->once()->with('foo', array('name' => 'Dayle'));

Eventそれを任意のテストメソッドに入れることができるようで、ファサードで何も行われていない場合でも、常に合格します。

テストクラスは次のとおりです。

class SessionsControllerTest
extends TestCase
{    
    public function test_invalid_login_returns_to_login_page()
    {
        // All of these pass even when they should fail
        Notification::shouldReceive('error')->once()->with('Incorrect email or password.');
        Event::shouldReceive('fire')->once()->with('foo', array('name' => 'Dayle'));
        Notification::shouldReceive('nonsense')->once()->with('nonsense');

        // Make login attempt with bad credentials
        $this->post(action('SessionsController@postLogin'), [
            'inputEmail'     => 'bademail@example.com',
            'inputPassword'  => 'badpassword'
        ]);

        // Should redirect back to login form with old input
        $this->assertHasOldInput();
        $this->assertRedirectedToAction('SessionsController@getLogin');
    }

}

Facades をテストするために不足しているものは何ですか? shouldReceive()セットアップなしで Laravel Facadeを呼び出すことができるはずだと考えているのは正しいですか?

4

1 に答える 1