Skip to content
Advertisement

assertRedirect causing output of email already exists – PHP Testing

So my test case in laravel is the following:

JavaScript

This line:

JavaScript

is causing the test to fail and get an output of ‘The email has already been taken’ Why is this the case? I want to check upon sign up, the user is directed to the home page which it does but my test fails.

The user is being created in the database so that part works fine.

UserFactory:

JavaScript

Advertisement

Answer

Okay I will explain your test case to you.

You are testing a register feature of your app.

JavaScript

this block of code is wrong because you are using the data of a User already inside the database to create an account. So it will naturally fails since the data is already inside the database the moment you call the User::factory()->create().

So instead of that you should pass a data that looks like you are the one registering.Remove the User::factory()->create() then replace the array $user with hard coded data or use the fake() helper.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement