1 year agoby Vaibhav Jain

How to pass session key & value from controller to feature testing

I want to pass session key & value from controller to feature testing. So, I create a test function: public function test_Register() { // $request=new Request(); // Session::start(); //$request->session()->keep('username', 'email'); $value = session()->put('docmob','4561122337'); // dd(session('docmob')); $this->post('/doctor/_docfreg', 'f_name'=>null, 'l_name' => 'Jain', 'email'=>'vaibhavj1994@gmail.com', '_password' => '1234567', '_cpassword'=>'1234567', // '_token' => csrf_token(), )->assertSessionHasNoErrors(session('doc_id'));

		 It should be failed but the assertion is paased. 
		 vendor/bin/phpunit --filter=test_Register

PHPUnit 7.5.6 by Sebastian Bergmann and contributors.

. 1 / 1 (100%)

Time: 152 ms, Memory: 16 MB

OK (1 test, 1 assertion) Registeration Controller.php session()->put('docmob',$request->_mobile); $request->session()->keep('docmob'); So, my question is to how the session key & value passed from Registeration controller to test_Register??


Sarthak Shrivastava replied 1 year ago


Hey, firstly try to use code formal to write code here.

Now come to your question, I believe you are adding session on your controller. So in your test you does't need to create session, just make a post request to your endpoint and then assertSessionHas('yourKey')

Ask Question
Most Visited