class TestResponse implements ArrayAccess mixin Response (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
Response $baseResponse

The response to delegate to.

Collection $exceptions

The collection of logged exceptions for the request.

protected string $streamedContent

The streamed content of the response.

Methods

$this
assertOk()

Assert that the response has a 200 "OK" status code.

$this
assertCreated()

Assert that the response has a 201 "Created" status code.

$this
assertAccepted()

Assert that the response has a 202 "Accepted" status code.

$this
assertNoContent(int $status = 204)

Assert that the response has the given status code and no content.

$this
assertMovedPermanently()

Assert that the response has a 301 "Moved Permanently" status code.

$this
assertFound()

Assert that the response has a 302 "Found" status code.

$this
assertBadRequest()

Assert that the response has a 400 "Bad Request" status code.

$this
assertUnauthorized()

Assert that the response has a 401 "Unauthorized" status code.

$this
assertPaymentRequired()

Assert that the response has a 402 "Payment Required" status code.

$this
assertForbidden()

Assert that the response has a 403 "Forbidden" status code.

$this
assertNotFound()

Assert that the response has a 404 "Not Found" status code.

$this
assertRequestTimeout()

Assert that the response has a 408 "Request Timeout" status code.

$this
assertConflict()

Assert that the response has a 409 "Conflict" status code.

$this
assertUnprocessable()

Assert that the response has a 422 "Unprocessable Entity" status code.

$this
assertTooManyRequests()

Assert that the response has a 429 "Too Many Requests" status code.

tap(callable|null $callback = null)

Call the given Closure with this instance then return the instance.

from  Tappable
static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $args)

Handle dynamic calls into macros or pass missing methods to the base response.

void
__construct(Response $response)

Create a new test response instance.

static TestResponse
fromBaseResponse(Response $response)

Create a new TestResponse from another response.

$this
assertSuccessful()

Assert that the response has a successful status code.

$this
assertServerError()

Assert that the response is a server error.

$this
assertStatus(int $status)

Assert that the response has the given status code.

string
statusMessageWithDetails(string|int $expected, string|int $actual)

Get an assertion message for a status assertion containing extra details when available.

$this
assertRedirect(string|null $uri = null)

Assert whether the response is redirecting to a given URI.

$this
assertRedirectContains(string $uri)

Assert whether the response is redirecting to a URI that contains the given URI.

$this
assertRedirectToRoute(string $name, mixed $parameters = [])

Assert whether the response is redirecting to a given route.

$this
assertRedirectToSignedRoute(string|null $name = null, mixed $parameters = [])

Assert whether the response is redirecting to a given signed route.

$this
assertHeader(string $headerName, mixed $value = null)

Asserts that the response contains the given header and equals the optional value.

$this
assertHeaderMissing(string $headerName)

Asserts that the response does not contain the given header.

$this
assertLocation(string $uri)

Assert that the current location header matches the given URI.

$this
assertDownload(string|null $filename = null)

Assert that the response offers a file download.

$this
assertPlainCookie(string $cookieName, mixed $value = null)

Asserts that the response contains the given cookie and equals the optional value.

$this
assertCookie(string $cookieName, mixed $value = null, bool $encrypted = true, bool $unserialize = false)

Asserts that the response contains the given cookie and equals the optional value.

$this
assertCookieExpired(string $cookieName)

Asserts that the response contains the given cookie and is expired.

$this
assertCookieNotExpired(string $cookieName)

Asserts that the response contains the given cookie and is not expired.

$this
assertCookieMissing(string $cookieName)

Asserts that the response does not contain the given cookie.

Cookie|null
getCookie(string $cookieName, bool $decrypt = true, bool $unserialize = false)

Get the given cookie from the response.

$this
assertContent(string $value)

Assert that the given string matches the response content.

$this
assertStreamedContent(string $value)

Assert that the given string matches the streamed response content.

$this
assertSee(string|array $value, bool $escape = true)

