[英]Codeception api suite,Ignore redirect
I have used codeception to test my api written in symfony framework, I have been stuck into a problem that one of my endpoint contains redirect. 我已经使用代码接收来测试用symfony框架编写的api,但我陷入了一个问题,即我的一个端点包含重定向。 How would I handle the redirect?
我将如何处理重定向? Below is my code snippet
以下是我的代码段
if ($request->get('error') == 'access_denied') {
$error = array(
'status' => $this->get(GenericConstants::TRANSLATOR)->trans('vk.page.error', array(), 'page'),
'code' => 400,
'channel' => 'VK',
'user_identifier' => '',
'profile_select' => 'true',
'process' => $process_type,
'message' => $this->get(GenericConstants::TRANSLATOR)->trans('vk.dashboard.error.userCancelled', array(), 'dashboard')
);
return **$this->redirect($setting_url . http_build_query($error));**
}
Here is my test 这是我的测试
$customer = $this->ui->getCustomer();
$user = $I->haveAVkUser();
$application = $I->haveAVkApplication($customer);
$owner = $I->haveAnOwner($customer, $this->ui);
$community = $I->haveACommunity($customer, $owner, array('communityType' => 0));
$I->sendGET(
'/oauth/callback',
[
"state" => strtr(base64_encode($community->getId(). "-new") , '+/=', '-_,'),
'code' => 404,
'error' => "access_denied"
]
);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::FOUND);
I want that I should not be redirected from test environment 我希望我不应该从测试环境中重定向
Great, you are using REST module here. 太好了,您在这里使用REST模块。
REST module has stopFollowingRedirects method. REST模块具有stopFollowingRedirects方法。 Use it before
sendGET
call. 在
sendGET
调用之前使用它。
$I->stopFollowingRedirects();
$I->sendGET(
'/oauth/callback',
[
"state" => strtr(base64_encode($community->getId(). "-new") , '+/=', '-_,'),
'code' => 404,
'error' => "access_denied"
]
);
If you need to re-enable redirects in the same test, use $I->startFollowingRedirects();
如果需要在同一测试中重新启用重定向,请使用
$I->startFollowingRedirects();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.