[9.x] Adds bootable traits to TestCase - #42394
Conversation
|
There was a similar PR by @DarkGhostHunter: https://github.com/laravel/framework/pull/39883/files His supported setUp and tearDown in the traits, which may be useful? What are the use cases for this type of thing? What kind of traits are you writing? |
|
I have Dusk tests that upload a file directly to an S3 bucket (similar to Vapor with MinIO is fast and lightweight, so I've created a trait that boots up a new server for each test and destroys it when the test has finished. I don't have to think about starting the server manually before running the test suite, and it only boots on tests that use the trait. I haven't thought about a tearDown method, as I register a callback using the |
|
Renamed to |
This PR brings the bootable trait feature from Eloquent over to the Foundation TestCase.
Currently, the
setUpTraitsmethod checks several traits likeRefreshDatabaseandDatabaseMigrations, and then calls a method if the TestCase uses that trait. If you want to do this for custom traits, you must override thesetUporsetUpTraitsmethod. With this PR, it checks whether the trait has a bootTraitName method, and then calls that method.