Session id changed
Hi. I have trouble with testing my api.
$phone = '6876876876';
$this->json('post', route('api.client.login'), [
'phone' => $phone
]);
$this->json('post', route('api.client.login.confirm'), [
'phone' => $phone,
'code' => '12345678',
])->dump();
I need same session for both requests. How i can do it?
I tried to rewrite call method
public function setUp()
{
parent::setUp();
$this->session_id = session()->getId();
$this->session_cookie = [session()->getName() => $this->session_id];
}
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
$cookies = array_merge($cookies, $this->session_cookie);
parent::call($method, $uri, $parameters, $cookies, $files, $server, $content);
}
but it works only for $this->get() and other like this, not for $this->json()
I solved the problem. Ty for all...
Maybe someone will need it in the future
protected $session_id;
protected $session_cookie;
public function setUp()
{
parent::setUp();
$this->session_id = session()->getId();
$this->session_cookie = [session()->getName() => encrypt($this->session_id)];
}
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
$cookies = array_merge($cookies, $this->session_cookie);
return parent::call($method, $uri, $parameters, $cookies, $files, $server, $content);
}
the problem was in cookie. Laravel need cookie which they can decrypt. And our call method needed to return parent::call()
Please or to participate in this conversation.