【问题标题】:phpunit test check statuscodephpunit 测试检查状态码
【发布时间】:2016-06-03 00:21:02
【问题描述】:

我正在尝试使用单元测试来测试我的 Laravel api。但是当我尝试检查状态代码时,它并没有按照我想要的方式工作。

这是我的代码:

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 行的注释)

我在这里做错了什么?

【问题讨论】:

    标签: php unit-testing


    【解决方案1】:

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

    this thread可以查看如何配置php正确显示此类错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 2019-03-20
      • 2022-11-07
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多