mardi 19 février 2019

Testing For Data Shared To All Views To Ensure It Exists

I share a few things to all views in my laravel project in AppServiceProvider:

public function boot()
    {

        $userLocation = geoip()->getLocation(geoip()->getClientIP());

        view()->share(['user' => \Auth::user(), 'userLocation' => $userLocation]);
    }

But when I test against this, they don't show up:

/** @test */
public function page_has_recent_reviews()
{
    $response = $this->get(route('home'));

    $response->assertSuccessful();

    $response->assertViewHasAll(['recentReviews', 'recentPhotos']);

    $data = $response->getOriginalContent()->getData();

    print_r(array_keys($data)); exit;

}

The dumped content contains:

Array
(
    [0] => recentReviews
    [1] => recentPhotos
)

But none of the data shared to the view. How does one test this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire