jeudi 17 octobre 2019

How to test function in laravel Unit testing

Using Unit Testing for the first time.

Ceated Test File by cmd:

php artisan module:make-test ProjectTest Projects

I can test by cmd:

./vendor/bin/phpunit

But I want to test my function, My function is like:

public function update(Request $request, $id)
    {
        $project = Project::find($id);
        $project->project_name = request('project_name');
        $project->save();
        return response()->json([
            'message' =>  "Project Updated Successfully",
            'updatedId' => $project->id
            ], 200);
    }

Can anyone please guide me on how to test this Controller in PHPUnit?

On PostMan testing the function like:

URL:(POST method) http://localhost:8000/api/updateProject/1

On Body

{
    "project_name":"school",
}

How to use PHP Unit Testing in Laravel for the above Controller ?. Kindly explain to me with code Snippets.

Aucun commentaire:

Enregistrer un commentaire