potentdevelopment's avatar

Error When Running Unit Test Of Middleware

Hello,

I wrote a unit test and to test a middleware, when I run the test, this is the error showing in the console.

• Tests\Unit\MAMiddlewareTest > token failed status not authorized
   Illuminate\Contracts\Container\BindingResolutionException 

  Target [Illuminate\Contracts\Routing\ResponseFactory] is not instantiable.

Here is the test that I wrote.

public function token_failed_status_not_authorized() {
        $token = "ma-page-access";
        $request = Request::create('/test', 'GET');
        $request->query->add(['token' => $token]);
        $middleware = new MyAccountAccessCheckMiddleware;
        
        $response = $middleware->handle($request, function () {});
        $this->assertEquals($response->getStatusCode(), 200);
    }
0 likes
2 replies
Tray2's avatar

Why don't you just use a feature test to check that instead?

Something like

$this->get('/test', $token)
	->assertSuccess():

Please or to participate in this conversation.