Assert that the given string or array of strings are contained within the response.

$this
assertSeeInOrder(array $values, bool $escape = true)

Assert that the given strings are contained in order within the response.

$this
assertSeeText(string|array $value, bool $escape = true)

Assert that the given string or array of strings are contained within the response text.

$this
assertSeeTextInOrder(array $values, bool $escape = true)

Assert that the given strings are contained in order within the response text.

$this
assertDontSee(string|array $value, bool $escape = true)

Assert that the given string or array of strings are not contained within the response.

$this
assertDontSeeText(string|array $value, bool $escape = true)

Assert that the given string or array of strings are not contained within the response text.

$this
assertJson(array|callable $value, bool $strict = false)

Assert that the response is a superset of the given JSON.

$this
assertJsonPath(string $path, mixed $expect)

Assert that the expected value and type exists at the given path in the response.

$this
assertExactJson(array $data)

Assert that the response has the exact given JSON.

$this
assertSimilarJson(array $data)

Assert that the response has the similar JSON as given.

$this
assertJsonFragment(array $data)

Assert that the response contains the given JSON fragment.

$this
assertJsonMissing(array $data, bool $exact = false)

Assert that the response does not contain the given JSON fragment.

$this
assertJsonMissingExact(array $data)

Assert that the response does not contain the exact JSON fragment.

$this
assertJsonMissingPath(string $path)

Assert that the response does not contain the given path.

$this
assertJsonStructure(array $structure = null, array|null $responseData = null)

Assert that the response has a given JSON structure.

$this
assertJsonCount(int $count, string|null $key = null)

Assert that the response JSON has the expected count of items at the given key.

$this
assertJsonValidationErrors(string|array $errors, string $responseKey = 'errors')

Assert that the response has the given JSON validation errors.

$this
assertJsonValidationErrorFor(string $key, string $responseKey = 'errors')

Assert the response has any JSON validation errors for the given key.

$this
assertJsonMissingValidationErrors(string|array|null $keys = null, string $responseKey = 'errors')

Assert that the response has no JSON validation errors for the given keys.

$this
assertJsonIsArray(string|null $key = null)

Assert that the given key is a JSON array.

$this
assertJsonIsObject(string|null $key = null)

Assert that the given key is a JSON object.

decodeResponseJson()

Validate and return the decoded response JSON.

mixed
json(string|null $key = null)

Validate and return the decoded response JSON.

collect(string|null $key = null)

Get the JSON decoded body of the response as a collection.

$this
assertViewIs(string $value)

Assert that the response view equals the given value.

$this
assertViewHas(string|array $key, mixed $value = null)

Assert that the response view has a given piece of bound data.

$this
assertViewHasAll(array $bindings)

Assert that the response view has a given list of bound data.

mixed
viewData(string $key)

Get a piece of data from the original view.

$this
assertViewMissing(string $key)

Assert that the response view is missing a piece of bound data.

$this
ensureResponseHasView()

Ensure that the response has a view as its original content.

bool
responseHasView()

Determine if the original response is a view.

$this
assertValid(string|array|null $keys = null, string $errorBag = 'default', string $responseKey = 'errors')

Assert that the given keys do not have validation errors.

$this
assertInvalid(string|array|null $errors = null, string $errorBag = 'default', string $responseKey = 'errors')

Assert that the response has the given validation errors.

$this
assertSessionHas(string|array $key, mixed $value = null)

Assert that the session has a given value.

$this
assertSessionHasAll(array $bindings)

Assert that the session has a given list of values.

$this
assertSessionHasInput(string|array $key, mixed $value = null)

Assert that the session has a given value in the flashed input array.

$this
assertSessionHasErrors(string|array $keys = [], mixed $format = null, string $errorBag = 'default')

Assert that the session has the given errors.

$this
assertSessionDoesntHaveErrors(string|array $keys = [], string|null $format = null, string $errorBag = 'default')

Assert that the session is missing the given errors.

