Factory
class Factory mixin PendingRequest (View source)
Traits
Properties
static protected array | $macros | The registered string macros. |
from Macroable |
protected Dispatcher|null | $dispatcher | The event dispatcher implementation. |
|
protected array | $globalMiddleware | The middleware to apply to every request. |
|
protected Closure|array | $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. |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Execute a method against a new pending request instance.
Create a new factory 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 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.
Begin recording request / response pairs.
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.
Details
static void
macro(string $name, object|callable $macro)
Register a custom macro.
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
static bool
hasMacro(string $name)
Checks if macro is registered.
static void
flushMacros()
Flush the existing macros.
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
mixed
__call(string $method, array $parameters)
Execute a method against a new pending request instance.
void
__construct(Dispatcher|null $dispatcher = null)
Create a new factory instance.
$this
globalMiddleware(callable $middleware)
Add middleware to apply to every request.
$this
globalRequestMiddleware(callable $middleware)
Add request middleware to apply to every request.
$this
globalResponseMiddleware(callable $middleware)
Add response middleware to apply to every request.
$this
globalOptions(Closure|array $options)
Set the options to apply to every request.
static PromiseInterface
response(array|string|null $body = null, int $status = 200, array $headers = [])
Create a new response instance for use during stubbing.
static PromiseInterface
failedConnection(string|null $message = null)
Create a new connection exception for use during stubbing.
ResponseSequence
sequence(array $responses = [])
Get an invokable object that returns a sequence of responses in order for use during stubbing.
$this
fake(callable|array|null $callback = null)
Register a stub callable that will intercept requests and be able to return stub responses.
ResponseSequence
fakeSequence(string $url = '*')
Register a response sequence for the given URL pattern.
$this
stubUrl(string $url, Response|PromiseInterface|callable $callback)
Stub the given URL using the given callback.
$this
preventStrayRequests(bool $prevent = true)
Indicate that an exception should be thrown if any request is not faked.
bool
preventingStrayRequests()
Determine if stray requests are being prevented.
$this
allowStrayRequests()
Indicate that an exception should not be thrown if any request is not faked.
protected $this
record()
Begin recording request / response pairs.
void
recordRequestResponsePair(Request $request, Response|null $response)
Record a request response pair.
void
assertSent(callable $callback)
Assert that a request / response pair was recorded matching a given truth test.
void
assertSentInOrder(array $callbacks)
Assert that the given request was sent in the given order.
void
assertNotSent(callable $callback)
Assert that a request / response pair was not recorded matching a given truth test.
void
assertNothingSent()
Assert that no request / response pair was recorded.
void
assertSentCount(int $count)
Assert how many requests have been recorded.
void
assertSequencesAreEmpty()
Assert that every created response sequence is empty.
Collection
recorded(callable $callback = null)
Get a collection of the request / response pairs matching the given truth test.
PendingRequest
createPendingRequest()
Create a new pending request instance for this factory.
protected PendingRequest
newPendingRequest()
Instantiate a new pending request instance for this factory.
Dispatcher|null
getDispatcher()
Get the current event dispatcher implementation.
array
getGlobalMiddleware()
Get the array of global middleware.