diff --git a/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php b/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php index a78234470fc7..059aa48b6d57 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php +++ b/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php @@ -12,93 +12,93 @@ trait MakesHttpRequests { /** - * Additional server variables for the request. + * Additional headers for the request. * * @var array */ - protected $serverVariables = []; + protected $defaultHeaders = []; /** - * Additional headers for the request. + * Additional server variables for the request. * * @var array */ - protected $defaultHeaders = []; + protected $serverVariables = []; /** - * Define a set of server variables to be sent with the requests. + * Define additional headers to be sent with the request. * - * @param array $server + * @param array $headers * @return $this */ - public function withServerVariables(array $server) + public function withHeaders(array $headers) { - $this->serverVariables = $server; + $this->defaultHeaders = array_merge($this->defaultHeaders, $headers); return $this; } /** - * Disable middleware for the test. + * Add a header to be sent with the request. * - * @param string|array $middleware + * @param string $name + * @param string $value * @return $this */ - public function withoutMiddleware($middleware = null) + public function withHeader(string $name, string $value) { - if (is_null($middleware)) { - $this->app->instance('middleware.disable', true); - - return $this; - } - - foreach ((array) $middleware as $abstract) { - $this->app->instance($abstract, new class { - public function handle($request, $next) - { - return $next($request); - } - }); - } + $this->defaultHeaders[$name] = $value; return $this; } /** - * Define a set of headers to be sent with the requests. + * Flush all the configured headers. * - * @param array $headers * @return $this */ - public function withHeaders(array $headers) + public function flushHeaders() { - $this->defaultHeaders = $headers; + $this->defaultHeaders = []; return $this; } /** - * Adds a header to be sent with the requests. + * Define a set of server variables to be sent with the requests. * - * @param string $name - * @param string $value + * @param array $server * @return $this */ - public function withHeader(string $name, string $value) + public function withServerVariables(array $server) { - $this->defaultHeaders[$name] = $value; + $this->serverVariables = $server; return $this; } /** - * Removes all the predefined headers to be sent with the requests. + * Disable middleware for the test. * + * @param string|array $middleware * @return $this */ - public function cleanHeaders() + public function withoutMiddleware($middleware = null) { - $this->defaultHeaders = []; + if (is_null($middleware)) { + $this->app->instance('middleware.disable', true); + + return $this; + } + + foreach ((array) $middleware as $abstract) { + $this->app->instance($abstract, new class { + public function handle($request, $next) + { + return $next($request); + } + }); + } return $this; } @@ -326,24 +326,13 @@ protected function prepareUrlForRequest($uri) */ protected function transformHeadersToServerVars(array $headers) { - return collect($this->mergeDefaultHeaders($headers))->mapWithKeys(function ($value, $name) { + return collect(array_merge($this->defaultHeaders, $headers))->mapWithKeys(function ($value, $name) { $name = strtr(strtoupper($name), '-', '_'); return [$this->formatServerHeaderKey($name) => $value]; })->all(); } - /** - * Merges the given headers and the default request headers. - * - * @param array $headers - * @return array - */ - protected function mergeDefaultHeaders(array $headers) - { - return array_merge($headers, $this->defaultHeaders); - } - /** * Format the header name for the server array. *