Symfony 3中的功能测试认证失败

时间:2016-06-16 07:33:53

标签: php authentication symfony functional-testing

我是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.

0 个答案:

没有答案