Maybe try adding use RefreshDatabase;. https://laravel.com/docs/5.8/database-testing#resetting-the-database-after-each-test
Error in test when share variable between views in ServiceProvider
Hi Friends,
in This Course Let's Build A Forum with Laravel and TDD in Episode 13
@JeffreyWay
teach how to share variable but when i do that all of my test get failed.
he share View::share('channels', \App\Channel::all());
when i see error in test all of them throw this error:
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1 no such table: channels (SQL: select * from "channels")
I think because in test at first AppServiceProvider will call and then test will call so database in not migrate how can i resolve that?
pay Attension: Test Database in sqlite:memory:
My guess was write and in the later episode Jeffrey Correct that. when i write this question i thought he run project and was correct with old solution the new Solution is use View::composer() like this:
// Correct on Tests
View::composer('*', function ($view) {
$view->with('channels', \App\Channel::all());
});
the Above code should be place in instead of this code
// Failed on Tests
View::share('channels', \App\Channel::all());
Please or to participate in this conversation.