Can't make this pass the login test with Laravel scaffolding.
I tried accessing database $user
with $user = User::first();
and also using factory User::factory()->create();
. In both cases I'm able to successfully dd($user)
info, so it means $user
exists and can be accessed.
I also tried hardcoding credentials with bcrpyt()
and Hash::make
password - where the error also appears to happen.
I'm not ussing RefreshDatabase
trait.
public function test_log_user()
{
$this->withoutExceptionHandling();
// $user = User::first();
$user = User::factory()->create();
// dd($user);
$response = $this->post('/login', [
'email' => $user->email,
'password' => $user->password, //line 47
]);
$response->getStatusCode();
// $response->dumpHeaders();
// $response->dump();
$response->assertStatus(302);
}
Getting this error:
IlluminateValidationValidationException: The given data was invalid.
C:xampphtdocs
eactReact-Laravelvinos-gdlestsFeatureAuthTest.php:47
I have already cleared cache, routes, config.
phpunit.xml:
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<!-- <server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/> -->
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
I also have a test_create_user
which passes correctly
public function test_create_user()
{
$this->withoutExceptionHandling();
$user = [
'name' => Factory::create()->name(),
'email' => Factory::create()->email(),
];
$response = $this->post('/register', [
'name' => $user['name'],
'email' => $user['email'],
'password' => Hash::make('123456'),
'password_confirmation' => Hash::make('123456')
]);
// $response->dumpHeaders();
// $response->dump();
$response->assertStatus(302);
}
question from:
https://stackoverflow.com/questions/65864249/testing-login-scaffolding-in-laravel-with-phpunit 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…