Answer the question
In order to leave comments, you need to log in
How to write tests for a controller method in LARAVEL?
There is a method in the controller:
public function sendVeryficationEmail(Request $request) {
return $request->input('name');
}
$response = $this->call('post', '/user/registerrequest',['name'=>'VasyaPupkin']);
Answer the question
In order to leave comments, you need to log in
You can simply create a controller instance and call the method with a parameter.
$controller = new My\Controller();
$request = Request::create('/', 'GET', ['name' => 'test']);
$this->assertEquals('test', $controller->sendVeryficationEmail($request));
$request = \Mockery::mock(Request::class);
$request->shouldReceive('input')->once()->andReturn('VasyaPupkin');
$continer->instance(Request::class, $request);
$response = $this->call('post', '/user/registerrequest');
$this->assertEquals('VasyaPupkin', $response);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question