0

I want to Unit test my Authentication. I'm using Service-Repository pattern, so i already wrote unit tests for Controller and Service, but now i need to test AuthRepository.php For example i have "Register" method in repository, which looks like this:

public function register(RegisterAuthRequest $fields)
{
    $user = $this->_user->create([
        'name' => $fields['name'],
        'email' => $fields['email'],
        'password' => bcrypt($fields['password']),
    ]);

    $token = $user->createToken('wcgtoken')->plainTextToken;

    $response = [
        'user' => $user,
        'token' => $token,
    ];

    return response($response, 201);
}

And i have Custom Form Request RegisterAuthRequest.php

public function rules()
{
    return [
        'name' => 'required|string',
        'email' => 'required|string|unique:users,email',
        'password' => 'required|string|confirmed',
    ];
}

So i want to make unit test which will assert failed validation, like if request would have empty data

  • Does this answer your question? [Unit Test Laravel's FormRequest](https://stackoverflow.com/questions/36978147/unit-test-laravels-formrequest) – miken32 Dec 10 '21 at 21:55

0 Answers0