Reputation: 95
I am trying to test the user registration, the test file came with laravel jetstream, I just added some additional fields, and I kept getting this error The user is not authenticated Failed asserting that false is true., please anyone with any idea what's wrong should help. User authentication login is working fine but registrationTest keep spitting this error
• Tests\Feature\RegistrationTest > new users can register
The user is not authenticated
Failed asserting that false is true.
at C:\wamp64\www\fegocomosa\tests\Feature\RegistrationTest.php:71
67▕ 'password' => 'password',
68▕ 'password_confirmation' => 'password',
69▕ ]);
70▕
➜ 71▕ $this->assertAuthenticated();
72▕ $response->assertRedirect('/successful');
73▕ }
74▕ }
75▕
1 C:\wamp64\www\fegocomosa\vendor\phpunit\phpunit\phpunit:98
PHPUnit\TextUI\Command::main()
This is the test file
<?PHP
namespace Tests\Feature;
use Carbon\Carbon;
use Tests\TestCase;
use Laravel\Fortify\Features;
use Laravel\Jetstream\Jetstream;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
class RegistrationTest extends TestCase
{
use RefreshDatabase;
public function test_registration_screen_can_be_rendered()
{
if (! Features::enabled(Features::registration())) {
return $this->markTestSkipped('Registration support is not enabled.');
}
$response = $this->get('/register');
$response->assertStatus(200);
}
public function test_registration_screen_cannot_be_rendered_if_support_is_disabled()
{
if (Features::enabled(Features::registration())) {
return $this->markTestSkipped('Registration support is enabled.');
}
$response = $this->get('/register');
$response->assertStatus(404);
}
public function test_new_users_can_register()
{
if (! Features::enabled(Features::registration())) {
return $this->markTestSkipped('Registration support is not enabled.');
}
$response = $this->post('/register', [
'username' => 'Test User',
'first_name' => 'User',
'middle_name' => '',
'last_name' => 'Username',
'date_of_birth' => Carbon::parse('1991-04-12'),
'about_you' => 'Lorem, ipsum dolor sit amet consectetur adipisicing
elit. Quaerat, tempora.',
'profile_photo_path'=> 'profile-photos/image.jpg',
'gender_id' => 1,
'marital_status_id' => 1,
'address' => 'new adress',
'phone' => '0706074000',
'state_id' => 8,
'city_id' => 162,
'profession' => 'Engineer',
'workplace' => 'NOUN',
'jss_class' => 'Jss1Q',
'sss_class' => 'Sss3Q',
'house_id' => 2,
'potrai_image' => 'mj_1.jpg',
'entry_year_id' => 1,
'graduation_year_id'=> 2,
'email' => '[email protected]',
'password' => 'password',
'password_confirmation' => 'password',
]);
$this->assertAuthenticated();
$response->assertRedirect('/successful');
}
}
Upvotes: 2
Views: 708
Reputation: 310
Answering in case someone else comes looking.
The default user in the Registration test and the default user in the DatabaseSeeder have the same email so the test fails. Just change the email in the seeder or the test.
Upvotes: 0