Factory
class Factory mixin PendingRequest
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. |
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 a connection.
Create a low-level transport handler for a connection.
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 all resolved connection handlers.
Ensure the given HTTP client connection is registered.
Validate a registered connection configuration.
Flush all static state.
Details
in
Macroable at line 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
at line 771
mixed
__call(string $method, array $parameters)
Execute a method against a new pending request instance.
at line 98
__construct(Dispatcher|null $dispatcher = null)
Create a new factory instance.
at line 109
Factory
globalMiddleware(callable $middleware)
Add middleware to apply to every request.
Boot-only. The middleware persists on the factory for the worker lifetime and affects every subsequently created pending request.
at line 122
Factory
globalRequestMiddleware(callable $middleware)
Add request middleware to apply to every request.
Boot-only. The middleware persists on the factory for the worker lifetime and affects every subsequently created pending request.
at line 135
Factory
globalResponseMiddleware(callable $middleware)
Add response middleware to apply to every request.
Boot-only. The middleware persists on the factory for the worker lifetime and affects every subsequently created pending request.
at line 148
Factory
globalOptions(array|Closure $options)
Set the options to apply to every request.
Boot-only. The options persist on the factory for the worker lifetime and affect every subsequently created pending request.
at line 162
mixed
withoutGlobalConfiguration(Closure $callback)
Execute a callback while requests are created without global middleware or global options.
at line 183
static PromiseInterface
response(mixed $body = null, int $status = 200, array $headers = [])
Create a new response instance for use during stubbing.
at line 200
static Response
psr7Response(mixed $body = null, int $status = 200, array $headers = [])
Create a new PSR-7 response instance for use during stubbing.
at line 227
static protected array
normalizeResponseHeaders(array $headers)
Normalize the given fake response headers.
at line 265
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 283
static RequestException
failedRequest(mixed $body = null, int $status = 200, array $headers = [])
Create a new RequestException instance for use during stubbing.
at line 294
static Closure
failedConnection(string|null $message = null)
Create a new connection exception for use during stubbing.
at line 311
ResponseSequence
sequence(array $responses = [])
Get an invokable object that returns a sequence of responses in order for use during stubbing.
Tests only. The sequence is retained by the factory for the worker lifetime.
at line 322
Factory
fake(array|callable|null $callback = null)
Register a stub callable that will intercept requests and be able to return stub responses.
Tests only. Stubs persist on the factory for the worker lifetime and affect every subsequently created pending request.
at line 372
ResponseSequence
fakeSequence(string $url = '*')
Register a response sequence for the given URL pattern.
Tests only. The sequence and stub persist on the factory for the worker lifetime.
at line 387
Factory
stubUrl(string $url, array|callable|int|PromiseInterface|Response|string $callback)
Stub the given URL using the given callback.
Tests only. The stub persists on the factory for the worker lifetime and affects every subsequently created pending request.
at line 423
Factory
preventStrayRequests(bool $prevent = true)
Indicate that an exception should be thrown if any request is not faked.
Boot or tests only. The policy persists on the factory for the worker lifetime and affects every subsequently created pending request.
at line 433
bool
preventingStrayRequests()
Determine if stray requests are being prevented.
at line 444
Factory
allowStrayRequests(array|null $only = null)
Indicate that an exception should not be thrown if any request is not faked.
Boot or tests only. The policy persists on the factory for the worker lifetime and affects every subsequently created pending request.
at line 462
Factory
record()
Begin recording request / response pairs.
Tests only. Recording persists on the factory for the worker lifetime and retains every subsequently completed request attempt.
at line 472
void
recordRequestResponsePair(Request $request, Response|null $response)
Record a request response pair.
at line 482
void
assertSent(callable $callback)
Assert that a request / response pair was recorded matching a given truth test.
at line 493
void
assertSentInOrder(array $callbacks)
Assert that the given request was sent in the given order.
at line 515
void
assertNotSent(callable $callback)
Assert that a request / response pair was not recorded matching a given truth test.
at line 526
void
assertNothingSent()
Assert that no request / response pair was recorded.
at line 537
void
assertSentCount(int $count)
Assert how many requests have been recorded.
at line 545
void
assertSequencesAreEmpty()
Assert that every created response sequence is empty.
at line 558
Collection
recorded(callable|null $callback = null)
Get a collection of the request / response pairs matching the given truth test.
at line 578
PendingRequest
createPendingRequest()
Create a new pending request instance for this factory.
at line 593
protected PendingRequest
newPendingRequest()
Instantiate a new pending request instance for this factory.
at line 611
Dispatcher|null
getDispatcher()
Get the current event dispatcher implementation.
at line 619
array
getGlobalMiddleware()
Get the array of global middleware.
at line 632
Factory
registerConnection(string $name, array $config = [])
Register a connection with the given name and configuration.
Boot-only. The connection preset and shared transport handler registry persist on the factory for the worker lifetime.
at line 640
bool
hasConnection(string $name)
Determine if the given HTTP client connection is registered.
at line 648
callable
getConnectionHandler(string $name)
Get the shared low-level transport handler for a connection.
at line 671
protected callable
createConnectionHandler(array $options)
Create a low-level transport handler for a connection.
at line 679
ClientInterface
createClient(HandlerStack $handlerStack, CookieJar $cookies)
Create new Guzzle client.
at line 690
array
getConnectionConfigs()
Get the configuration for all connections.
at line 698
array
getConnectionConfig(string $name)
Get the configuration for a specific connection.
at line 706
array
getConnectionOptions(string $name)
Get the request-option preset for a registered connection.
at line 719
Factory
setConnectionConfig(string $name, array $config)
Set the configuration for a specific connection.
Boot-only. Reconfiguration replaces the worker-lifetime preset and invalidates its shared transport handler for subsequent requests.
at line 735
Factory
forgetConnectionHandlers()
Forget all resolved connection handlers.
Boot or tests only. Request-time use forces subsequent requests to rebuild warmed keep-alive, DNS, and TLS session state.
at line 745
protected void
ensureConnectionIsRegistered(string $name)
Ensure the given HTTP client connection is registered.
at line 755
protected void
validateConnectionConfig(array $config)
Validate a registered connection configuration.
at line 763
static void
flushState()
Flush all static state.