Laravel - API Test cases returns 401 Unauthorized

Hi

I am using Laravel 5.2 with Dingo to write APIs for my application. My application uses JWT to authenticate users.

I also wanted to write test cases for the API endpoints. When I hit my api endpoints using POSTMAN, they work like a charm, but the same endpoints when being hit through phpunit test cases, respond with 401 Unauthorized. I am using the same token value as being used in POSTMAN so my token isn’t the problem.

Following is my test case code:

    public function testSomeTest()
    {
        $token = 'Bearer  xxx';

        $response = $this->get('/users', ['Authorization' => $token]);
        print_r($response->dump());
    }

I have also tried the following, but no dice

    public function testSomeTest()
    {
        $token = 'Bearer  xxx';

        $response = $this->call('GET',  '/users', [],[],[], ['Authorization' => $token]);
        print_r($response->getContent());
    }

Here is the error output: http://pastebin.com/raw/Tjirez1V

Can someone please help me figure out what could be the problem?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.