$this
assertSessionHasNoErrors()

Assert that the session has no errors.

$this
assertSessionHasErrorsIn(string $errorBag, string|array $keys = [], mixed $format = null)

Assert that the session has the given errors.

$this
assertSessionMissing(string|array $key)

Assert that the session does not have a given key.

session()

Get the current session store.

never
dd()

Dump the content from the response and end the script.

never
ddHeaders()

Dump the headers from the response and end the script.

never
ddSession(string|array $keys = [])

Dump the session from the response and end the script.

$this
dump(string|null $key = null)

Dump the content from the response.

$this
dumpHeaders()

Dump the headers from the response.

$this
dumpSession(string|array $keys = [])

Dump the session from the response.

string
streamedContent()

Get the streamed content from the response.

$this
withExceptions(Collection $exceptions)

Set the previous exceptions on the response.

transformNotSuccessfulException(Throwable $exception)

This method is called when test method did not execute successfully.

appendExceptionToException(Throwable $exceptionToAppend, Throwable $exception)

Append an exception to the message of another exception.

appendErrorsToException(array $errors, Throwable $exception, bool $json = false)

Append errors to an exception message.

appendMessageToException(string $message, Throwable $exception)

Append a message to an exception.

mixed
__get(string $key)

Dynamically access base response parameters.

bool
__isset(string $key)

Proxy isset() checks to the underlying base response.

bool
offsetExists(string $offset)

Determine if the given offset exists.

mixed
offsetGet(string $offset)

Get the value for a given offset.

void
offsetSet(string $offset, mixed $value)

Set the value at the given offset.

void
offsetUnset(string $offset)

Unset the value at the given offset.

Details

$this assertOk()

Assert that the response has a 200 "OK" status code.

Return Value

$this

$this assertCreated()

Assert that the response has a 201 "Created" status code.

Return Value

$this

$this assertAccepted()

Assert that the response has a 202 "Accepted" status code.

Return Value

$this

$this assertNoContent(int $status = 204)

Assert that the response has the given status code and no content.

Parameters

int $status

Return Value

$this

$this assertMovedPermanently()

Assert that the response has a 301 "Moved Permanently" status code.

Return Value

$this

$this assertFound()

Assert that the response has a 302 "Found" status code.

Return Value

$this

$this assertBadRequest()

Assert that the response has a 400 "Bad Request" status code.

Return Value

$this

$this assertUnauthorized()

Assert that the response has a 401 "Unauthorized" status code.

Return Value

$this

$this assertPaymentRequired()

Assert that the response has a 402 "Payment Required" status code.

Return Value

$this

$this assertForbidden()

Assert that the response has a 403 "Forbidden" status code.

Return Value

$this

$this assertNotFound()

Assert that the response has a 404 "Not Found" status code.

Return Value

$this

$this assertRequestTimeout()

Assert that the response has a 408 "Request Timeout" status code.

Return Value

$this

$this assertConflict()

Assert that the response has a 409 "Conflict" status code.

Return Value

$this

$this assertUnprocessable()

Assert that the response has a 422 "Unprocessable Entity" status code.

Return Value

$this

$this assertTooManyRequests()

Assert that the response has a 429 "Too Many Requests" status code.

Return Value

$this

$this|HigherOrderTapProxy tap(callable|null $callback = null)

Call the given Closure with this instance then return the instance.

Parameters

callable|null $callback

Return Value

$this|HigherOrderTapProxy

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $args)

Handle dynamic calls into macros or pass missing methods to the base response.

Parameters

string $method
array $args

Return Value

mixed

void __construct(Response $response)

Create a new test response instance.

Parameters

Response $response

Return Value

void

static TestResponse fromBaseResponse(Response $response)

Create a new TestResponse from another response.

Parameters

Response $response

Return Value

TestResponse

$this assertSuccessful()

Assert that the response has a successful status code.

Return Value

$this

$this assertServerError()

Assert that the response is a server error.

Return Value

