Answer the question
In order to leave comments, you need to log in
What's wrong with parameters in HTTP testing?
Here is my test:
public function testGetDataGoodResponse()
{
$response = $this->call('GET', '/getdata', [
'inn' => mt_rand(1111111111, 9999999999),
'id' => mt_rand(11111111, 99999999) . '_0_' . mt_rand(111111111, 999999999),
]);
$response->assertStatus(200);
}
public function getData(Request $request)
{
dd($request->all());
$validator = Validator::make($request->all(), [
'inn' => 'required|numeric|digits:10',
'id' => 'required|string',
]);
if($validator->fails())
{
dd($validator->errors());
throw new \Exception('error inn or id');
}
}
>vendor\bin\phpunit
PHPUnit 7.5.2 by Sebastian Bergmann and contributors.
.[]
vendor\bin\phpunit
PHPUnit 7.5.2 by Sebastian Bergmann and contributors.
.Illuminate\Support\MessageBag {#208
#messages: array:2 [
"inn" => array:1 [
0 => "The inn field is required."
]
"id" => array:1 [
0 => "The id field is required."
]
]
#format: ":message"
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question