diff --git a/composer.json b/composer.json index c015635..4701c6a 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "php": "^7.3 || ^8.0", "illuminate/contracts": "^6.0 || ^7.0 || ^8.0 || ^9.0", "illuminate/http": "^6.0 || ^7.0 || ^8.0 || ^9.0", - "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0" + "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "lmc/http-constants": "^1.2" }, "require-dev": { "orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0", diff --git a/src/Middlewares/SetHeaderMiddleware.php b/src/Middlewares/SetHeaderMiddleware.php index ad8f00d..478c186 100644 --- a/src/Middlewares/SetHeaderMiddleware.php +++ b/src/Middlewares/SetHeaderMiddleware.php @@ -3,12 +3,19 @@ namespace DragonCode\LaravelJsonResponse\Middlewares; use Closure; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Lmc\HttpConstants\Header; class SetHeaderMiddleware { - public function handle(Request $request, Closure $next) + /** + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * + * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response + */ + public function handle(Request $request, Closure $next): JsonResponse { /** @var \Illuminate\Http\Response $response */ $response = $next($request); diff --git a/tests/Middlewares/SetHeaderMiddlewareTest.php b/tests/Middlewares/SetHeaderMiddlewareTest.php index 2819c56..55c0352 100644 --- a/tests/Middlewares/SetHeaderMiddlewareTest.php +++ b/tests/Middlewares/SetHeaderMiddlewareTest.php @@ -2,6 +2,7 @@ namespace Tests\Middlewares; +use Lmc\HttpConstants\Header; use Tests\TestCase; class SetHeaderMiddlewareTest extends TestCase @@ -11,7 +12,7 @@ public function testWeb(): void $this ->get('web') ->assertSuccessful() - ->assertHeader('Accept', 'application/json') + ->assertHeader(Header::ACCEPT, 'application/json') ->assertJsonStructure(['data']) ->assertJson(['data' => 'Hello, JSON!']); } @@ -21,7 +22,7 @@ public function testApi(): void $this ->get('api') ->assertSuccessful() - ->assertHeader('Accept', 'application/json') + ->assertHeader(Header::ACCEPT, 'application/json') ->assertJsonStructure(['data']) ->assertJson(['data' => 'Hello, JSON!']); }