createMock(Request::class); $instance = new Handler($this->createMock(Container::class)); $class = new \ReflectionClass(Handler::class); $method = $class->getMethod('render'); $method->setAccessible(true); $response = $method->invokeArgs($instance, [$request, $this->createMock($exception)]); $this->assertInstanceOf(JsonResponse::class, $response); $response = \Illuminate\Testing\TestResponse::fromBaseResponse($response); $response->assertStatus(400) ->assertJsonStructure([ 'message' ]); } /** * Provide Valid data for validation test */ public function provideExceptionsforBadRequest() : array { return [ [ '\App\Exceptions\InvalidOtpParameterException' ], [ '\App\Exceptions\InvalidQrCodeException' ], [ '\App\Exceptions\InvalidSecretException' ], [ '\App\Exceptions\DbEncryptionException' ], ]; } /** * @test * * @dataProvider provideExceptionsforNotFound */ public function test_exceptions_returns_notFound_json_response($exception) { $request = $this->createMock(Request::class); $instance = new Handler($this->createMock(Container::class)); $class = new \ReflectionClass(Handler::class); $method = $class->getMethod('render'); $method->setAccessible(true); $response = $method->invokeArgs($instance, [$request, $this->createMock($exception)]); $this->assertInstanceOf(JsonResponse::class, $response); $response = \Illuminate\Testing\TestResponse::fromBaseResponse($response); $response->assertStatus(404) ->assertJsonStructure([ 'message' ]); } /** * Provide Valid data for validation test */ public function provideExceptionsforNotFound() : array { return [ [ '\Illuminate\Database\Eloquent\ModelNotFoundException' ], [ '\Symfony\Component\HttpKernel\Exception\NotFoundHttpException' ], ]; } }