What I usually do is dd($response); and then look for the key and value I need and when I found it I make the assertion.
Jan 8, 2021
4
Level 6
test add ip server with local method
I wanted to test this method with a feature test:
public function getTask(Request $requestSvr)
{
$requestSvr->all();
$requestSvr['id_server'] = (string) $requestSvr['id_server'];
$task = Task::whereIn('works', $requestSvr['task_available'])->where('process_status','=','new')->first();
if(!empty($task))
{
$task->process_status = 'processing';
$task->id_server = $requestSvr['id_server'];
if(!empty($requestSvr->server('SERVER_ADDR')))
{
$task->ip_server = (string) $requestSvr->server('SERVER_ADDR');
}
$task->save();
return response()->json($task, 200);
}
else
{
return response()->json([], 204);
}
}
doing the test locally I would not know how to verify that ip_server is entered
I would like to test it as follows:
//so he simulated the server call $requestSvr1 = [ "id_server" => server_1', "task_available" => ["A","B"] ];
$response = $this->put('/api/get_task',$requestSvr1);
$ja = Task::find($response['id']);
//this FAIL $response->server('SERVER_ADDR') is empty
$this->assertSame($response->server('SERVER_ADDR'),$ja['ip_server']);
this $requestSvr->server ('SERVER_ADDR') value is null. It will only ever be null locally.
how could I test such a thing?
Please or to participate in this conversation.