Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MrMoto9000's avatar

Testing that an email can be verified

I wish to have a test that checks whether or not an email can be verified successfully.

The issue I have is getting my test to visit the link created by verificationUrl() in the VerifyEmail notification. Is there a way I can easily expose this for testing purposes?

This is one way of doing it: https://stackoverflow.com/a/57714619/199700

But I was wondering if anyone knows a better way?

0 likes
6 replies
tykus's avatar

I am trying to understand what exactly you are testing here; why do you need to visit that link in your test?

MrMoto9000's avatar

Hey, thanks for trying to help. My app has the simple ability to allow the user to change their email address. They request the change, an email with a verification link is dispatched to the new address, and once it's clicked then the new email is inserted into the place of the old one.

Does that help explain the situation? I basically want to replicate the behaviour of a user clicking the link in the verification email to test that their new email is inserted correctly.

Thanks again!

tykus's avatar
tykus
Best Answer
Level 104

I think I know what you're doing, but I'm not sure I would go about testing it as you are since I don't own that Email Verification code. I think I would probably be Unit Testing whatever is listening to the Verified event, and it is inside that Listener that I would updated their email address?

MrMoto9000's avatar

I'm sure you're probably right. It may not even be possible to do what I was hoping to. It's late here and I'm tired :)

As to what updates the email, it's simply visiting the URL:

Route::get('/verify-email/{id}/{hash}', [VerifyEmailController::class, '__invoke']) ->middleware(['auth', 'signed', 'throttle:6,1']) ->name('verification.verify');

MrMoto9000's avatar

Oops. I took a moment and zoomed out. I was really overcomplicating something that was actually very simple! :) I got it to do what I want now.

mg3994's avatar

i modified the whole code, as i want to design it for Mobile API (Deeplink)=>

Route::middleware('auth')->group(function () {
    Volt::route('verify-email', 'auth.verify-email')
        ->name('verification.notice');

//  Moved From HERE
    Volt::route('confirm-password', 'auth.confirm-password')
        ->name('password.confirm');
});
//  Out of auth middleware
Route::get('verify-email/{id}/{hash}', VerifyEmailController::class)
        ->middleware(['signed', 'throttle:6,1']) //signed means signature
        ->name('verification.verify');

and Modified it

Now I am trying to Modify -> verify-email.blade.php -> as I want to Listen and reflect the Email Verification Status By Routing To dashboard in real time (Not Using wire:poll) => guess How

Please or to participate in this conversation.