$this

$this assertStatus(int $status)

Assert that the response has the given status code.

Parameters

int $status

Return Value

$this

protected string statusMessageWithDetails(string|int $expected, string|int $actual)

Get an assertion message for a status assertion containing extra details when available.

Parameters

string|int $expected
string|int $actual

Return Value

string

$this assertRedirect(string|null $uri = null)

Assert whether the response is redirecting to a given URI.

Parameters

string|null $uri

Return Value

$this

$this assertRedirectContains(string $uri)

Assert whether the response is redirecting to a URI that contains the given URI.

Parameters

string $uri

Return Value

$this

$this assertRedirectToRoute(string $name, mixed $parameters = [])

Assert whether the response is redirecting to a given route.

Parameters

string $name
mixed $parameters

Return Value

$this

$this assertRedirectToSignedRoute(string|null $name = null, mixed $parameters = [])

Assert whether the response is redirecting to a given signed route.

Parameters

string|null $name
mixed $parameters

Return Value

$this

$this assertHeader(string $headerName, mixed $value = null)

Asserts that the response contains the given header and equals the optional value.

Parameters

string $headerName
mixed $value

Return Value

$this

$this assertHeaderMissing(string $headerName)

Asserts that the response does not contain the given header.

Parameters

string $headerName

Return Value

$this

$this assertLocation(string $uri)

Assert that the current location header matches the given URI.

Parameters

string $uri

Return Value

$this

$this assertDownload(string|null $filename = null)

Assert that the response offers a file download.

Parameters

string|null $filename

Return Value

$this

$this assertPlainCookie(string $cookieName, mixed $value = null)

Asserts that the response contains the given cookie and equals the optional value.

Parameters

string $cookieName
mixed $value

Return Value

$this

$this assertCookie(string $cookieName, mixed $value = null, bool $encrypted = true, bool $unserialize = false)

Asserts that the response contains the given cookie and equals the optional value.

Parameters

string $cookieName
mixed $value
bool $encrypted
bool $unserialize

Return Value

$this

$this assertCookieExpired(string $cookieName)

Asserts that the response contains the given cookie and is expired.

Parameters

string $cookieName

Return Value

$this

$this assertCookieNotExpired(string $cookieName)

Asserts that the response contains the given cookie and is not expired.

Parameters

string $cookieName

Return Value

$this

$this assertCookieMissing(string $cookieName)

Asserts that the response does not contain the given cookie.

Parameters

string $cookieName

Return Value

$this

Cookie|null getCookie(string $cookieName, bool $decrypt = true, bool $unserialize = false)

Get the given cookie from the response.

Parameters

string $cookieName
bool $decrypt
bool $unserialize

Return Value

Cookie|null

$this assertContent(string $value)

Assert that the given string matches the response content.

Parameters

string $value

Return Value

$this

$this assertStreamedContent(string $value)

Assert that the given string matches the streamed response content.

Parameters

string $value

Return Value

$this

$this assertSee(string|array $value, bool $escape = true)

Assert that the given string or array of strings are contained within the response.

Parameters

string|array $value
bool $escape

Return Value

$this

$this assertSeeInOrder(array $values, bool $escape = true)

Assert that the given strings are contained in order within the response.

Parameters

array $values
bool $escape

Return Value

$this

$this assertSeeText(string|array $value, bool $escape = true)

Assert that the given string or array of strings are contained within the response text.

Parameters

string|array $value
bool $escape

Return Value

$this

$this assertSeeTextInOrder(array $values, bool $escape = true)

Assert that the given strings are contained in order within the response text.

Parameters

array $values
bool $escape

Return Value

$this

$this assertDontSee(string|array $value, bool $escape = true)

Assert that the given string or array of strings are not contained within the response.

Parameters

string|array $value
bool $escape

Return Value

$this

$this assertDontSeeText(string|array $value, bool $escape = true)

Assert that the given string or array of strings are not contained within the response text.

Parameters

