class TestResponse

A simplified test response wrapper that mimics HTTP-style responses for use in feature tests.

This class is used to encapsulate content and status from simulated controller executions, and provides assertion methods to verify test outcomes such as HTTP status or content presence.

Example usage in a test: $response = $this->get('/'); $response->assertStatus(200); $response->assertSee('Welcome');

Methods

__construct(string $content, int $status = 200)

Constructs a new TestResponse instance.

void
assertDontSee(string $text)

Asserts that the given text is not present in the response content.

void
assertJson(array $expected)

Asserts that the response content is a valid JSON string and that it contains the specified keys and values.

void
assertSee(string $text)

Asserts that the response content contains the given text.

void
assertStatus(int $expected)

Asserts that the response status matches the expected value.

string
getContent()

Returns the response content.

Details

at line 42
__construct(string $content, int $status = 200)

Constructs a new TestResponse instance.

Parameters

string $content

The response body (typically HTML or JSON).

int $status

The HTTP status code (default is 200).

at line 54
void assertDontSee(string $text)

Asserts that the given text is not present in the response content.

Parameters

string $text

The string that should not appear in the content

Return Value

void

at line 70
void assertJson(array $expected)

Asserts that the response content is a valid JSON string and that it contains the specified keys and values.

Parameters

array $expected

An associative array of expected key-value pairs

Return Value

void

at line 87
void assertSee(string $text)

Asserts that the response content contains the given text.

Parameters

string $text

The text expected to be found in the response content.

Return Value

void

at line 102
void assertStatus(int $expected)

Asserts that the response status matches the expected value.

Parameters

int $expected

The expected HTTP status code.

Return Value

void

at line 116
string getContent()

Returns the response content.

Return Value

string

The body of the response.