class TestCase extends TestCase (View source)

Properties

protected ?string $url

The base url. If null, resolves to APP_URL env var, then to http://127.0.0.1:8080 (the default of php bow run:server).

Methods

attach(array $attach)

Add files / multipart attachments to the next request.

withHeaders(array $headers)

Replace the header map applied to every request.

withHeader(string $key, string $value)

Add (or override) a single header.

get(string $url, array $param = [])

GET request.

post(string $url, array $param = [])

POST request.

put(string $url, array $param = [])

PUT request.

patch(string $url, array $param = [])

PATCH request (real HTTP PATCH — no _method POST hack).

delete(string $url, array $param = [])

DELETE request (real HTTP DELETE — no _method POST hack).

head(string $url, array $param = [])

HEAD request (headers only, no body).

options(string $url)

OPTIONS request (typically for CORS preflight).

visit(string $method, string $url, array $params = [])

Dispatch a request by HTTP verb name.

newHttpClient()

Build a fresh HttpClient pre-configured with the current headers and pending attachments. Attachments are consumed (reset) after this call; headers persist for the lifetime of the test instance.

string
getBaseUrl()

Resolve the base URL. Override this in a subclass for more elaborate setups (per-test base URLs, computed from env, etc.).

Details

TestCase attach(array $attach)

Add files / multipart attachments to the next request.

Cleared automatically after the request is sent.

Parameters

array $attach

Return Value

TestCase

TestCase withHeaders(array $headers)

Replace the header map applied to every request.

Parameters

array $headers

Return Value

TestCase

TestCase withHeader(string $key, string $value)

Add (or override) a single header.

Parameters

string $key
string $value

Return Value

TestCase

Response get(string $url, array $param = [])

GET request.

Parameters

string $url
array $param

Return Value

Response

Exceptions

Exception

Response post(string $url, array $param = [])

POST request.

Parameters

string $url
array $param

Return Value

Response

Exceptions

Exception

Response put(string $url, array $param = [])

PUT request.

Parameters

string $url
array $param

Return Value

Response

Exceptions

Exception

Response patch(string $url, array $param = [])

PATCH request (real HTTP PATCH — no _method POST hack).

Parameters

string $url
array $param

Return Value

Response

Exceptions

Exception

Response delete(string $url, array $param = [])

DELETE request (real HTTP DELETE — no _method POST hack).

Parameters

string $url
array $param

Return Value

Response

Exceptions

Exception

Response head(string $url, array $param = [])

HEAD request (headers only, no body).

Parameters

string $url
array $param

Return Value

Response

Exceptions

Exception

Response options(string $url)

OPTIONS request (typically for CORS preflight).

Parameters

string $url

Return Value

Response

Exceptions

Exception

Response visit(string $method, string $url, array $params = [])

Dispatch a request by HTTP verb name.

Parameters

string $method
string $url
array $params

Return Value

Response

Exceptions

BadMethodCallException

protected HttpClient newHttpClient()

Build a fresh HttpClient pre-configured with the current headers and pending attachments. Attachments are consumed (reset) after this call; headers persist for the lifetime of the test instance.

Return Value

HttpClient

protected string getBaseUrl()

Resolve the base URL. Override this in a subclass for more elaborate setups (per-test base URLs, computed from env, etc.).

Return Value

string