I am trying to test signup for user in pest here is my pest code
test('signup user', function () {
$response = $this->post('signup-user',[
'email' => 'vishal444@gmail.com',
'first_name' => 'vishal',
'last_name' => 'singh',
'password' => '111111',
'confirm_password' => '111111'
]);
$response->assertSessionHas('success', 'You have registered successfully');
});
am getting this error
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'testing.users' doesn't exist (Connection: mysql, SQL: select count(*) as aggregate from `users` where `email` = vishal444@gmail.com)
at D:\laravel-tailwind\laravelwithtailwind\tests\Feature\AppTest.php:36
32▕ 'password' => '111111',
33▕ 'confirm_password' => '111111'
34▕ ]);
35▕
➜ 36▕ $response->assertSessionHas('success', 'You have registered successfully');
37▕ });
38▕
on docker all the containers are running well.and i have users table in my database,when i am testing someting related to data base or mysql am getting error
This is my signup_user
function:
public function signupUser(Request $request) {
$request->validate([
'email'=>'required|email|unique:users',
'first_name'=>'required',
'last_name'=>'required',
'password'=>'required|min:6|max:12',
'confirm_password'=>'required|min:6|max:12'
]);
$user = new User();
$user->email = $request->email;
$user->first_name = $request->first_name;
$user->last_name = $request->last_name;
$user->password = Hash::make($request->password);
$user->confirm_password = Hash::make($request->confirm_password);
I want to test this case:
test('user can signup', function () {
$userData = [ 'email' => 'vishal123@gmail.com', 'first_name' => 'vishal', 'last_name' => 'singh', 'password' => '123123', 'confirm_password' => '123123', ];
$this->post(route('signup-user'), $userData)
->assertSessionHas('success', 'You have registered successfully');
$this->assertDatabaseHas('users', [ 'email' => 'vishal123@gmail.com', 'first_name' => 'vishal', 'last_name' => 'singh', ]);
});