私が機能を持っているsymfonyの3コントローラファイルで:3 behatミンクテストのリダイレクト
/**
* @Route("/user/registration", name="post_registration")
* @Method("POST")
* @return mixed
*/
public function postRegistration()
{
$post = $this->getAllPost();
$this->curl = $this->get('ApiClient');
$responseArray = $this->curl->post(
$this->container->getParameter('api_url') . '/users',
$post
);
if (isset($responseArray['api_key'])) {
return $this->redirectResponseWithCookie($responseArray['api_key']);
} else {
return $this->render(
static::REGISTRATION_TEMPLATE,
['errors' => $responseArray['errors']]
);
}
}
1つの部分では、ページをリダイレクトする必要がある関数
redirectResponseWithCookie()
を呼び出します。
私はリダイレクトヘッダーをテストしたいです - 正しいLocation値を持っていますか?
私は
class UserRegistrationContext extends BaseContext implements Context, SnippetAcceptingContext
{
/**
* @When I register successfully into the system
* @return null
*/
public function iRegisterSuccessfullyIntoTheSystem()
{
$this->canIntercept();
$this->session->getDriver()->getClient()->followRedirects(false);
// Enters his data
// Posts to www.notification.guru .
$this->session->getDriver()->getClient()
->request('POST', $this->baseUrl . '/user/registration', $this->getFormArray());
echo 'test';
}
}
BaseContextクラスだけで、セッションのINITそのコンストラクタをいくつかのヘルパー関数を持っているUserRegistrationContextクラスの機能を持っている:
$driver = new GoutteDriver();
$this->session = new Session($driver);
この部分は間違っているかもしれない:
$this->session->getDriver()->getClient()->followRedirects(false);
私はちょうど2.5からコードを取り出し、3で動作させるように調整しようとしましたが、それが正しいかどうかわからないが、少なくともエラーを投げない。
それは、リダイレクトを停止する必要がありますので、私は
getResponseHeaders()
でレスポンスヘッダを得ることができる。しかし、それはリダイレクトどこ実際のサイトがまだlauchedされていないため、問題は、それがリダイレクトしようとすることで、コードが失敗しました。また、実際のリダイレクト後に推測するヘッダーをテストすることもできません。
したがって、リダイレクトを停止する必要があります。
どうすればよいですか?私は情報を見つけることができません。私は、コンソールでよく見ていなかった -
テストは、私がコメントで言ったように私の質問のコードは、間違っていないライン
$this->session->getDriver()->getClient()
->request('POST', $this->baseUrl . '/user/registration', $this->getFormArray());
実は私はそのコードに誤りがない見て、私はテストを実行した後、コンソールにも表示されませんでした。 –