I now know what was/is wrong. I added google recaptcha to the registercontroller. This is why the unit test fails.
But how could I consider or how should I treat the recaptcha code in my test.
public function store(Request $request)
{
$request->validate([
'username' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);
// Google Recaptcha
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = [
'secret' => config('google-recaptcha.recaptcha_secret_key'),
'response' => $request->recaptcha,
];
$options = [
'http' => [
'header' => 'Content-type: application/x-www-form-urlencoded\r\n',
'method' => 'POST',
'content' => http_build_query($data),
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$resultJson = json_decode($result);
if($resultJson->success != true) return back()->withErrors('Captcha Error');
// Google Recaptcha End
$user = User::create([
'username' => $request->username,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
event(new Registered($user));
Auth::login($user);
return redirect(RouteServiceProvider::HOME);
}