4jZW7jVSdS4U6PC's avatar

Load view composer for a single test method

Hello everyone.

I'm trying to test a page with a form that's generated by a View composer instance inside the ViewComposerServiceProvider:

        View::composer("components.user.settings", function ($view)
        {
            $settings = Setting::select(["key", "value"])->orderBy("key")->get();
            $view->withSettings($settings);
        });

The view is rendered properly when you use it but inside my test suite I cannot select any <select> generate by this view composer because the page rendered with PHPUnit doesn't have those selects at all.

I read about a bunch of solutions like forcing the rendering inside the test method by calling $this->app->make(... but I don't like very much and I wonder if Laravel has something already built in that I'm missing.

Does Laravel provide some sort of trait or whatever that I'm missing in order to render the view composer properly ?

0 likes
3 replies
dillscher's avatar

Do you know any other solution to use this as I want to make assertions without always running dusk due to speed considerations?

1 like

Please or to participate in this conversation.