TestResponse
class TestResponse implements ArrayAccess mixin TResponse mixin Response
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| Request|null | $baseRequest | The original request. |
|
| TResponse | $baseResponse | The response to delegate to. |
|
| Collection | $exceptions | The collection of logged exceptions for the request. |
|
| protected string|null | $streamedContent | The streamed content of the response. |
|
| protected AssertableJsonString|null | $decodedResponseJson | The decoded response JSON. |
Methods
Assert that the response has a 200 "OK" status code.
Assert that the response has a 201 "Created" status code.
Assert that the response has a 202 "Accepted" status code.
Assert that the response has the given status code and no content.
Assert that the response has a 301 "Moved Permanently" status code.
Assert that the response has a 302 "Found" status code.
Assert that the response has a 304 "Not Modified" status code.
Assert that the response has a 307 "Temporary Redirect" status code.
Assert that the response has a 308 "Permanent Redirect" status code.
Assert that the response has a 400 "Bad Request" status code.
Assert that the response has a 401 "Unauthorized" status code.
Assert that the response has a 402 "Payment Required" status code.
Assert that the response has a 403 "Forbidden" status code.
Assert that the response has a 404 "Not Found" status code.
Assert that the response has a 405 "Method Not Allowed" status code.
Assert that the response has a 406 "Not Acceptable" status code.
Assert that the response has a 408 "Request Timeout" status code.
Assert that the response has a 409 "Conflict" status code.
Assert that the response has a 410 "Gone" status code.
Assert that the response has a 415 "Unsupported Media Type" status code.
Assert that the response has a 422 "Unprocessable Content" status code.
Assert that the response has a 424 "Failed Dependency" status code.
Assert that the response has a 429 "Too Many Requests" status code.
Assert that the response has a 500 "Internal Server Error" status code.
Assert that the response has a 503 "Service Unavailable" status code.
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Dump the content from the response.
Call the given Closure with this instance then return the instance.
Mix another object into the class.
Dynamically handle calls to the class.
Handle dynamic calls into macros or pass missing methods to the base response.
Create a new TestResponse from another response.
Assert that the response has a successful status code.
Assert that the Precognition request was successful.
Assert that the response is a client error.
Assert that the response is a server error.
Assert that the response has the given status code.
Get an assertion message for a status assertion containing extra details when available.
Assert whether the response is redirecting to a given URI.
Assert whether the response is redirecting to a URI that contains the given URI.
Assert whether the response is redirecting back to the previous location.
Assert whether the response is redirecting back to the previous location with the given errors in the session.
Assert whether the response is redirecting back to the previous location with no errors in the session.
Assert whether the response is redirecting to a given route.
Assert whether the response is redirecting to a given signed route.
Assert whether the response is redirecting to a given controller action.
Asserts that the response contains the given header and equals the optional value.
Asserts that the response contains the given header and that its value contains the given string.
Asserts that the response does not contain the given header.
Assert that the current location header matches the given URI.
Assert that the response offers a file download.
Asserts that the response contains the given cookie and equals the optional value.
Asserts that the response contains the given cookie and equals the optional value.
Asserts that the response contains the given cookie and is expired.
Asserts that the response contains the given cookie and is not expired.
Asserts that the response does not contain the given cookie.
Get the given cookie from the response.
Assert that the given string matches the response content.
Assert that the response was streamed.
Assert that the response was not streamed.
Assert that the given string matches the streamed response content.
Assert that the given array matches the streamed JSON response content.
Assert that the given string or array of strings are contained within the response.
Assert that the given HTML string or array of HTML strings are contained within the response.
Assert that the given strings are contained in order within the response.
Assert that the given HTML strings are contained in order within the response.
Assert that the given string or array of strings are contained within the response text.
Assert that the given strings are contained in order within the response text.
Assert that the given string or array of strings are not contained within the response.
Assert that the given HTML string or array of HTML strings are not contained within the response.
Assert that the given string or array of strings are not contained within the response text.
Assert that the response is a superset of the given JSON.
Assert that the expected value and type exists at the given path in the response.
Assert that the expected values and types exist at the given paths in the response.
Assert that the given paths in the response contain all of the expected values without looking at the order.
Assert that the given path in the response contains all of the expected values without looking at the order.
Assert that the response has the exact given JSON.
Assert that the response has the similar JSON as given.
Assert that the response contains the given JSON fragments.
Assert that the response contains the given JSON fragment.
Assert that the response does not contain the given JSON fragment.
Assert that the response does not contain the exact JSON fragment.
Assert that the response does not contain the given path.
Assert that the response does not contain the given paths.
Assert that the response has a given JSON structure.
Assert that the response has the exact JSON structure.
Assert that the response JSON has the expected count of items at the given key.
Assert that the response has the given JSON validation errors.
Assert that the response has the given JSON validation errors but does not have any other JSON validation errors.
Assert the response has any JSON validation errors for the given key.
Assert that the response has no JSON validation errors for the given keys.
Assert that the given key is a JSON array.
Assert that the given key is a JSON object.
Validate the decoded response JSON.
Return the decoded response JSON.
Get the decoded JSON body of the response as a collection.
Assert that the response view equals the given value.
Assert that the response view has a given piece of bound data.
Assert that the response view has a given list of bound data.
Get a piece of data from the original view.
Assert that the response view is missing a piece of bound data.
Ensure that the response has a view as its original content.
Determine if the original response is a view.
Assert that the given keys do not have validation errors.
Assert that the response has the given validation errors.
Assert that the response has the given validation errors but does not have any other validation errors.
Assert that the session has a given value.
Assert that the session has a given list of values.
Assert that the session has a given value in the flashed input array.
Assert that the session is missing a given key in the flashed input array.
Assert that the session has the given errors.
Assert that the session is missing the given errors.
Assert that the session has no errors.
Assert that the session has the given errors.
Assert that the session does not have a given key.
Dump the headers from the response and end the script.
Dump the body of the response and end the script.
Dump the JSON payload from the response and end the script.
Dump the session from the response and end the script.
Dump the headers from the response.
Dump the session from the response.
Get the response content.
Get the streamed content from the response.
Determine if the response is a streamed response.
Flush all static state.
Dynamically access base response parameters.
Proxy isset() checks to the underlying base response.
Determine if the given offset exists.
Get the value for a given offset.
Set the value at the given offset.
Unset the value at the given offset.
Details
in
AssertsStatusCodes at line 16
AssertsStatusCodes
assertOk()
Assert that the response has a 200 "OK" status code.
in
AssertsStatusCodes at line 26
AssertsStatusCodes
assertCreated()
Assert that the response has a 201 "Created" status code.
in
AssertsStatusCodes at line 36
AssertsStatusCodes
assertAccepted()
Assert that the response has a 202 "Accepted" status code.
in
AssertsStatusCodes at line 46
AssertsStatusCodes
assertNoContent(int $status = 204)
Assert that the response has the given status code and no content.
in
AssertsStatusCodes at line 60
AssertsStatusCodes
assertMovedPermanently()
Assert that the response has a 301 "Moved Permanently" status code.
in
AssertsStatusCodes at line 70
AssertsStatusCodes
assertFound()
Assert that the response has a 302 "Found" status code.
in
AssertsStatusCodes at line 80
AssertsStatusCodes
assertNotModified()
Assert that the response has a 304 "Not Modified" status code.
in
AssertsStatusCodes at line 90
AssertsStatusCodes
assertTemporaryRedirect()
Assert that the response has a 307 "Temporary Redirect" status code.
in
AssertsStatusCodes at line 100
AssertsStatusCodes
assertPermanentRedirect()
Assert that the response has a 308 "Permanent Redirect" status code.
in
AssertsStatusCodes at line 110
AssertsStatusCodes
assertBadRequest()
Assert that the response has a 400 "Bad Request" status code.
in
AssertsStatusCodes at line 120
AssertsStatusCodes
assertUnauthorized()
Assert that the response has a 401 "Unauthorized" status code.
in
AssertsStatusCodes at line 130
AssertsStatusCodes
assertPaymentRequired()
Assert that the response has a 402 "Payment Required" status code.
in
AssertsStatusCodes at line 140
AssertsStatusCodes
assertForbidden()
Assert that the response has a 403 "Forbidden" status code.
in
AssertsStatusCodes at line 150
AssertsStatusCodes
assertNotFound()
Assert that the response has a 404 "Not Found" status code.
in
AssertsStatusCodes at line 160
AssertsStatusCodes
assertMethodNotAllowed()
Assert that the response has a 405 "Method Not Allowed" status code.
in
AssertsStatusCodes at line 170
AssertsStatusCodes
assertNotAcceptable()
Assert that the response has a 406 "Not Acceptable" status code.
in
AssertsStatusCodes at line 180
AssertsStatusCodes
assertRequestTimeout()
Assert that the response has a 408 "Request Timeout" status code.
in
AssertsStatusCodes at line 190
AssertsStatusCodes
assertConflict()
Assert that the response has a 409 "Conflict" status code.
in
AssertsStatusCodes at line 200
AssertsStatusCodes
assertGone()
Assert that the response has a 410 "Gone" status code.
in
AssertsStatusCodes at line 210
AssertsStatusCodes
assertUnsupportedMediaType()
Assert that the response has a 415 "Unsupported Media Type" status code.
in
AssertsStatusCodes at line 220
AssertsStatusCodes
assertUnprocessable()
Assert that the response has a 422 "Unprocessable Content" status code.
in
AssertsStatusCodes at line 230
AssertsStatusCodes
assertFailedDependency()
Assert that the response has a 424 "Failed Dependency" status code.
in
AssertsStatusCodes at line 240
AssertsStatusCodes
assertTooManyRequests()
Assert that the response has a 429 "Too Many Requests" status code.
in
AssertsStatusCodes at line 250
AssertsStatusCodes
assertInternalServerError()
Assert that the response has a 500 "Internal Server Error" status code.
in
AssertsStatusCodes at line 260
AssertsStatusCodes
assertServiceUnavailable()
Assert that the response has a 503 "Service Unavailable" status code.
in
Conditionable at line 23
mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
in
Conditionable at line 56
mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
in
Dumpable at line 12
never
dd(mixed ...$args)
Dump the given arguments and terminate execution.
at line 1781
TestResponse
dump(string|null $key = null)
Dump the content from the response.
in
Tappable at line 17
mixed
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
at line 1967
mixed
__call(string $method, array $args)
Handle dynamic calls into macros or pass missing methods to the base response.
at line 86
__construct(TResponse $response, Request|null $request = null)
Create a new test response instance.
at line 101
static TestResponse
fromBaseResponse(R $response, Request|null $request = null)
Create a new TestResponse from another response.
at line 111
TestResponse
assertSuccessful()
Assert that the response has a successful status code.
at line 126
TestResponse
assertSuccessfulPrecognition()
Assert that the Precognition request was successful.
at line 149
TestResponse
assertClientError()
Assert that the response is a client error.
at line 164
TestResponse
assertServerError()
Assert that the response is a server error.
at line 179
TestResponse
assertStatus(int $status)
Assert that the response has the given status code.
at line 191
protected string
statusMessageWithDetails(int|string $expected, int|string $actual)
Get an assertion message for a status assertion containing extra details when available.
at line 201
TestResponse
assertRedirect(string|null $uri = null)
Assert whether the response is redirecting to a given URI.
at line 220
TestResponse
assertRedirectContains(string $uri)
Assert whether the response is redirecting to a URI that contains the given URI.
at line 240
TestResponse
assertRedirectBack()
Assert whether the response is redirecting back to the previous location.
at line 257
TestResponse
assertRedirectBackWithErrors(array|string $keys = [], mixed $format = null, string $errorBag = 'default')
Assert whether the response is redirecting back to the previous location with the given errors in the session.
at line 271
TestResponse
assertRedirectBackWithoutErrors()
Assert whether the response is redirecting back to the previous location with no errors in the session.
at line 285
TestResponse
assertRedirectToRoute(BackedEnum|string $name, mixed $parameters = [])
Assert whether the response is redirecting to a given route.
at line 304
TestResponse
assertRedirectToSignedRoute(BackedEnum|string|null $name = null, mixed $parameters = [], bool $absolute = true)
Assert whether the response is redirecting to a given signed route.
at line 342
TestResponse
assertRedirectToAction(array|string $name, array $parameters = [])
Assert whether the response is redirecting to a given controller action.
at line 361
TestResponse
assertHeader(string $headerName, mixed $value = null)
Asserts that the response contains the given header and equals the optional value.
at line 386
TestResponse
assertHeaderContains(string $headerName, string $value)
Asserts that the response contains the given header and that its value contains the given string.
at line 408
TestResponse
assertHeaderMissing(string $headerName)
Asserts that the response does not contain the given header.
at line 423
TestResponse
assertLocation(string $uri)
Assert that the current location header matches the given URI.
at line 438
TestResponse
assertDownload(string|null $filename = null)
Assert that the response offers a file download.
at line 485
TestResponse
assertPlainCookie(string $cookieName, mixed $value = null)
Asserts that the response contains the given cookie and equals the optional value.
at line 497
TestResponse
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.
at line 524
TestResponse
assertCookieExpired(string $cookieName)
Asserts that the response contains the given cookie and is expired.
at line 546
TestResponse
assertCookieNotExpired(string $cookieName)
Asserts that the response contains the given cookie and is not expired.
at line 568
TestResponse
assertCookieMissing(string $cookieName)
Asserts that the response does not contain the given cookie.
at line 581
Cookie|null
getCookie(string $cookieName, bool $decrypt = true, bool $unserialize = false)
Get the given cookie from the response.
at line 616
TestResponse
assertContent(string $value)
Assert that the given string matches the response content.
at line 628
TestResponse
assertStreamed()
Assert that the response was streamed.
at line 643
TestResponse
assertNotStreamed()
Assert that the response was not streamed.
at line 658
TestResponse
assertStreamedContent(string $value)
Assert that the given string matches the streamed response content.
at line 672
TestResponse
assertStreamedJsonContent(array $value)
Assert that the given array matches the streamed JSON response content.
at line 683
TestResponse
assertSee(array|string $value, bool $escape = true)
Assert that the given string or array of strings are contained within the response.
at line 702
TestResponse
assertSeeHtml(array|string $value)
Assert that the given HTML string or array of HTML strings are contained within the response.
at line 713
TestResponse
assertSeeInOrder(array $values, bool $escape = true)
Assert that the given strings are contained in order within the response.
at line 728
TestResponse
assertSeeHtmlInOrder(array $values)
Assert that the given HTML strings are contained in order within the response.
at line 739
TestResponse
assertSeeText(array|string $value, bool $escape = true)
Assert that the given string or array of strings are contained within the response text.
at line 756
TestResponse
assertSeeTextInOrder(array $values, bool $escape = true)
Assert that the given strings are contained in order within the response text.
at line 771
TestResponse
assertDontSee(array|string $value, bool $escape = true)
Assert that the given string or array of strings are not contained within the response.
at line 790
TestResponse
assertDontSeeHtml(array|string $value)
Assert that the given HTML string or array of HTML strings are not contained within the response.
at line 801
TestResponse
assertDontSeeText(array|string $value, bool $escape = true)
Assert that the given string or array of strings are not contained within the response text.
at line 817
TestResponse
assertJson(array|callable $value, bool $strict = false)
Assert that the response is a superset of the given JSON.
at line 841
TestResponse
assertJsonPath(string $path, mixed $expect)
Assert that the expected value and type exists at the given path in the response.
at line 854
TestResponse
assertJsonPaths(array $paths)
Assert that the expected values and types exist at the given paths in the response.
at line 869
TestResponse
assertJsonPathsCanonicalizing(array $paths)
Assert that the given paths in the response contain all of the expected values without looking at the order.
at line 883
TestResponse
assertJsonPathCanonicalizing(string $path, array $expect)
Assert that the given path in the response contains all of the expected values without looking at the order.
at line 895
TestResponse
assertExactJson(array $data)
Assert that the response has the exact given JSON.
at line 907
TestResponse
assertSimilarJson(array $data)
Assert that the response has the similar JSON as given.
at line 919
TestResponse
assertJsonFragments(array $data)
Assert that the response contains the given JSON fragments.
at line 933
TestResponse
assertJsonFragment(array $data)
Assert that the response contains the given JSON fragment.
at line 945
TestResponse
assertJsonMissing(array $data, bool $exact = false)
Assert that the response does not contain the given JSON fragment.
at line 957
TestResponse
assertJsonMissingExact(array $data)
Assert that the response does not contain the exact JSON fragment.
at line 969
TestResponse
assertJsonMissingPath(string $path)
Assert that the response does not contain the given path.
at line 982
TestResponse
assertJsonMissingPaths(array $paths)
Assert that the response does not contain the given paths.
at line 996
TestResponse
assertJsonStructure(array|null $structure = null, array|null $responseData = null)
Assert that the response has a given JSON structure.
at line 1008
TestResponse
assertExactJsonStructure(array|null $structure = null, array|null $responseData = null)
Assert that the response has the exact JSON structure.
at line 1020
TestResponse
assertJsonCount(int $count, string|null $key = null)
Assert that the response JSON has the expected count of items at the given key.
at line 1032
TestResponse
assertJsonValidationErrors(array|string|null $errors, string $responseKey = 'errors')
Assert that the response has the given JSON validation errors.
at line 1081
TestResponse
assertOnlyJsonValidationErrors(array|string|null $errors, string $responseKey = 'errors')
Assert that the response has the given JSON validation errors but does not have any other JSON validation errors.
at line 1106
TestResponse
assertJsonValidationErrorFor(string $key, string $responseKey = 'errors')
Assert the response has any JSON validation errors for the given key.
at line 1129
TestResponse
assertJsonMissingValidationErrors(array|string|null $keys = null, string $responseKey = 'errors')
Assert that the response has no JSON validation errors for the given keys.
at line 1169
TestResponse
assertJsonIsArray(string|null $key = null)
Assert that the given key is a JSON array.
at line 1184
TestResponse
assertJsonIsObject(string|null $key = null)
Assert that the given key is a JSON object.
at line 1199
AssertableJsonString
decodeResponseJson()
Validate the decoded response JSON.
at line 1224
mixed
json(string|null $key = null)
Return the decoded response JSON.
at line 1232
Collection
collect(string|null $key = null)
Get the decoded JSON body of the response as a collection.
at line 1242
TestResponse
assertViewIs(string $value)
Assert that the response view equals the given value.
at line 1256
TestResponse
assertViewHas(array|string $key, mixed $value = null)
Assert that the response view has a given piece of bound data.
at line 1299
TestResponse
assertViewHasAll(array $bindings)
Assert that the response view has a given list of bound data.
at line 1315
mixed
viewData(string|null $key = null)
Get a piece of data from the original view.
at line 1333
TestResponse
assertViewMissing(string $key)
Assert that the response view is missing a piece of bound data.
at line 1347
protected TestResponse
ensureResponseHasView()
Ensure that the response has a view as its original content.
at line 1359
protected bool
responseHasView()
Determine if the original response is a view.
at line 1369
TestResponse
assertValid(array|string|null $keys = null, string $errorBag = 'default', string $responseKey = 'errors')
Assert that the given keys do not have validation errors.
at line 1409
TestResponse
assertInvalid(array|string|null $errors = null, string $errorBag = 'default', string $responseKey = 'errors')
Assert that the response has the given validation errors.
at line 1460
TestResponse
assertOnlyInvalid(array|string|null $errors = null, string $errorBag = 'default', string $responseKey = 'errors')
Assert that the response has the given validation errors but does not have any other validation errors.
at line 1491
TestResponse
assertSessionHas(array|string $key, mixed $value = null)
Assert that the session has a given value.
at line 1516
TestResponse
assertSessionHasAll(array $bindings)
Assert that the session has a given list of values.
at line 1545
TestResponse
assertSessionHasInput(array|string $key, mixed $value = null)
Assert that the session has a given value in the flashed input array.
at line 1579
TestResponse
assertSessionMissingInput(array|string $key)
Assert that the session is missing a given key in the flashed input array.
at line 1602
TestResponse
assertSessionHasErrors(array|string $keys = [], mixed $format = null, string $errorBag = 'default')
Assert that the session has the given errors.
at line 1626
TestResponse
assertSessionDoesntHaveErrors(array|string $keys = [], string|null $format = null, string $errorBag = 'default')
Assert that the session is missing the given errors.
at line 1660
TestResponse
assertSessionHasNoErrors()
Assert that the session has no errors.
at line 1692
TestResponse
assertSessionHasErrorsIn(string $errorBag, array|string $keys = [], mixed $format = null)
Assert that the session has the given errors.
at line 1702
TestResponse
assertSessionMissing(array|string $key, mixed $value = null)
Assert that the session does not have a given key.
at line 1729
protected Session
session()
Get the current session store.
at line 1737
never
ddHeaders()
Dump the headers from the response and end the script.
at line 1747
never
ddBody(string|null $key = null)
Dump the body of the response and end the script.
at line 1761
never
ddJson(string|null $key = null)
Dump the JSON payload from the response and end the script.
at line 1769
never
ddSession(array|string $keys = [])
Dump the session from the response and end the script.
at line 1806
TestResponse
dumpHeaders()
Dump the headers from the response.
at line 1818
TestResponse
dumpSession(array|string $keys = [])
Dump the session from the response.
at line 1834
string
getContent()
Get the response content.
at line 1845
string
streamedContent()
Get the streamed content from the response.
at line 1883
protected bool
isStreamedResponse()
Determine if the response is a streamed response.
at line 1893
TestResponse
withExceptions(Collection $exceptions)
Set the previous exceptions on the response.
at line 1903
static void
flushState()
Flush all static state.
at line 1911
mixed
__get(string $key)
Dynamically access base response parameters.
at line 1919
bool
__isset(string $key)
Proxy isset() checks to the underlying base response.
at line 1927
bool
offsetExists(mixed $offset)
Determine if the given offset exists.
at line 1937
mixed
offsetGet(mixed $offset)
Get the value for a given offset.
at line 1949
void
offsetSet(mixed $offset, mixed $value)
Set the value at the given offset.
at line 1959
void
offsetUnset(mixed $offset)
Unset the value at the given offset.