I am developing an app and now I need to do some testing. Everything in the app is based on authenticated user so this is the first test that I need to do. I have a google captcha in the form but I modified the .env file so that will not be required. This is my feature test.
public function test_users_can_authenticate()
{
$user = User::factory()->create();
$response = $this->get('/login', [
'_token' => csrf_token(),
'email' => $user->email,
'password' => 'secret',
'g-recaptcha-response' => ''
]);
$this->assertAuthenticated();
$response->assertRedirect(RouteServiceProvider::HOME);
}
The test is failing on this line $this->assertAuthenticated(); saying that The user is not authenticated. Failed asserting that false is true. I did not now what can I do to make it work. I tried php artisan config:clear before php artisan test, not working. I uncomment the lines in phpunit.xml
<!-- <server name="DB_CONNECTION" value="mysql"/> -->
<!-- <server name="DB_DATABASE" value=":memory:"/> -->
but still with no result. Working with Laravel 8.x. What can I do to make this work? Thanks.
sqliteinstead ofmysqlin yourphpunit.xml:<server name="DB_CONNECTION" value="sqlite"/>Also share your routes file but i think the call should be apostand not agetUser::factory(), which is as bad as a global variable. Generally, using dependency injection would be preferred, IMHO.postorgetis not working for the route. And with thesqliteconnection fromphpunit.xmlit's throwing me the errorcould not find driver (SQL: PRAGMA foreign_keys = ON;). And the routes for the login are the ones frommake:auth.