TestResponse

class TestResponse (View source)

Traits

Macroable

Properties

static protected array $macros The registered string macros. from Macroable
Response $baseResponse The response to delegate to.
protected string $streamedContent The streamed content of the response.

Methods

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

Register a custom macro.

from Macroable
static void mixin(object $mixin)

Mix another object into the class.

from Macroable
static bool hasMacro(string $name)

Checks if macro is registered.

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

Dynamically handle calls to the class.

from Macroable
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 assertOk()

Assert that the response has a 200 status code.

$this assertNotFound()

Assert that the response has a not found status code.

$this assertForbidden()

Assert that the response has a forbidden status code.

$this assertStatus(int $status)

Assert that the response has the given status code.

$this assertRedirect(string $uri = null)

Assert whether the response is redirecting to a given URI.

$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 contains the given header.

$this assertLocation(string $uri)

Assert that the current location header matches the given URI.

$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 contains the given cookie.

Cookie|null getCookie(string $cookieName)

Get the given cookie from the response.

$this assertSee(string $value)

Assert that the given string is contained within the response.

$this assertSeeInOrder(array $values)

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

$this assertSeeText(string $value)

Assert that the given string is contained within the response text.

$this assertSeeTextInOrder(array $values)

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

$this assertDontSee(string $value)

Assert that the given string is not contained within the response.

$this assertDontSeeText(string $value)

Assert that the given string is not contained within the response text.

$this assertJson(array $data, bool $strict = false)

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

string assertJsonMessage(array $data)

Get the assertion message for assertJson.

$this assertExactJson(array $data)

Assert that the response has the exact given JSON.

$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.

array jsonSearchStrings(string $key, string $value)

Get the strings we need to search for when examining the JSON.

$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 $keys)

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

$this assertJsonMissingValidationErrors(string|array $keys)

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

mixed decodeResponseJson(string|null $key = null)

Validate and return the decoded response JSON.

mixed json(string|null $key = null)

Validate and return the decoded response JSON.

$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.

$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 assertSessionHasErrors(string|array $keys = [], mixed $format = null, string $errorBag = 'default')

Assert that the session has 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.

Store session()

Get the current session store.

void dump()

Dump the content from the response.

string streamedContent()

Get the streamed content from the response.

mixed __get(string $key)

Dynamically access base response parameters.

mixed __isset(string $key)

Proxy isset() checks to the underlying base response.

Details

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)

Mix another object into the class.

Parameters

object $mixin

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

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 assertOk()

Assert that the response has a 200 status code.

Return Value

$this

$this assertNotFound()

Assert that the response has a not found status code.

Return Value

$this

$this assertForbidden()

Assert that the response has a forbidden status code.

Return Value

$this

$this assertStatus(int $status)

Assert that the response has the given status code.

Parameters

int $status

Return Value

$this

$this assertRedirect(string $uri = null)

Assert whether the response is redirecting to a given URI.

Parameters

string $uri

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 contains 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 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 contains the given cookie.

Parameters

string $cookieName

Return Value

$this

protected Cookie|null getCookie(string $cookieName)

Get the given cookie from the response.

Parameters

string $cookieName

Return Value

Cookie|null

$this assertSee(string $value)

Assert that the given string is contained within the response.

Parameters

string $value

Return Value

$this

$this assertSeeInOrder(array $values)

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

Parameters

array $values

Return Value

$this

$this assertSeeText(string $value)

Assert that the given string is contained within the response text.

Parameters

string $value

Return Value

$this

$this assertSeeTextInOrder(array $values)

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

Parameters

array $values

Return Value

$this

$this assertDontSee(string $value)

Assert that the given string is not contained within the response.

Parameters

string $value

Return Value

$this

$this assertDontSeeText(string $value)

Assert that the given string is not contained within the response text.

Parameters

string $value

Return Value

$this

$this assertJson(array $data, bool $strict = false)

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

Parameters

array $data
bool $strict

Return Value

$this

protected string assertJsonMessage(array $data)

Get the assertion message for assertJson.

Parameters

array $data

Return Value

string

$this assertExactJson(array $data)

Assert that the response has the exact given JSON.

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

protected array jsonSearchStrings(string $key, string $value)

Get the strings we need to search for when examining the JSON.

Parameters

string $key
string $value

Return Value

array

$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 $keys)

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

Parameters

string|array $keys

Return Value

$this

$this assertJsonMissingValidationErrors(string|array $keys)

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

Parameters

string|array $keys

Return Value

$this

mixed decodeResponseJson(string|null $key = null)

Validate and return the decoded response JSON.

Parameters

string|null $key

Return Value

mixed

mixed json(string|null $key = null)

Validate and return the decoded response JSON.

Parameters

string|null $key

Return Value

mixed

$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

$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 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 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

void dump()

Dump the content from the response.

Return Value

void

string streamedContent()

Get the streamed content from the response.

Return Value

string

mixed __get(string $key)

Dynamically access base response parameters.

Parameters

string $key

Return Value

mixed

mixed __isset(string $key)

Proxy isset() checks to the underlying base response.

Parameters

string $key

Return Value

mixed

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.7/Illuminate/Foundation/Testing/TestResponse.html