string|array $value
bool $escape

Return Value

$this

$this assertJson(array|callable $value, bool $strict = false)

Assert that the response is a superset of the given JSON.

Parameters

array|callable $value
bool $strict

Return Value

$this

$this assertJsonPath(string $path, mixed $expect)

Assert that the expected value and type exists at the given path in the response.

Parameters

string $path
mixed $expect

Return Value

$this

$this assertExactJson(array $data)

Assert that the response has the exact given JSON.

Parameters

array $data

Return Value

$this

$this assertSimilarJson(array $data)

Assert that the response has the similar JSON as given.

Parameters

array $data

Return Value

$this

$this assertJsonFragment(array $data)

Assert that the response contains the given JSON fragment.

Parameters

array $data

Return Value

$this

$this assertJsonMissing(array $data, bool $exact = false)

Assert that the response does not contain the given JSON fragment.

Parameters

array $data
bool $exact

Return Value

$this

$this assertJsonMissingExact(array $data)

Assert that the response does not contain the exact JSON fragment.

Parameters

array $data

Return Value

$this

$this assertJsonMissingPath(string $path)

Assert that the response does not contain the given path.

Parameters

string $path

Return Value

$this

$this assertJsonStructure(array $structure = null, array|null $responseData = null)

Assert that the response has a given JSON structure.

Parameters

array $structure
array|null $responseData

Return Value

$this

$this assertJsonCount(int $count, string|null $key = null)

Assert that the response JSON has the expected count of items at the given key.

Parameters

int $count
string|null $key

Return Value

$this

$this assertJsonValidationErrors(string|array $errors, string $responseKey = 'errors')

Assert that the response has the given JSON validation errors.

Parameters

string|array $errors
string $responseKey

Return Value

$this

$this assertJsonValidationErrorFor(string $key, string $responseKey = 'errors')

Assert the response has any JSON validation errors for the given key.

Parameters

string $key
string $responseKey

Return Value

$this

$this assertJsonMissingValidationErrors(string|array|null $keys = null, string $responseKey = 'errors')

Assert that the response has no JSON validation errors for the given keys.

Parameters

string|array|null $keys
string $responseKey

Return Value

$this

$this assertJsonIsArray(string|null $key = null)

Assert that the given key is a JSON array.

Parameters

string|null $key

Return Value

$this

$this assertJsonIsObject(string|null $key = null)

Assert that the given key is a JSON object.

Parameters

string|null $key

Return Value

$this

AssertableJsonString decodeResponseJson()

Validate and return the decoded response JSON.

Return Value

AssertableJsonString

Exceptions

Throwable

mixed json(string|null $key = null)

Validate and return the decoded response JSON.

Parameters

string|null $key

Return Value

mixed

Collection collect(string|null $key = null)

Get the JSON decoded body of the response as a collection.

Parameters

string|null $key

Return Value

Collection

$this assertViewIs(string $value)

Assert that the response view equals the given value.

Parameters

string $value

Return Value

$this

$this assertViewHas(string|array $key, mixed $value = null)

Assert that the response view has a given piece of bound data.

Parameters

string|array $key
mixed $value

Return Value

$this

$this assertViewHasAll(array $bindings)

Assert that the response view has a given list of bound data.

Parameters

array $bindings

Return Value

$this

mixed viewData(string $key)

Get a piece of data from the original view.

Parameters

string $key

Return Value

mixed

$this assertViewMissing(string $key)

Assert that the response view is missing a piece of bound data.

Parameters

string $key

Return Value

$this

protected $this ensureResponseHasView()

Ensure that the response has a view as its original content.

Return Value

$this

protected bool responseHasView()

Determine if the original response is a view.

Return Value

bool

$this assertValid(string|array|null $keys = null, string $errorBag = 'default', string $responseKey = 'errors')

Assert that the given keys do not have validation errors.

Parameters

string|array|null $keys
string $errorBag
string $responseKey

Return Value

$this

