Summer Sale! All accounts are 50% off this week.

jaapoost's avatar

Laravel "A facade root has not been set" when running phpunit

I'm doing a feature test on a function that uses the Cache facade.

public static function getMainCategories()
{
    $cacheKey = self::CATEGORY_CACHE_KEY . '_main';
    $fromCache = Cache::get($cacheKey, false);

    if ($fromCache) {
        dd('Cache');
    } else {
        dd('No cache');
    }
}

When running the function all works fine, but running it from a tests results in:

public function testItGetsTheMainCategoryPages()
{
    $data = MyClass::getMainCategories();
    $this->assertNotEmpty($data);
}
  1. Tests\Unit\MantelTest::testItGetsAllCategoryPages RuntimeException: A facade root has not been set.

Hopefully someone can point me in the right direction, since Googling didn't bring me much unfortunately

0 likes
5 replies
jaapoost's avatar

For anyone ending up here... It turned out that I auto-included PHPUnit\Framework\TestCase instead of Tests\TestCase... 🤯

6 likes
jjudge's avatar

So what is in your Tests\TestCase after it extends PHPUnit\Framework\TestCase?

Please or to participate in this conversation.