Menu

Laravel 5.5 PHPUnit: Fix 'A facade root has not been set'
📰

Laravel 5.5 PHPUnit: Fix 'A facade root has not been set'

DEV Community: laravel·Faizan·about 8 hours ago
#DSXWcMta
#devtolaravel#devto#dev#laravel#test
Reading 0:00
15s threshold

"A facade root has not been set." in a Laravel 5.5 PHPUnit test almost always means one thing: your test touched a facade like DB , Schema or Config before Laravel had booted. The fix usually takes a few minutes once you know where in the PHPUnit lifecycle the call happens.

Quick answer: Look for facade calls in three places: setUpBeforeClass() , @dataProvider methods, and your test class constructor. All three run before Laravel creates the application. Move those calls into setUp() after parent::setUp() , or into the test method itself. Then confirm the test extends Tests\TestCase , not PHPUnit's base TestCase .

This is an old, well-understood testing problem rather than a framework bug.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.