I want to use standard Laravel facades, such as Str
and Config
, in my PestPHP Feature tests. Is there some concise way I can get PestPHP to do this for all of my tests in my tests/Feature
directory?
I thought having uses(Tests\TestCase::class)->in('Feature');
in my Pest.php
file would be sufficient, but all I ever get is this error: "A facade root has not been set."
The problem appears to be that Pest does not boot Laravel when it runs your test files, but rather only when you call certain global functions, e.g. the test closure functions
test()
andit()
. So it's not possible to use Pest's "simplified" test script structure to easily initialize class-wide (file wide) values, i.e. attributes.beforeAll()
does not work for this. Instead, one has to usebeforeEach()
in each class where facades will be needed.See these issues: https://github.com/pestphp/pest/issues/237, https://github.com/pestphp/pest/issues/33#issuecomment-658022624, https://github.com/pestphp/pest/issues/246.