1

I am newbie for Symfony. I am trying do functional test for UserController. But I don't know how can do it. Because response 401 not equals 200. How can I skip authentication. My codes below:

    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);
}

And my problem is here:

3) AppBundle\Tests\Controller\UserControllerTest::testGetAction
   {"code":401,"message":"Authentication Required"}
   Failed asserting that 401 matches expected 200.
Kerim
  • 231
  • 1
  • 5
  • 15
  • 1
    You need to authenticate yourself or have a valid user session before you try to access a link which is under the firewall and requires a login. Try my answer to a similar question: http://stackoverflow.com/a/35824792/393805 – tftd Jun 16 '16 at 09:52

0 Answers0