更新方法的Laravel单元测试不起作用



我试图在资源控制器中对更新函数进行单元测试,但一直收到一个错误调用未定义的方法assertStatus((。这是我的代码:$this->不带ExceptionHandling((;

$this->withoutExceptionHandling();
$timesheet = factory(TimeSheets::class)->create();
$user = factory(UsersLoginModel::class)->create();
$data = [
'subject' => $this->faker->text,
'subjectmatter' => $this->faker->text,
'description' => $this->faker->text,
];
;
$update = $this->actingAs($user)->json('PATCH','timesheets/update'.$timesheet->id, $data);
$this->assertStatus(200);
$this->assertEquals($data['subject'], $timesheet->subject);
$this->assertEquals($data['subjectmatter'], $timesheet->subjectmatter);
$this->assertEquals($data['description'], $timesheet->description);

assertStatus断言不在IlluminateFoundationTestingTestCase类上,而是在IlluminateFoundationTestingTestResponse类上,因此在代码中需要这样使用它:

$update = $this->actingAs($user)->json('PATCH','timesheets/update'.$timesheet->id, $data);
$update->assertStatus(200);

最新更新