beforeSuite() hook that runs after Laravel boots #1600
rdehnhardt
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Currently,
beforeAll()runs before the Laravel application is initialized, which means we cannot use any Laravel features (facades, models, database, etc.) in it. This creates a common pain point when developers want to seed data once for multiple tests in a file.Current behavior
Current workaround
The only way to achieve this currently is using a static variable in
beforeEach():This works, but it's not intuitive and requires developers to understand the internal lifecycle.
Proposed Solution
Introduce a
beforeSuite()(or similar name likebeforeTests(),onceBefore()) hook that runs after Laravel boots but before all tests in a file.Proposed API
Benefits
Lifecycle comparison
Current
Proposed
Alternative names
onceBefore()/onceAfter()beforeTests()/afterTests()setupSuite()/teardownSuite()Notes
RefreshDatabasetraitafterSuite()counterpart would also be useful for cleanupUse cases
Thank you for considering this feature! Pest is an amazing testing framework, and this would make the Laravel testing experience even better. 🙏
Beta Was this translation helpful? Give feedback.
All reactions