首页 > 解决方案 > PHP 单元测试 Laravel

问题描述

我无法在 PHPUnit 中解决这个问题。在 Postman 中它运行良好,但在 PHPUnit 中出现错误。

class MyPageTakumoiTest extends TestCase
{
    protected $api = "/api/my_page_takumoi/2";

    public function testUpdate()
    {

        $response = $this->json('PUT', $this->api, [
            'family_name' => 'new kk',
        ]);

        $response->assertStatus(200);

    }
}

Expected status code 200 but received 500.
Failed asserting that 200 is identical to 500.

在此处输入图像描述

标签: laravelphpunit

解决方案


您可以在测试开始时使用它来获得更好的异常:

$this->withoutExceptionHandling();

推荐阅读