Factory
class Factory mixin PendingRequest<false>
Traits
Constants
| protected GLOBAL_CONFIGURATION_DISABLED_CONTEXT_KEY_PREFIX |
|
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected array | $globalMiddleware | The middleware to apply to every request. |
|
| protected array|Closure | $globalOptions | The options to apply to every request. |
|
| protected Collection | $stubCallbacks | The stub callables that will handle requests. |
|
| protected bool | $recording | Indicates if the factory is recording requests and responses. |
|
| protected array | $recorded | The recorded response array. |
|
| protected array | $responseSequences | All created response sequences. |
|
| protected bool | $preventStrayRequests | Indicates that an exception should be thrown if any request is not faked. |
|
| protected array | $allowedStrayRequestUrls | The URL patterns that are allowed as stray requests. |
|
| protected array | $connectionConfigs | The configuration for all registered connections. |
|
| protected array<string, callable> | $connectionHandlers | The resolved low-level transport handlers for registered connections. |
|
| protected Closure|null | $defaultHandler | The transport shared by requests without a named connection. |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Execute a method against a new pending request instance.
Add middleware to apply to every request.
Add request middleware to apply to every request.
Add response middleware to apply to every request.
Execute a callback while requests are created without global middleware or global options.
Create a new response instance for use during stubbing.
Create a new PSR-7 response instance for use during stubbing.
Normalize the given fake response headers.
Normalize a scalar to a string without triggering PHP 8.5 non-finite float warnings.
Create a new RequestException instance for use during stubbing.
Create a new connection exception for use during stubbing.
Get an invokable object that returns a sequence of responses in order for use during stubbing.
Register a stub callable that will intercept requests and be able to return stub responses.
Register a response sequence for the given URL pattern.
Indicate that an exception should be thrown if any request is not faked.
Determine if stray requests are being prevented.
Indicate that an exception should not be thrown if any request is not faked.
Record a request response pair.
Assert that a request / response pair was recorded matching a given truth test.
Assert that the given request was sent in the given order.
Assert that a request / response pair was not recorded matching a given truth test.
Assert that no request / response pair was recorded.
Assert how many requests have been recorded.
Assert that every created response sequence is empty.
Get a collection of the request / response pairs matching the given truth test.
Create a new pending request instance for this factory.
Instantiate a new pending request instance for this factory.
Get the current event dispatcher implementation.
Get the array of global middleware.
Register a connection with the given name and configuration.
Determine if the given HTTP client connection is registered.
Get the shared low-level transport handler for default requests.
Get the shared low-level transport handler for a connection.
Create a request-owned transport whose DNS pins cannot reach shared caches.
Get the transport options owned by a registered connection.
Create a reusable transport handler with incremental streaming support.
Create new Guzzle client.
Get the configuration for all connections.
Get the configuration for a specific connection.
Get the request-option preset for a registered connection.
Set the configuration for a specific connection.
Forget the resolved default and connection handlers.
Ensure the given HTTP client connection is registered.
Validate a registered connection configuration.
Flush all static state.
Details
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 884
mixed
__call(string $method, array $parameters)
Execute a method against a new pending request instance.
at line 108
__construct(Dispatcher|null $dispatcher = null)
Create a new factory instance.
at line 121
Factory
globalMiddleware(callable $middleware)
Add middleware to apply to every request.
The middleware persists on the shared factory for the worker lifetime and affects every subsequently created pending request.
at line 137
Factory
globalRequestMiddleware(callable $middleware)
Add request middleware to apply to every request.
The middleware persists on the shared factory for the worker lifetime and affects every subsequently created pending request.
at line 153
Factory
globalResponseMiddleware(callable $middleware)
Add response middleware to apply to every request.
The middleware persists on the shared factory for the worker lifetime and affects every subsequently created pending request.
at line 169
Factory
globalOptions(array|Closure $options)
Set the options to apply to every request.
The options persist on the shared factory for the worker lifetime and affect every subsequently created pending request.
at line 184
mixed
withoutGlobalConfiguration(Closure $callback)
Execute a callback while requests are created without global middleware or global options.
at line 205
static PromiseInterface
response(mixed $body = null, int $status = 200, array $headers = [])
Create a new response instance for use during stubbing.
at line 222
static Response
psr7Response(mixed $body = null, int $status = 200, array $headers = [])
Create a new PSR-7 response instance for use during stubbing.
at line 249
static protected array
normalizeResponseHeaders(array $headers)
Normalize the given fake response headers.
at line 292
static protected string
normalizeScalarString(bool|float|int|string $value)
Normalize a scalar to a string without triggering PHP 8.5 non-finite float warnings.
at line 310
static RequestException
failedRequest(mixed $body = null, int $status = 200, array $headers = [])
Create a new RequestException instance for use during stubbing.
at line 321
static Closure
failedConnection(string|null $message = null)
Create a new connection exception for use during stubbing.
at line 338
ResponseSequence
sequence(array $responses = [])
Get an invokable object that returns a sequence of responses in order for use during stubbing.
The sequence is retained by the shared factory for the worker lifetime.
at line 352
Factory
fake(array|callable|null $callback = null)
Register a stub callable that will intercept requests and be able to return stub responses.
Stubs persist on the shared factory for the worker lifetime and affect every subsequently created pending request.
at line 404
ResponseSequence
fakeSequence(string $url = '*')
Register a response sequence for the given URL pattern.
The sequence and stub persist on the shared factory for the worker lifetime.
at line 422
Factory
stubUrl(string $url, array|callable|int|PromiseInterface|Response|string $callback)
Stub the given URL using the given callback.
The stub persists on the shared factory for the worker lifetime and affects every subsequently created pending request.
at line 461
Factory
preventStrayRequests(bool $prevent = true)
Indicate that an exception should be thrown if any request is not faked.
The policy persists on the shared factory for the worker lifetime and affects every subsequently created pending request.
at line 472
bool
preventingStrayRequests()
Determine if stray requests are being prevented.
at line 485
Factory
allowStrayRequests(array|null $only = null)
Indicate that an exception should not be thrown if any request is not faked.
The policy persists on the shared factory for the worker lifetime and affects every subsequently created pending request.
at line 506
Factory
record()
Begin recording request / response pairs.
Recording persists on the shared factory for the worker lifetime and retains every subsequently completed request attempt.
at line 517
void
recordRequestResponsePair(Request $request, Response|null $response)
Record a request response pair.
at line 527
void
assertSent(callable $callback)
Assert that a request / response pair was recorded matching a given truth test.
at line 538
void
assertSentInOrder(array $callbacks)
Assert that the given request was sent in the given order.
at line 560
void
assertNotSent(callable $callback)
Assert that a request / response pair was not recorded matching a given truth test.
at line 571
void
assertNothingSent()
Assert that no request / response pair was recorded.
at line 582
void
assertSentCount(int $count)
Assert how many requests have been recorded.
at line 590
void
assertSequencesAreEmpty()
Assert that every created response sequence is empty.
at line 605
Collection
recorded(callable|null $callback = null)
Get a collection of the request / response pairs matching the given truth test.
at line 625
PendingRequest
createPendingRequest()
Create a new pending request instance for this factory.
at line 640
protected PendingRequest
newPendingRequest()
Instantiate a new pending request instance for this factory.
at line 658
Dispatcher|null
getDispatcher()
Get the current event dispatcher implementation.
at line 669
void
setDispatcher(Dispatcher|null $dispatcher)
Set the event dispatcher implementation.
The dispatcher persists on the shared factory for the worker lifetime and receives every subsequent HTTP client event.
at line 678
array
getGlobalMiddleware()
Get the array of global middleware.
at line 693
Factory
registerConnection(string $name, array $config = [])
Register a connection with the given name and configuration.
The connection preset and shared transport handler registry persist on the shared factory for the worker lifetime.
at line 702
bool
hasConnection(string $name)
Determine if the given HTTP client connection is registered.
at line 710
callable
getDefaultHandler()
Get the shared low-level transport handler for default requests.
at line 718
callable
getConnectionHandler(string $name)
Get the shared low-level transport handler for a connection.
at line 728
callable
newIsolatedHandler(string|null $connection = null)
| internal |
Create a request-owned transport whose DNS pins cannot reach shared caches.
at line 747
protected array
connectionHandlerOptions(string|null $name)
Get the transport options owned by a registered connection.
at line 768
protected callable
createConnectionHandler(array $options)
Create a reusable transport handler with incremental streaming support.
at line 779
ClientInterface
createClient(HandlerStack $handlerStack, CookieJar $cookies)
Create new Guzzle client.
at line 790
array
getConnectionConfigs()
Get the configuration for all connections.
at line 798
array
getConnectionConfig(string $name)
Get the configuration for a specific connection.
at line 806
array
getConnectionOptions(string $name)
Get the request-option preset for a registered connection.
at line 821
Factory
setConnectionConfig(string $name, array $config)
Set the configuration for a specific connection.
Reconfiguration replaces the worker-lifetime preset and invalidates its shared transport handler for subsequent requests.
at line 840
Factory
forgetConnectionHandlers()
Forget the resolved default and connection handlers.
Request-time use forces subsequent requests to rebuild warmed keep-alive, DNS, and TLS session state.
at line 852
protected void
ensureConnectionIsRegistered(string $name)
Ensure the given HTTP client connection is registered.
at line 862
protected void
validateConnectionConfig(array $config)
Validate a registered connection configuration.
at line 876
static void
flushState()
Flush all static state.