On this page
Factory
class Factory (View source)
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected Dispatcher|null | $dispatcher | The event dispatcher implementation. |
|
| 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. |
Methods
| static void | macro(string $name, object|callable $macro) Register a custom macro. |
from Macroable |
| static void | mixin(object $mixin, bool $replace = true) Mix another object into the class. |
from Macroable |
| static bool | hasMacro(string $name) Checks if macro is registered. |
from Macroable |
| static void | flushMacros() Flush the existing macros. |
from Macroable |
| static mixed | __callStatic(string $method, array $parameters) Dynamically handle calls to the class. |
from Macroable |
| mixed | __call(string $method, array $parameters) Execute a method against a new pending request instance. |
|
| void | __construct(Dispatcher $dispatcher = null) Create a new factory instance. |
|
| static PromiseInterface | response(array|string $body = null, int $status = 200, array $headers = []) Create a new response instance 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 $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 | record() Begin recording request / response pairs. |
|
| void | recordRequestResponsePair(Request $request, Response $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 | newPendingRequest() Create a new pending request instance for this factory. |
|
| Dispatcher|null | getDispatcher() Get the current event dispatcher implementation. |
|
| PendingRequest | accept(string $contentType) No description |
|
| PendingRequest | acceptJson() No description |
|
| PendingRequest | asForm() No description |
|
| PendingRequest | asJson() No description |
|
| PendingRequest | asMultipart() No description |
|
| PendingRequest | async() No description |
|
| PendingRequest | attach(string|array $name, string|resource $contents = '', string|null $filename = null, array $headers = []) No description |
|
| PendingRequest | baseUrl(string $url) No description |
|
| PendingRequest | beforeSending(callable $callback) No description |
|
| PendingRequest | bodyFormat(string $format) No description |
|
| PendingRequest | contentType(string $contentType) No description |
|
| PendingRequest | dd() No description |
|
| PendingRequest | dump() No description |
|
| PendingRequest | retry(int $times, int $sleep, ?callable $when = null) No description |
|
| PendingRequest | sink(string|resource $to) No description |
|
| PendingRequest | stub(callable $callback) No description |
|
| PendingRequest | timeout(int $seconds) No description |
|
| PendingRequest | withBasicAuth(string $username, string $password) No description |
|
| PendingRequest | withBody(resource|string $content, string $contentType) No description |
|
| PendingRequest | withCookies(array $cookies, string $domain) No description |
|
| PendingRequest | withDigestAuth(string $username, string $password) No description |
|
| PendingRequest | withHeaders(array $headers) No description |
|
| PendingRequest | withMiddleware(callable $middleware) No description |
|
| PendingRequest | withOptions(array $options) No description |
|
| PendingRequest | withToken(string $token, string $type = 'Bearer') No description |
|
| PendingRequest | withUserAgent(string $userAgent) No description |
|
| PendingRequest | withoutRedirecting() No description |
|
| PendingRequest | withoutVerifying() No description |
|
| array | pool(callable $callback) No description |
|
| Response | delete(string $url, array $data = []) No description |
|
| Response | get(string $url, array|string|null $query = null) No description |
|
| Response | head(string $url, array|string|null $query = null) No description |
|
| Response | patch(string $url, array $data = []) No description |
|
| Response | post(string $url, array $data = []) No description |
|
| Response | put(string $url, array $data = []) No description |
|
| Response | send(string $method, string $url, array $options = []) No description |
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 $dispatcher = null)
Create a new factory instance.
static PromiseInterface response(array|string $body = null, int $status = 200, array $headers = [])
Create a new response instance 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 $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.
protected $this record()
Begin recording request / response pairs.
void recordRequestResponsePair(Request $request, Response $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.
protected PendingRequest newPendingRequest()
Create a new pending request instance for this factory.
Dispatcher|null getDispatcher()
Get the current event dispatcher implementation.
PendingRequest accept(string $contentType)
No description
PendingRequest acceptJson()
No description
PendingRequest asForm()
No description
PendingRequest asJson()
No description
PendingRequest asMultipart()
No description
PendingRequest async()
No description
PendingRequest attach(string|array $name, string|resource $contents = '', string|null $filename = null, array $headers = [])
No description
PendingRequest baseUrl(string $url)
No description
PendingRequest beforeSending(callable $callback)
No description
PendingRequest bodyFormat(string $format)
No description
PendingRequest contentType(string $contentType)
No description
PendingRequest dd()
No description
PendingRequest dump()
No description
PendingRequest retry(int $times, int $sleep, ?callable $when = null)
No description
PendingRequest sink(string|resource $to)
No description
PendingRequest stub(callable $callback)
No description
PendingRequest timeout(int $seconds)
No description
PendingRequest withBasicAuth(string $username, string $password)
No description
PendingRequest withBody(resource|string $content, string $contentType)
No description
PendingRequest withCookies(array $cookies, string $domain)
No description
PendingRequest withDigestAuth(string $username, string $password)
No description
PendingRequest withHeaders(array $headers)
No description
PendingRequest withMiddleware(callable $middleware)
No description
PendingRequest withOptions(array $options)
No description
PendingRequest withToken(string $token, string $type = 'Bearer')
No description
PendingRequest withUserAgent(string $userAgent)
No description
PendingRequest withoutRedirecting()
No description
PendingRequest withoutVerifying()
No description
array pool(callable $callback)
No description
Response delete(string $url, array $data = [])
No description
Response get(string $url, array|string|null $query = null)
No description
Response head(string $url, array|string|null $query = null)
No description
Response patch(string $url, array $data = [])
No description
Response post(string $url, array $data = [])
No description
Response put(string $url, array $data = [])
No description
Response send(string $method, string $url, array $options = [])
No description
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/8.x/Illuminate/Http/Client/Factory.html