2

I'm trying to test my Laravel api with unit testing. But when I try to check for a status code it's not working the way I want it to.

This is my code:

public function testExample()
    {
        $client = new Client();
        $res = $client->request('POST', 'domain.dev/api/v1/test/1', [
            'form_params' => [
                'currentUserId' => 13
            ]
        ]);  //line 22
        $this->assertEquals(500, $client->getResponse()->getStatusCode());
    }

When I try this in for example postman I receive the following:

{"result":{"message":"Error show school"}}

with status code 500

If I run phpunit it shows:

/Users/jamie/Code/domain/tests/ExampleTest.php:22 (see comment for line 22)

What am I doing wrong here?

Jamie
  • 10,302
  • 32
  • 103
  • 186

1 Answers1

0

Your call $res = $client->request(...) throw an exception.

On this thread you can view how to configure php to display this kind of error correctly.

Community
  • 1
  • 1
kletord
  • 146
  • 5