Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow a single subscriber to subscribe to multiple event types #6086

Open
mollierobbert opened this issue Dec 16, 2024 · 0 comments
Open

Allow a single subscriber to subscribe to multiple event types #6086

mollierobbert opened this issue Dec 16, 2024 · 0 comments
Labels
type/enhancement A new idea that should be implemented

Comments

@mollierobbert
Copy link

PHPUnit's event system could potentially allow a single subscriber to subscribe to multiple events using union types. For example:

class MySubscriber implements PHPUnit\Event\Test\PreparedSubscriber, PHPUnit\Event\Test\FinishedSubscriber
{
    public function notify(PHPUnit\Event\Test\Prepared | PHPUnit\Event\Test\Finished $event): void
    {
        // Do something interesting with either event
    }
}

However, currently in PHPUnit\Event\Dispatcher\DirectDispatcher::registerSubscriber(), it is assumed each subscriber only implements a single subscriber interface.

If you try to add MySubscriber anyway, it will be registered to only one of the two event types (whichever comes first in the PHPUnit\Event\Facade::registerDefaultTypes() list), and thus never receive events of the second type.

Allowing a single subscriber to define multiple subscriber interfaces could help reduce boilerplate in extensions.

@mollierobbert mollierobbert added the type/enhancement A new idea that should be implemented label Dec 16, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

1 participant