Jonathan's avatar

View Composer in Integration Test?

I'm trying Jeffrey's new Integrated testing package.

In my app, I set a wildcard view composer using

$this->app['view']->composer('*', function ($view) {
    $view->with('currentUser', $this->app['auth']->user());
});

In one of my views, I display an 'Edit' button, if the currentUser id is equal to the profileUser id. However, when running the integration tests with the package, the button isn't available.

I've tried putting the above code in a helper function with no luck:

protected function beLoggedInUser($overrides = [])
    {
        $user = $this->createUser($overrides);

        $this->be($user);

        $this->app['view']->composer('*', function ($view) {
            $view->with('currentUser', $this->app['auth']->user());
        });

        return $user;
    }

Any thoughts? Is this even possible?

0 likes
1 reply
Jonathan's avatar
Jonathan
OP
Best Answer
Level 6

Just as an FYI, I figured out what the problem was. My View Composers were taking effect from my Service providers, but in my view, I had a strict equal (===) for $currentUser->id and $user->id. The comparison was between and integer and a string, so I made it a loose comparison (==) and that fixed the problem.

Please or to participate in this conversation.