Testing a Laravel 5 route with an exists rule via Codeception Testing a Laravel 5 route with an exists rule via Codeception laravel laravel

Testing a Laravel 5 route with an exists rule via Codeception


The problem is, that if the transaction is not commited, the original data in the database tables is not affected. So within the transaction, you create two users, but there is no commit statement that would persist that to your database. Hence the laravel validation rule 'exists' cannot find them ( that rule makes a database request to find particular user_id ).

So in your case the users have to exist before testing. I would recommend to use Migrations instead. Resetting Database after each test

Create your tables with database migrations and seeds and roll them back after tests have finished.


Quote:

$I->sendPOST('users/' . $users[0]->id . '/friendships', [    'user_id' => $users[1]->id]);

Why are you sending $users[0]->id in the request url and then 'user_id' => $users[1]->id in the parameters?

Could this be your problem? Could this be the reason you are failing the validation?