m21s's avatar
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?

0 likes
4 replies
m21s's avatar
Level 1

Here's the test, I just added the Http Facade to the example test.

<?php

namespace Tests\Unit\ExampleTest;

use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase
{
    public function testBasicTest()
    {
        Http::fake();
        $this->assertTrue(true);
    }
}
m21s's avatar
Level 1

Thanks, didn't notice!

Please or to participate in this conversation.