create(); $user->refresh(); $this->actingAs($user) ->withSession(['auth.password_confirmed_at' => time()]) ->post('/settings/email', ['email' => $user->email]) ->assertRedirect('/settings/email') ->assertSessionHasNoErrors(); }); it('persists a genuinely new email', function () { $user = User::factory()->create(); $user->refresh(); $newEmail = 'brand.new.'.uniqid().'@example.com'; $this->actingAs($user) ->withSession(['auth.password_confirmed_at' => time()]) ->post('/settings/email', ['email' => $newEmail]) ->assertSessionHasNoErrors(); expect($user->fresh()->email)->toBe($newEmail); }); it('rejects an email already used by another account', function () { $other = User::factory()->create(['email' => 'taken@example.com']); $user = User::factory()->create(); $user->refresh(); $this->actingAs($user) ->withSession(['auth.password_confirmed_at' => time()]) ->post('/settings/email', ['email' => 'taken@example.com']) ->assertSessionHasErrors('email'); expect($user->fresh()->email)->not->toBe('taken@example.com'); });