Ad
Laravel 6.12 "A Facade Root Has Not Been Set." When Using Log::
Using Log
in unit tests causes weird error
Versions: Laravel Framework 6.12.0 php 7.4 phpunit 8.5.2
<?php
namespace Tests\Unit;
use Illuminate\Support\Facades\Log;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
Log::info('hellowli');
$this->assertTrue(true);
}
}
I run:
$ php7.4 vendor/bin/phpunit tests/Unit/ExampleTest.php
$ php7.4 vendor/bin/phpunit tests/Unit/ExampleTest.php
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 49 ms, Memory: 6.00 MB
There was 1 error:
1) Tests\Unit\ExampleTest::testBasicTest
RuntimeException: A facade root has not been set.
/home/toskan/IdeaProjects/apartments/laravel/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:258
/home/toskan/IdeaProjects/apartments/laravel/tests/Unit/ExampleTest.php:17
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Ad
Answer
Your test case is extending the wrong base TestCase.
Simply change the namespace to:
use Tests\TestCase;
Instead of:
use PHPUnit\Framework\TestCase;
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad