Try to change
use PHPUnit\Framework\TestCase;
to:
use Tests\TestCase;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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.
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()
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")
Try to change
use PHPUnit\Framework\TestCase;
to:
use Tests\TestCase;
Please or to participate in this conversation.