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

troccoli's avatar

How do I test Flux::toast ?

I know Flux is very new, but maybe this is more a Livewire question than a Flux one.

I have a Livewire component with a form. The submit method is something like the following

public function submit(): ?Redirector
{
    $this->validate();

    if ($this->everythingIsOk()) {
        // Save the data
        redirect()->route('home');
    }
        
    Flux::toast(
        heading: 'Error!',
        text: 'Sorry try again.',
        variant: 'danger'
        );

    return null;
}

I can easily test the validation, and the happy path. Now I want to test if everything else is not OK (the everythingIsOk() is not a real method, I've just put it there to show the logic) and therefore the toast message appears.

Since Flux::toast is another Livewire component I don't know how to do it.

I know I could probably refactor it so my component emit an event and the event listener show the toast, but is this really the only way? It's such a simple component that it feels like an overkill to use events.

0 likes
3 replies
troccoli's avatar

Thanks @alifewithless

That solutions assumes a use an event to then show the toast, which I would like to avoid if possible.

Please or to participate in this conversation.