trait Illuminate / Foundation / Testing / Concerns / MakesHttpRequests
You are viewing an older version of the documentation. For the latest, please visit master documentation.

MakesHttpRequests

Properties

protected

$defaultHeaders array

Additional headers for the request.

Default: []
protected

$defaultCookies array

Additional cookies for the request.

Default: []
protected

$unencryptedCookies array

Additional cookies will not be encrypted for the request.

Default: []
protected

$serverVariables array

Additional server variables for the request.

Default: []
protected

$followRedirects bool

Indicates whether redirects should be followed.

Default: false
protected

$encryptCookies bool

Indicates whether cookies should be encrypted.

Default: true
protected

$withCredentials bool

Indicated whether JSON requests should be performed "with credentials" (cookies).

Default: false

Methods

public

withHeaders ( array $headers ) : $this

Define additional headers to be sent with the request.

Parameters

  • $headers array
public

withHeader ( string $name , string $value ) : $this

Add a header to be sent with the request.

Parameters

  • $name string
  • $value string
public

withToken ( string $token , string $type ) : $this

Add an authorization token for the request.

Parameters

  • $token string
  • $type string
public

flushHeaders ( ) : $this

Flush all the configured headers.

public

withServerVariables ( array $server ) : $this

Define a set of server variables to be sent with the requests.

Parameters

  • $server array
public

withoutMiddleware ( $middleware ) : $this

Disable middleware for the test.

Parameters

  • $middleware string|array|null
public

withMiddleware ( $middleware ) : $this

Enable the given middleware for the test.

Parameters

  • $middleware string|array|null
public

withCookies ( array $cookies ) : $this

Define additional cookies to be sent with the request.

Parameters

  • $cookies array
public

withCookie ( string $name , string $value ) : $this

Add a cookie to be sent with the request.

Parameters

  • $name string
  • $value string
public

withUnencryptedCookies ( array $cookies ) : $this

Define additional cookies will not be encrypted before sending with the request.

Parameters

  • $cookies array
public

withUnencryptedCookie ( string $name , string $value ) : $this

Add a cookie will not be encrypted before sending with the request.

Parameters

  • $name string
  • $value string
public

followingRedirects ( ) : $this

Automatically follow any redirects returned from the response.

public

withCredentials ( ) : $this

Include cookies and authorization headers for JSON requests.

public

disableCookieEncryption ( ) : $this

Disable automatic encryption of cookie values.

public

from ( string $url ) : $this

Set the referer header and previous URL session value in order to simulate a previous request.

Parameters

  • $url string
public

get ( $uri , array $headers ) : TestResponse

Visit the given URI with a GET request.

Parameters

  • $uri string
  • $headers array
public

getJson ( $uri , array $headers ) : TestResponse

Visit the given URI with a GET request, expecting a JSON response.

Parameters

  • $uri string
  • $headers array
public

post ( $uri , array $data , array $headers ) : TestResponse

Visit the given URI with a POST request.

Parameters

  • $uri string
  • $data array
  • $headers array
public

postJson ( $uri , array $data , array $headers ) : TestResponse

Visit the given URI with a POST request, expecting a JSON response.

Parameters

  • $uri string
  • $data array
  • $headers array
public

put ( $uri , array $data , array $headers ) : TestResponse

Visit the given URI with a PUT request.

Parameters

  • $uri string
  • $data array
  • $headers array
public

putJson ( $uri , array $data , array $headers ) : TestResponse

Visit the given URI with a PUT request, expecting a JSON response.

Parameters

  • $uri string
  • $data array
  • $headers array
public

patch ( $uri , array $data , array $headers ) : TestResponse

Visit the given URI with a PATCH request.

Parameters

  • $uri string
  • $data array
  • $headers array
public

patchJson ( $uri , array $data , array $headers ) : TestResponse

Visit the given URI with a PATCH request, expecting a JSON response.

Parameters

  • $uri string
  • $data array
  • $headers array
public

delete ( $uri , array $data , array $headers ) : TestResponse

Visit the given URI with a DELETE request.

Parameters

  • $uri string
  • $data array
  • $headers array
public

deleteJson ( $uri , array $data , array $headers ) : TestResponse

Visit the given URI with a DELETE request, expecting a JSON response.

Parameters

  • $uri string
  • $data array
  • $headers array
public

options ( $uri , array $data , array $headers ) : TestResponse

Visit the given URI with an OPTIONS request.

Parameters

  • $uri string
  • $data array
  • $headers array
public

optionsJson ( $uri , array $data , array $headers ) : TestResponse

Visit the given URI with an OPTIONS request, expecting a JSON response.

Parameters

  • $uri string
  • $data array
  • $headers array
public

json ( $method , $uri , array $data , array $headers ) : TestResponse

Call the given URI with a JSON request.

Parameters

  • $method string
  • $uri string
  • $data array
  • $headers array
public

call ( $method , $uri , $parameters , $cookies , $files , $server , $content ) : TestResponse

Call the given URI and return the Response.

Parameters

  • $method string
  • $uri string
  • $parameters array
  • $cookies array
  • $files array
  • $server array
  • $content string|null
protected

prepareUrlForRequest ( $uri ) : string

Turn the given URI into a fully qualified URL.

Parameters

  • $uri string
protected

transformHeadersToServerVars ( array $headers ) : array

Transform headers array to array of $SERVER vars with HTTP* format.

Parameters

  • $headers array
protected

formatServerHeaderKey ( $name ) : string

Format the header name for the server array.

Parameters

  • $name string
protected

extractFilesFromDataArray ( $data ) : array

Extract the file uploads from the given data array.

Parameters

  • $data array
protected

prepareCookiesForRequest ( ) : array

If enabled, encrypt cookie values for request.

protected

prepareCookiesForJsonRequest ( ) : array

If enabled, add cookies for JSON requests.

protected

followRedirects ( $response ) : Response |TestResponse

Follow a redirect chain until a non-redirect is received.

Parameters

protected

createTestResponse ( $response ) : TestResponse

Create the test response instance from the given response.

Parameters