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

Getting request input array different in actual vs testing #39069

Closed
lloricode opened this issue Oct 4, 2021 · 2 comments
Closed

Getting request input array different in actual vs testing #39069

lloricode opened this issue Oct 4, 2021 · 2 comments

Comments

@lloricode
Copy link
Contributor

lloricode commented Oct 4, 2021

  • Laravel Version: 8.62
  • PHP Version: 7.4.24
  • Database Driver & Version: mysql - 8.0.11 | sqlite 3.31.1

Description:

im using this feature #38832
works great, but when using testing environment, is not working

Steps To Reproduce:

# controller level
$this->validation($request, [
  'meta[name]' => 'nullable|string',
  'meta[keywords]' => 'nullable|string',
  'meta[description]' => 'nullable|string',
]);

ray($request->collect('meta'));

Getting data request

# using browser

// https://github.com/spatie/laravel-html
                    html()
                        ->text('meta[name]', $meta ? $meta->name : old('meta.name'))

                    html()
                        ->text('meta[keywords]', $meta ? $meta->keywords : old('meta.keywords'))
                
                    html()
                        ->textarea('meta[description]', $meta ? $meta->description : old('meta.description'))
                 
# ray results:
Illuminate\Support\Collection {#1950 ▼
  #items: array:3 [▼
    "name" => "aa"
    "keywords" => "bb"
    "description" => "ccc"
  ]
}
# testing with pestphp
    patch(route('admin.article.update', $article), [
        'category_ids' => [$article->categories->first()->getKey()],
        'title' => 'test xxx title',
        'content' => 'test xxxxx article',

        'meta[name]' => 'test meta title',
        'meta[keywords]' => 'test meta keywords',
        'meta[description]' => 'test meta description',
    ])

# ray results:
Illuminate\Support\Collection {#4077 ▼
  #items: []
}

Thank you

@lloricode lloricode changed the title Using collection request not working in testing environment Getting request input array different in actual vs testing Oct 4, 2021
@lloricode
Copy link
Contributor Author

It seems not collection problem, try to use input() still not same result between actual and tesing

            'meta' => [
                'name'=>$request->input('meta[name]'),
                'keywords'=>$request->input('meta[keywords]'),
                'description'=>$request->input('meta[description]'),
            ],

@lloricode
Copy link
Contributor Author

Fixes:

# data
$meta = $request->meta


# testing

    patch(route('admin.article.update', $article), [
        'category_ids' => [$article->categories->first()->getKey()],
        'title' => 'test xxx title',
        'content' => 'test xxxxx article',

        'meta' => [
            'name' => 'test meta title',
            'keywords' => 'test meta keywords',
            'description' => 'test meta description',
        ],
    ])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant