Warm tip: This article is reproduced from stackoverflow.com, please click
codeception laravel php testing

How can I test DELETE api in Laravel?

发布于 2020-04-22 11:01:16

How can I test RESTful api of DELETE in Laravel by using Codeception?

I use the following function:


    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);
    } 

But the employee does not created in the DB!

How can I create an object for testing delete API?

Questioner
Mahdi J.Ansari
Viewed
16
Mahdi J.Ansari 2020-02-07 02:12

I found the problem. I need to send the id as part of the url!

$I->sendDELETE('employees/20200100000000');