MakesHttpRequests
trait MakesHttpRequests
Properties
| protected array | $defaultHeaders | Additional headers for the request. |
|
| protected array | $defaultCookies | Additional cookies for the request. |
|
| protected array | $unencryptedCookies | Additional cookies that will not be encrypted for the request. |
|
| protected array | $serverVariables | Additional server variables for the request. |
|
| protected bool | $followRedirects | Indicates whether redirects should be followed. |
|
| protected bool | $encryptCookies | Indicates whether cookies should be encrypted. |
|
| protected bool | $withCredentials | Indicated whether JSON requests should be performed "with credentials" (cookies). |
|
| static protected Waiter|null | $waiter | The coroutine waiter for test requests. |
Methods
Define additional headers to be sent with the request.
Add a header to be sent with the request.
Remove a header from the request.
Remove headers from the request.
Add an authorization token for the request.
Add a basic authentication header to the request with the given credentials.
Remove the authorization token from the request.
Flush all the configured headers.
Define a set of server variables to be sent with the requests.
Disable middleware for the test.
Enable the given middleware for the test.
Define additional cookies to be sent with the request.
Add a cookie to be sent with the request.
Define additional cookies that will not be encrypted before sending with the request.
Add a cookie that will not be encrypted before sending with the request.
Automatically follow any redirects returned from the response.
Include cookies and authorization headers for JSON requests.
Disable automatic encryption of cookie values.
Set the referer header and previous URL session value in order to simulate a previous request.
Set the referer header and previous URL session value from a given route in order to simulate a previous request.
Set the Precognition header to "true".
Visit the given URI with a GET request, expecting a JSON response.
Visit the given URI with a POST request.
Visit the given URI with a POST request, expecting a JSON response.
Visit the given URI with a PUT request.
Visit the given URI with a PUT request, expecting a JSON response.
Visit the given URI with a PATCH request.
Visit the given URI with a PATCH request, expecting a JSON response.
Visit the given URI with a DELETE request.
Visit the given URI with a DELETE request, expecting a JSON response.
Visit the given URI with an OPTIONS request.
Visit the given URI with an OPTIONS request, expecting a JSON response.
Visit the given URI with a QUERY request.
Visit the given URI with a QUERY request, expecting a JSON response.
Call the given URI with a JSON request.
Call the given URI and return the Response.
Sync durable request Context state to the test coroutine.
Get a snapshot of durable session Context state for the completed request.
Get durable session Context keys.
Get durable authentication Context keys.
Transform headers array to array of $SERVER vars with HTTP* format.
Format the header name for the server array.
Extract the file uploads from the given data array.
If enabled, encrypt cookie values for request.
Prepare cookies for JSON requests.
Follow a redirect chain until a non-redirect is received.
Create the request instance used for testing from the given Symfony request.
Create the test response instance from the given response.
Dispatch a request lifecycle event if enabled.
Details
at line 73
MakesHttpRequests
withHeaders(array $headers)
Define additional headers to be sent with the request.
at line 83
MakesHttpRequests
withHeader(string $name, string $value)
Add a header to be sent with the request.
at line 93
MakesHttpRequests
withoutHeader(string $name)
Remove a header from the request.
at line 103
MakesHttpRequests
withoutHeaders(array $headers)
Remove headers from the request.
at line 115
MakesHttpRequests
withToken(string $token, string $type = 'Bearer')
Add an authorization token for the request.
at line 123
MakesHttpRequests
withBasicAuth(string $username, string $password)
Add a basic authentication header to the request with the given credentials.
at line 131
MakesHttpRequests
withoutToken()
Remove the authorization token from the request.
at line 139
MakesHttpRequests
flushHeaders()
Flush all the configured headers.
at line 149
MakesHttpRequests
withServerVariables(array $server)
Define a set of server variables to be sent with the requests.
at line 161
MakesHttpRequests
withoutMiddleware(null|array|string $middleware = null)
Disable middleware for the test.
at line 181
MakesHttpRequests
withMiddleware(null|array|string $middleware = null)
Enable the given middleware for the test.
at line 199
MakesHttpRequests
withCookies(array $cookies)
Define additional cookies to be sent with the request.
at line 209
MakesHttpRequests
withCookie(string $name, string $value)
Add a cookie to be sent with the request.
at line 219
MakesHttpRequests
withUnencryptedCookies(array $cookies)
Define additional cookies that will not be encrypted before sending with the request.
at line 229
MakesHttpRequests
withUnencryptedCookie(string $name, string $value)
Add a cookie that will not be encrypted before sending with the request.
at line 239
MakesHttpRequests
followingRedirects()
Automatically follow any redirects returned from the response.
at line 249
MakesHttpRequests
withCredentials()
Include cookies and authorization headers for JSON requests.
at line 259
MakesHttpRequests
disableCookieEncryption()
Disable automatic encryption of cookie values.
at line 269
MakesHttpRequests
from(string $url)
Set the referer header and previous URL session value in order to simulate a previous request.
at line 279
MakesHttpRequests
fromRoute(BackedEnum|string $name, mixed $parameters = [])
Set the referer header and previous URL session value from a given route in order to simulate a previous request.
at line 287
MakesHttpRequests
withPrecognition()
Set the Precognition header to "true".
at line 295
TestResponse
get(Stringable|string $uri, array $headers = [])
Visit the given URI with a GET request.
at line 306
TestResponse
getJson(Stringable|string $uri, array $headers = [], int $options = 0)
Visit the given URI with a GET request, expecting a JSON response.
at line 314
TestResponse
post(Stringable|string $uri, array $data = [], array $headers = [])
Visit the given URI with a POST request.
at line 325
TestResponse
postJson(Stringable|string $uri, array $data = [], array $headers = [], int $options = 0)
Visit the given URI with a POST request, expecting a JSON response.
at line 333
TestResponse
put(Stringable|string $uri, array $data = [], array $headers = [])
Visit the given URI with a PUT request.
at line 344
TestResponse
putJson(Stringable|string $uri, array $data = [], array $headers = [], int $options = 0)
Visit the given URI with a PUT request, expecting a JSON response.
at line 352
TestResponse
patch(Stringable|string $uri, array $data = [], array $headers = [])
Visit the given URI with a PATCH request.
at line 363
TestResponse
patchJson(Stringable|string $uri, array $data = [], array $headers = [], int $options = 0)
Visit the given URI with a PATCH request, expecting a JSON response.
at line 371
TestResponse
delete(Stringable|string $uri, array $data = [], array $headers = [])
Visit the given URI with a DELETE request.
at line 382
TestResponse
deleteJson(Stringable|string $uri, array $data = [], array $headers = [], int $options = 0)
Visit the given URI with a DELETE request, expecting a JSON response.
at line 390
TestResponse
options(Stringable|string $uri, array $data = [], array $headers = [])
Visit the given URI with an OPTIONS request.
at line 401
TestResponse
optionsJson(Stringable|string $uri, array $data = [], array $headers = [], int $options = 0)
Visit the given URI with an OPTIONS request, expecting a JSON response.
at line 409
TestResponse
head(Stringable|string $uri, array $headers = [])
Visit the given URI with a HEAD request.
at line 420
TestResponse
query(Stringable|string $uri, array $data = [], array $headers = [])
Visit the given URI with a QUERY request.
at line 431
TestResponse
queryJson(Stringable|string $uri, array $data = [], array $headers = [], int $options = 0)
Visit the given URI with a QUERY request, expecting a JSON response.
at line 443
TestResponse
json(string $method, Stringable|string $uri, array $data = [], array $headers = [], int $options = 0)
Call the given URI with a JSON request.
at line 474
TestResponse
call(string $method, Stringable|string $uri, array $parameters = [], array $cookies = [], array $files = [], array $server = [], string|null $content = null)
Call the given URI and return the Response.
Each test request runs in a fresh coroutine via the Waiter to ensure coroutine-local Context isolation. RequestContext is seeded because tests bypass the HttpServer\Server adapter which normally does this in onRequest().
at line 546
protected string
prepareUrlForRequest(Stringable|string $uri)
Turn the given URI into a fully-qualified URL.
at line 560
protected void
syncRequestContextToParent(Request $request)
Sync durable request Context state to the test coroutine.
at line 577
protected array
sessionContextSnapshot(Request $request)
Get a snapshot of durable session Context state for the completed request.
at line 600
protected array
sessionContextKeys()
Get durable session Context keys.
at line 619
protected array
sessionStoreContextKeys(Store $session)
Get the Context keys for the given session store.
at line 635
protected array
authenticationContextKeys()
Get durable authentication Context keys.
at line 653
protected array
transformHeadersToServerVars(array $headers)
Transform headers array to array of $SERVER vars with HTTP* format.
at line 665
protected string
formatServerHeaderKey(string $name)
Format the header name for the server array.
at line 677
protected array
extractFilesFromDataArray(array $data)
Extract the file uploads from the given data array.
at line 701
protected array
prepareCookiesForRequest()
If enabled, encrypt cookie values for request.
at line 716
protected array
prepareCookiesForJsonRequest()
Prepare cookies for JSON requests.
at line 725
protected TestResponse
followRedirects(mixed $response)
Follow a redirect chain until a non-redirect is received.
at line 739
protected Request
createTestRequest(Request $symfonyRequest)
Create the request instance used for testing from the given Symfony request.
at line 748
protected TestResponse
createTestResponse(mixed $response, Request|null $request = null)
Create the test response instance from the given response.
at line 765
protected void
dispatchRequestLifecycleEvent(string $eventClass, Request $request, Response|null $response = null)
Dispatch a request lifecycle event if enabled.
Tests bypass the HttpServer\Server adapter, so lifecycle events must be dispatched here for Telescope and other watchers to work in test contexts.
at line 790
protected Waiter
getWaiter()
Get the coroutine waiter for test requests.