@m21s can you show your full test?
Mar 11, 2020
4
Level 1
Facade error with the new Http Client in test
I just created a new Laravel 7 project. I required guzzle and added \Illuminate\Support\Facades\Http::fake(); into Tests\Unit\ExampleTest@testBasicTest. When I run the tests, I get the following:
FAIL Unit\ExampleTest
✕ basic test
Tests: 1 failed, 1 pending
RuntimeException
A facade root has not been set.
at vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:258
254| {
255| $instance = static::getFacadeRoot();
256|
257| if (! $instance) {
> 258| throw new RuntimeException('A facade root has not been set.');
259| }
260|
261| return $instance->$method(...$args);
262| }
1 tests/Unit/ExampleTest.php:16
Illuminate\Support\Facades\Facade::__callStatic("fake", [])
Any idea what I did wrong?
Level 53
@m21s that's because unit tests will not boot the framework by default in Laravel 6.7 and later. Of course you can change it by replacing use PHPUnit\Framework\TestCase; with use Tests\TestCase;, but as you're trying to mock Http request it should probably be a feature test.
https://github.com/laravel/framework/commit/e30a0c979d98f2f1f7b6c565e4002734237a280b
Please or to participate in this conversation.