如何在 Laravel 中测试 DELETE api?
How can I test DELETE api in Laravel?
如何使用 Codeception 测试 RESTful api 中的 DELETE in Laravel?
我使用了以下函数:
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 作为 url!
的一部分发送
$I->sendDELETE('employees/20200100000000');
如何使用 Codeception 测试 RESTful api 中的 DELETE in Laravel?
我使用了以下函数:
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 作为 url!
的一部分发送$I->sendDELETE('employees/20200100000000');