Input with '.' in name always triggers validation error in FormRequest #48630
-
Hi all, I'm writing a unit test for a class that maps a This is a simplified example: final class UpdateContactMapper
{
public static function map(UpdateContactRequest $request, string $id): Contact {
return new Contact(
Uuid::fromString($id),
$request->input('contact.name')
);
}
} It is declared in the Laravel docs that if you want to test something regarding requests, you probably should use something like I would like to only unit test if a request of a specific type gets mapped correctly to a specific domain object. To test if a mapper does its job correctly I write a test formed like this: $request = new UpdateContactRequest();
$request->merge([
'contact.name' => 'John'
]);
$id = '2e43a655-e24d-4de0-93f9-5e33b0c1f8ac';
$actual = UpdateContactMapper::map($request, $id);
$expected = new Contact(Uuid::fromString($id), 'John');
$this->assertEquals($expected, $actual); After a lot of debugging it looks like Laravel doesn't handle I've made a reproduction project where you can test it for yourself: I've added a few tests comparing the use of a name The request validation keeps complaining about missing the 'contact.name' field. Shouldn't I use a field name including a Thanks in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I am not sure, but maybe it has something to do with the dot notation which you can use to get a path to a certain parameter? it might expect something similar to: [
'contact'=> [
'name' => 'a name'
]
]; |
Beta Was this translation helpful? Give feedback.
I am not sure, but maybe it has something to do with the dot notation which you can use to get a path to a certain parameter?
it might expect something similar to: