Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
phpunit测试检查状态代码_Php_Unit Testing - Fatal编程技术网

phpunit测试检查状态代码

phpunit测试检查状态代码,php,unit-testing,Php,Unit Testing,我正试图用单元测试来测试我的LaravelAPI。但当我试图检查状态代码时,它并没有按我希望的方式工作 这是我的代码: public function testExample() { $client = new Client(); $res = $client->request('POST', 'domain.dev/api/v1/test/1', [ 'form_params' => [

我正试图用单元测试来测试我的LaravelAPI。但当我试图检查状态代码时,它并没有按我希望的方式工作

这是我的代码:

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());
    }
例如,当我在《邮递员》中尝试此功能时,我收到以下信息:

{"result":{"message":"Error show school"}}
状态代码
500

如果我运行phpunit,它会显示:

/Users/jamie/code/domain/tests/ExampleTest.php:22
(见第22行注释)


我做错了什么?

您的呼叫
$res=$client->request(…)
引发异常


在上,您可以查看如何配置php以正确显示此类错误。

您的调用
$res=$client->request(…)
引发异常

在上,您可以查看如何配置php以正确显示此类错误