Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 21, 2017
1 parent ee30e8b commit c32418e
Showing 1 changed file with 38 additions and 49 deletions.
87 changes: 38 additions & 49 deletions src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit c32418e

Please sign in to comment.