Factory
class Factory mixin PendingRequest
Traits
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.
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.
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 670
mixed
__call(string $method, array $parameters)
Execute a method against a new pending request instance.
at line 93
__construct(Dispatcher|null $dispatcher = null)
Create a new factory instance.
at line 101
Factory
globalMiddleware(callable $middleware)
Add middleware to apply to every request.
at line 111
Factory
globalRequestMiddleware(callable $middleware)
Add request middleware to apply to every request.
at line 121
Factory
globalResponseMiddleware(callable $middleware)
Add response middleware to apply to every request.
at line 134
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 144
static PromiseInterface
response(mixed $body = null, int $status = 200, array $headers = [])
Create a new response instance for use during stubbing.
at line 159
static Response
psr7Response(mixed $body = null, int $status = 200, array $headers = [])
Create a new PSR-7 response instance for use during stubbing.
at line 186
static protected array
normalizeResponseHeaders(array $headers)
Normalize the given fake response headers.
at line 224
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 240
static RequestException
failedRequest(mixed $body = null, int $status = 200, array $headers = [])
Create a new RequestException instance for use during stubbing.
at line 251
static Closure
failedConnection(string|null $message = null)
Create a new connection exception for use during stubbing.
at line 266
ResponseSequence
sequence(array $responses = [])
Get an invokable object that returns a sequence of responses in order for use during stubbing.
at line 274
Factory
fake(array|callable|null $callback = null)
Register a stub callable that will intercept requests and be able to return stub responses.
at line 320
ResponseSequence
fakeSequence(string $url = '*')
Register a response sequence for the given URL pattern.
at line 330
Factory
stubUrl(string $url, array|callable|int|PromiseInterface|Response|string $callback)
Stub the given URL using the given callback.
at line 363
Factory
preventStrayRequests(bool $prevent = true)
Indicate that an exception should be thrown if any request is not faked.
at line 373
bool
preventingStrayRequests()
Determine if stray requests are being prevented.
at line 381
Factory
allowStrayRequests(array|null $only = null)
Indicate that an exception should not be thrown if any request is not faked.
at line 396
protected Factory
record()
Begin recording request / response pairs.
at line 406
void
recordRequestResponsePair(Request $request, Response|null $response)
Record a request response pair.
at line 416
void
assertSent(callable $callback)
Assert that a request / response pair was recorded matching a given truth test.
at line 427
void
assertSentInOrder(array $callbacks)
Assert that the given request was sent in the given order.
at line 449
void
assertNotSent(callable $callback)
Assert that a request / response pair was not recorded matching a given truth test.
at line 460
void
assertNothingSent()
Assert that no request / response pair was recorded.
at line 471
void
assertSentCount(int $count)
Assert how many requests have been recorded.
at line 479
void
assertSequencesAreEmpty()
Assert that every created response sequence is empty.
at line 492
Collection
recorded(callable|null $callback = null)
Get a collection of the request / response pairs matching the given truth test.
at line 509
PendingRequest
createPendingRequest()
Create a new pending request instance for this factory.
at line 522
protected PendingRequest
newPendingRequest()
Instantiate a new pending request instance for this factory.
at line 536
Dispatcher|null
getDispatcher()
Get the current event dispatcher implementation.
at line 544
array
getGlobalMiddleware()
Get the array of global middleware.
at line 555
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 563
bool
hasConnection(string $name)
Determine if the given HTTP client connection is registered.
at line 571
callable
getConnectionHandler(string $name)
Get the shared low-level transport handler for a connection.
at line 583
protected callable
createConnectionHandler(array $options)
Create a low-level transport handler for a connection.
at line 591
ClientInterface
createClient(HandlerStack $handlerStack, CookieJar $cookies)
Create new Guzzle client.
at line 602
array
getConnectionConfigs()
Get the configuration for all connections.
at line 610
array
getConnectionConfig(string $name)
Get the configuration for a specific connection.
at line 618
array
getConnectionOptions(string $name)
Get the request-option preset for a registered connection.
at line 631
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 644
protected void
ensureConnectionIsRegistered(string $name)
Ensure the given HTTP client connection is registered.
at line 654
protected void
validateConnectionConfig(array $config)
Validate a registered connection configuration.
at line 662
static void
flushState()
Flush all static state.