Unit test Laravel middleware -


i trying write unit tests middleware in laravel. know tutorial, or have example of ?

i have been writing lot of code, there must better way test handle method.

using laravel 5.2, unit testing middleware passing request input , closure assertions.

so have middleware class getcommandfromslack parses first word of text field in post (the text slack slash command) new field called command, modifies text field not have first word more. has 1 method following signature: public function handle(\illuminate\http\request $request, closure $next).

my test case looks this:

use app\http\middleware\getcommandfromslack; use illuminate\http\request;  class commandsfromslacktest extends testcase {   public function testshouldknowliftcommand()   {     $request = new illuminate\http\request();     $request->replace([         'text' => 'lift foo bar baz',     ]);     $mw = new \app\http\middleware\getcommandfromslack;     $mw->handle($request,function($r) use ($after){       $this->assertequals('lift',       $r->input('command'));       $this->assertequals('foo bar baz',$r->input('text'));     });   } } 

i hope helps! i'll try update if more complicated middleware working.


Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -