Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Add support for nested arrays with `assertViewHas` #30837

Merged
merged 4 commits into from Dec 16, 2019

Conversation

@owenconti
Copy link
Contributor

owenconti commented Dec 13, 2019

This PR adds nested array support to the assertViewHas method.

Here's an example of the before/after usage:

// controller

return Inertia::render('PageComponent', [
    'user_name' => 'John Doe'
]);

Testing before PR:

// test class

$this->get('/page')
    ->assertViewHas('page', [
        'component' => 'PageComponent',
        'url' => '/page',
        'version' => null,
        'props' => [
            'user_name' => 'John Doe'
        ]
    ]);

Testing after PR:

$this->get('/page')
    ->assertViewHas('page.props', [
        'user_name' => 'John Doe'
    ]);

So in this example, I'm using Inertia to render a page. Inertia attaches multiple "props" to the page key passed to the view. I only really care to test that the data I returned from my controller is set correctly.

I think this could be useful for usage outside of Inertia as well, where a controller may return nested data to a view and a test wants to pick out a nested key.

I've also added a couple extra tests that were missing for assertViewHas.

@GrahamCampbell GrahamCampbell changed the title Add support for nested arrays with `assertViewHas`. [6.x] Add support for nested arrays with `assertViewHas` Dec 14, 2019
@taylorotwell taylorotwell merged commit a53d4a2 into laravel:6.x Dec 16, 2019
2 checks passed
2 checks passed
continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.