我是Symfony的新手。我正在尝试为UserController做功能测试。但我不知道怎么做。因为响应401不等于200.如何跳过身份验证。我的代码如下:
public function testGetAction() {
$expected = array(
'user'=>
array(
'id' => 1,
'tcId' => "23456789415",
'email' => '*********',
'firstName' => '****',
'lastName' => '****'
)
);
$expect = json_encode($expected);
$fixtures = array('AppBundle\DataFixtures\ORM\LoadUserData');
$this->loadFixtures($fixtures);
$users = LoadUserData::$users;
$this->client->request('GET', 'ajax/users/'.$users[0]->getTcId(), array('ACCEPT' => 'application/json'));
$response = $this->client->getResponse();
$content = $response->getContent();
$this->assertJsonResponse($response, 200);
$this->assertEquals($expect , $content);
}
我的问题在这里:
3) AppBundle\Tests\Controller\UserControllerTest::testGetAction
{"code":401,"message":"Authentication Required"}
Failed asserting that 401 matches expected 200.