sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.6k stars 2.19k forks source link

Add a priority for hooks #5889

Open nikophil opened 4 days ago

nikophil commented 4 days ago

Hello,

would you accept a PR which would add a concept of "priority" between hooks like Before, After...?

This would allow to control the order of execution of these hooks, mainly useful when used along with traits:

trait SomeTraitWithHook
{
    #[Before]
    protected function someBeforeHook(): void
    {
        // do something
    }
}

trait SomeOtherTraitWithHook
{
    #[Before(priority: 5)]
    protected function someOtherBeforeHook(): void
    {
        // will be executed before `SomeTraitWithHook::someBeforeHook`
    }
}

priority should be any integer (even negative ones), and it would default to 0.

thanks for your answer on this.

sebastianbergmann commented 4 days ago

Yes, I am open for that.