Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

notsosuper's avatar

A facade root has not been set and Call to undefined method Illuminate\Container\Container::basePath()

When running a PHPUnit test I am getting two errors. I can use both in my application and not get any error but when running base_path() and Http::fake() inside the test I do. I have also tried this on a fresh Laravel application and the same happens.

I have tried using the CreatesApplication trait and this does not help.

Base Path Error

Call to undefined method Illuminate\Container\Container::basePath()

  at vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:191
    187|      * @return string
    188|      */
    189|     function base_path($path = '')
    190|     {
  > 191|         return app()->basePath($path);
    192|     }
    193| }
    194|
    195| if (! function_exists('bcrypt')) {

  1   tests/Unit/ExampleTest.php:16
      base_path()

Http Error

   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:17
      Illuminate\Support\Facades\Facade::__callStatic("response")
0 likes
3 replies
Amaury's avatar
Amaury
Best Answer
Level 43

Try to change

use PHPUnit\Framework\TestCase;

to:

use Tests\TestCase;
1 like
carestad's avatar

That works! But this is seemingly an issue when using the artisan make:test command. It adds that use statement by default, which seems wrong to me, since none of the Laravel-specific unit tests methods are available then.

Could be a bug perhaps?

rachids's avatar

Hello friends,

I just found your conversation while running into the same issue and it totally fixed my problem.

And after a few searches, I found this issue on the laravel/framework's github.

Hope it will help clear things out.

Stay safe and keep coding cool things. Kisses.

Please or to participate in this conversation.