- Laravel 6.5
- Laravel Browser Kit ^5.1
I am creating my own packages for something I building and one is causing the issue at hand: A facade root has not been set. when I run my tests.
This is routes file App\Game\routes\web.php
:
<?php
use Illuminate\Support\Facades\Route;
// Core routes for the game related stuff:
Route::get('/game', ['as' => 'game', 'uses' => 'GameController@game']);
Pretty basic, nothing here that should stand out. So how do we register these:
<?php
namespace App\Game\Providers;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RoutesProvider extends ServiceProvider
{
protected $namespace = 'App\Game\Controllers';
public function boot()
{
parent::boot();
}
public function map()
{
$this->mapWebRoutes();
}
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(__DIR__.'/../routes/web.php');
}
}
Again nothing insane, if we addd this to the config/app.php
and run php artisan route:list
we see:
You can see the game route above. so now lets run our tests, make sure nothings breaking ...
composer phpunit
> ./vendor/bin/phpunit --coverage-html=./test-coverage
PHPUnit 8.4.3 by Sebastian Bergmann and contributors.
Fatal error: Uncaught RuntimeException: A facade root has not been set. in /Users/xxxx/Documents/xxxx/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:242
Stack trace:
#0 /Users/xxxx/Documents/xxxx/app/Game/routes/web.php(5): Illuminate\Support\Facades\Facade::__callStatic('get', Array)
#1 /Users/xxxx/Documents/xxxx/vendor/phpunit/php-code-coverage/src/CodeCoverage.php(955): include_once('/Users/adambala...')
#2 /Users/xxxx/Documents/xxxx/vendor/phpunit/php-code-coverage/src/CodeCoverage.php(239): SebastianBergmann\CodeCoverage\CodeCoverage->initializeData()
#3 /Users/xxxx/Documents/xxxx/vendor/phpunit/phpunit/src/Framework/TestResult.php(646): SebastianBergmann\CodeCoverage\CodeCoverage->start(Object(Tests\Unit\xxxx\BaseStatValueTest))
#4 /Users/xxxx/Documents/xxxx/vendor/phpunit/phpunit/src/Framework/TestCase.php(752): PHPUnit\Framework\TestResult->run(Object(Tests\Unit\xxxx\BaseStatValueTest))
#5 /Users/xxxx/Documents/xxxx/vendor/phpunit/phpunit/src/Framewor in /Users/xxxx/Documents/xxxx/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 242
PHP Fatal error: Uncaught RuntimeException: A facade root has not been set. in /Users/xxxx/Documents/xxxx/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:242
Stack trace:
#0 /Users/xxxx/Documents/xxxx/app/Game/routes/web.php(5): Illuminate\Support\Facades\Facade::__callStatic('get', Array)
#1 /Users/xxxx/Documents/xxxx/vendor/phpunit/php-code-coverage/src/CodeCoverage.php(955): include_once('/Users/adambala...')
#2 /Users/xxxx/Documents/xxxx/vendor/phpunit/php-code-coverage/src/CodeCoverage.php(239): SebastianBergmann\CodeCoverage\CodeCoverage->initializeData()
#3 /Users/xxxx/Documents/xxxx/vendor/phpunit/phpunit/src/Framework/TestResult.php(646): SebastianBergmann\CodeCoverage\CodeCoverage->start(Object(Tests\Unit\xxxx\BaseStatValueTest))
#4 /Users/xxxx/Documents/xxxx/vendor/phpunit/phpunit/src/Framework/TestCase.php(752): PHPUnit\Framework\TestResult->run(Object(Tests\Unit\xxxx\BaseStatValueTest))
#5 /Users/xxxx/Documents/xxxx/vendor/phpunit/phpunit/src/Framewor in /Users/xxxx/Documents/xxxx/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 242
Its all caused by that web.php
routes file when it tries to create the route doing: Route::get(....)
. From my understanding router
does not exist in app container when the app boots up for test.
I have tried calling setUp
in my test classes, and calling it's parent. But still I get the error.
I have never encountered this before and nothing o the internet is helping me. Any ideas as to why I am getting this error?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire