【发布时间】:2014-08-29 16:27:59
【问题描述】:
我正在使用 Symfony2 和 FOSRestBundle,现在我尝试为我的 rest api 编写功能测试。我想发布一个用户名并显示它,类似于http://npmasters.com/2012/11/25/Symfony2-Rest-FOSRestBundle.html。即,我的控制器返回一个 View::createRedirect([...],Codes::HTTP_CREATED) 实例。
现在,我的测试看起来像:
[...]
$client = static::createClient(array('debug'=>true));
$request = $client->request('POST', '/names',
array(),
array(),
array('CONTENT_TYPE' => 'application/json'),
$expression);
$response = $client->getResponse();
\print_r($response);
$this->assertEquals($response->getStatusCode(), 201);
$response = $client->followRedirect();
\print_r($response);
当我运行它时,我得到这个输出:
Symfony\Component\HttpFoundation\Response Object
(
[...]
[location] => Array
(
[0] => /names/90
)
[...]
There was 1 error:
1) MYNAME\MyBundle\Tests\Controller\RestControllerTest::testAddUser
LogicException: The request was not redirected.
为什么没有重定向? 我的错在哪里?
感谢您的帮助!
【问题讨论】: