如何使用Codeception在Laravel中测试DELETE的RESTful API?
我使用以下功能:
public function authenticatedUserSuccessDeleteEmployee(ApiTester $I)
{
$I->wantToTest('authenticated super user success delete employee');
// set header authorization
$I->amBearerAuthenticated($this->token);
//
$this->employee = factory(\App\Models\Employee::class)->create([
'id' => '20200100000000'
]);
// see database row is containing our expected data
$I->seeRecord('employees', ['id' => '20200100000000']);
// Send delete request
$I->sendDELETE('employees', array('id' => '20200100000000'));
// check expected response code is 200 OK
$I->seeResponseCodeIs(200);
}
但是员工没有在数据库中创建!
如何创建测试删除API的对象?
我发现了问题。我需要发送ID作为网址的一部分!
$I->sendDELETE('employees/20200100000000');