1
404,403などのプロジェクトでカスタムエラーテンプレートがあります。私はユニットテストケースを作成して、httpエラーをアサートする必要があります。私がユーザーとログを取ってベンダーの承認されたページにアクセスすると、ブラウザーで403アクセスが拒否されていますが、ユニットテストのケースでは常に404ページが見つかりませんでした。私はそれが404エラーテンプレートが表示されます応答内容を印刷するときAssert 403アクセスPHPUnitのテストケースでhttpステータスが拒否されました
class ErrorExceptionTest extends WebTestCase
{
public function testAccessDeniedException()
{
$server['HTTP_HOST'] = 'http://www.test.com/';
$client = static::createClient(array('debug' => false), $server);
$client->disableReboot();
$session = $client->getContainer()->get('session');
$firewall = 'main';
$token = new UsernamePasswordToken('user', null, $firewall, array('ROLE_USER'));
$session->set("_security_$firewall", serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$client->getCookieJar()->set($cookie);
$client->request('GET', '/vendor/profile/edit');
$this->assertEquals(403, $client->getResponse()->getStatusCode());
$this->assertContains('Sorry! Access Denied', $client->getResponse()->getContent());
}
}
私のテストケースは、失敗している:
は、ここに私のテストシナリオです。