4

FlashBag メッセージをどのようにテストしますか?

これを試しました:

public function testInvalidLogin()
{
    $session = $this->client->getContainer()->get('session');
    $crawler = $this->client->request('GET', '/login');

    $this->assertTrue($this->client->getResponse()->isSuccessful());
    $form = $crawler->filter('form');
    $this->assertGreaterThan(0, $form->count());

    $form = $form->form();
    $this->assertNotEmpty($form);

    $form['_username'] = 'username';
    $form['_password'] = 'password';

    $this->client->submit($form);
    $this->assertTrue($this->client->getResponse()->isRedirect('http://localhost/login'));
    $this->client->followRedirect();

    $session = $this->client->getContainer()->get('session');
    var_dump($session->getBag('flashes')->all()); // this print an empty array
}

ログイン コントローラーは「Bad credentials」というフラッシュ メッセージを設定しますが、テスト中にそれを見ることができません。

4

1 に答える 1