$this assertInvalid(string|array|null $errors = null, string $errorBag = 'default', string $responseKey = 'errors')

Assert that the response has the given validation errors.

Parameters

string|array|null $errors
string $errorBag
string $responseKey

Return Value

$this

$this assertSessionHas(string|array $key, mixed $value = null)

Assert that the session has a given value.

Parameters

string|array $key
mixed $value

Return Value

$this

$this assertSessionHasAll(array $bindings)

Assert that the session has a given list of values.

Parameters

array $bindings

Return Value

$this

$this assertSessionHasInput(string|array $key, mixed $value = null)

Assert that the session has a given value in the flashed input array.

Parameters

string|array $key
mixed $value

Return Value

$this

$this assertSessionHasErrors(string|array $keys = [], mixed $format = null, string $errorBag = 'default')

Assert that the session has the given errors.

Parameters

string|array $keys
mixed $format
string $errorBag

Return Value

$this

$this assertSessionDoesntHaveErrors(string|array $keys = [], string|null $format = null, string $errorBag = 'default')

Assert that the session is missing the given errors.

Parameters

string|array $keys
string|null $format
string $errorBag

Return Value

$this

$this assertSessionHasNoErrors()

Assert that the session has no errors.

Return Value

$this

$this assertSessionHasErrorsIn(string $errorBag, string|array $keys = [], mixed $format = null)

Assert that the session has the given errors.

Parameters

string $errorBag
string|array $keys
mixed $format

Return Value

$this

$this assertSessionMissing(string|array $key)

Assert that the session does not have a given key.

Parameters

string|array $key

Return Value

$this

protected Store session()

Get the current session store.

Return Value

Store

never dd()

Dump the content from the response and end the script.

Return Value

never

never ddHeaders()

Dump the headers from the response and end the script.

Return Value

never

never ddSession(string|array $keys = [])

Dump the session from the response and end the script.

Parameters

string|array $keys

Return Value

never

$this dump(string|null $key = null)

Dump the content from the response.

Parameters

string|null $key

Return Value

$this

$this dumpHeaders()

Dump the headers from the response.

Return Value

$this

$this dumpSession(string|array $keys = [])

Dump the session from the response.

Parameters

string|array $keys

Return Value

$this

string streamedContent()

Get the streamed content from the response.

Return Value

string

$this withExceptions(Collection $exceptions)

Set the previous exceptions on the response.

Parameters

Collection $exceptions

Return Value

$this

Throwable transformNotSuccessfulException(Throwable $exception)

This method is called when test method did not execute successfully.

Parameters

Throwable $exception

Return Value

Throwable

protected Throwable appendExceptionToException(Throwable $exceptionToAppend, Throwable $exception)

Append an exception to the message of another exception.

Parameters

Throwable $exceptionToAppend
Throwable $exception

Return Value

Throwable

protected Throwable appendErrorsToException(array $errors, Throwable $exception, bool $json = false)

Append errors to an exception message.

Parameters

array $errors
Throwable $exception
bool $json

Return Value

Throwable

protected Throwable appendMessageToException(string $message, Throwable $exception)

Append a message to an exception.

Parameters

string $message
Throwable $exception

Return Value

Throwable

mixed __get(string $key)

Dynamically access base response parameters.

Parameters

string $key

Return Value

mixed

bool __isset(string $key)

Proxy isset() checks to the underlying base response.

Parameters

string $key

Return Value

bool

bool offsetExists(string $offset)

Determine if the given offset exists.

Parameters

string $offset

Return Value

bool

mixed offsetGet(string $offset)

Get the value for a given offset.

Parameters

string $offset

Return Value

mixed

void offsetSet(string $offset, mixed $value)

Set the value at the given offset.

Parameters

string $offset
mixed $value

Return Value

void

Exceptions

LogicException

void offsetUnset(string $offset)

Unset the value at the given offset.

Parameters

string $offset

Return Value

void

Exceptions

LogicException