mardi 21 février 2023

is there a way to test data update failure in laravel unit test

I'm doing the unit testing in Laravel. I wrote a test for the if function (data store). but I want to know how to write test for else part. when data save is failure, an error message return.

    public function store(Request $request)
    {
        $user = $this->user->create($request->all());

        if ($user) {
            return response()->json([
                'message' => 'Data saved successfully,
                'data' => [
                    'user' => $user
                ]
            ]);
        } else {
            return response()->json([
                'message' => 'Data save failed.'
            ], 400);
        }
    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire