Behat/Behat — Issue #62: Allow altering the execution order of hooks
Author: mrtorrent
Created: 2011-10-19 17:20:30+00:00
State: open

Currently, as far as I can tell, there is no way to specify where in the stack a hook should be inserted, and they are fired on a first-in, first-out basis. It would be helpful to be able to rearrange the order of hooks for events from within a context.

Sample use case:

1. A feature suite uses Mink to do headless testing on a Symfony application
2. A beforeScenario hook does some set-up on an in-memory database
3. The hook injects the database connection into the service container of the kernel under test (otherwise the kernel would open its own connection, which would effectively be a new database)
4. The hook is queued to run after Mink's `prepareMinkSessions` hook, so that the database connection can be injected after the session is initialised. Otherwise, Mink resets the session after our database set-up hook and the service container and its database connection are lost.