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.

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 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.

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.

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.

recorded(callable $callback = null)

Get a collection of the request / response pairs matching the given truth test.

newPendingRequest()

Create a new pending request instance for this factory.

Dispatcher|null
getDispatcher()

Get the current event dispatcher implementation.

accept(string $contentType)

No description

acceptJson()

No description

asForm()

No description

asJson()

No description

asMultipart()

No description

async()

No description

attach(string|array $name, string $contents = '', string|null $filename = null, array $headers = [])

No description

baseUrl(string $url)

No description

beforeSending(callable $callback)

No description

bodyFormat(string $format)

No description

contentType(string $contentType)

No description

dd()

No description

dump()

No description

retry(int $times, int $sleep, ?callable $when = null)

No description

sink(string|resource $to)

No description

stub(callable $callback)

No description

timeout(int $seconds)

No description

withBasicAuth(string $username, string $password)

No description

withBody(resource|string $content, string $contentType)

No description

withCookies(array $cookies, string $domain)

No description

withDigestAuth(string $username, string $password)

No description

withHeaders(array $headers)

No description

withMiddleware(callable $middleware)

No description

withOptions(array $options)

No description

withToken(string $token, string $type = 'Bearer')

No description

withUserAgent(string $userAgent)

No description

withoutVerifying()

No description

array
pool(callable $callback)

No description

delete(string $url, array $data = [])

No description

get(string $url, array|string|null $query = null)

No description

head(string $url, array|string|null $query = null)

No description

patch(string $url, array $data = [])

No description

post(string $url, array $data = [])

No description

put(string $url, array $data = [])

No description

send(string $method, string $url, array $options = [])

No description

Details

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Execute a method against a new pending request instance.

Parameters

string $method
array $parameters

Return Value

mixed

void __construct(Dispatcher $dispatcher = null)

Create a new factory instance.

Parameters

Dispatcher $dispatcher

Return Value

void

static PromiseInterface response(array|string $body = null, int $status = 200, array $headers = [])

Create a new response instance for use during stubbing.

Parameters

array|string $body
int $status
array $headers

Return Value

PromiseInterface

ResponseSequence sequence(array $responses = [])

Get an invokable object that returns a sequence of responses in order for use during stubbing.

Parameters

array $responses

Return Value

ResponseSequence

$this fake(callable|array $callback = null)

Register a stub callable that will intercept requests and be able to return stub responses.

Parameters

callable|array $callback

Return Value

$this

ResponseSequence fakeSequence(string $url = '*')

Register a response sequence for the given URL pattern.

Parameters

string $url

Return Value

ResponseSequence

$this stubUrl(string $url, Response|PromiseInterface|callable $callback)

Stub the given URL using the given callback.

Parameters

string $url
Response|PromiseInterface|callable $callback

Return Value

$this

protected $this record()

Begin recording request / response pairs.

Return Value

$this

void recordRequestResponsePair(Request $request, Response $response)

Record a request response pair.

Parameters

Request $request
Response $response

Return Value

void

void assertSent(callable $callback)

Assert that a request / response pair was recorded matching a given truth test.

Parameters

callable $callback

Return Value

void

void assertSentInOrder(array $callbacks)

Assert that the given request was sent in the given order.

Parameters

array $callbacks

Return Value

void

void assertNotSent(callable $callback)

Assert that a request / response pair was not recorded matching a given truth test.

Parameters

callable $callback

Return Value

void

void assertNothingSent()

Assert that no request / response pair was recorded.

Return Value

void

void assertSentCount(int $count)

Assert how many requests have been recorded.

Parameters

int $count

Return Value

void

void assertSequencesAreEmpty()

Assert that every created response sequence is empty.

Return Value

void

Collection recorded(callable $callback = null)

Get a collection of the request / response pairs matching the given truth test.

Parameters

callable $callback

Return Value

Collection

protected PendingRequest newPendingRequest()

Create a new pending request instance for this factory.

Return Value

PendingRequest

Dispatcher|null getDispatcher()

Get the current event dispatcher implementation.

Return Value

Dispatcher|null

PendingRequest accept(string $contentType)

No description

Parameters

string $contentType

Return Value

PendingRequest

PendingRequest acceptJson()

No description

Return Value

PendingRequest

PendingRequest asForm()

No description

Return Value

PendingRequest

PendingRequest asJson()

No description

Return Value

PendingRequest

PendingRequest asMultipart()

No description

Return Value

PendingRequest

PendingRequest async()

No description

Return Value

PendingRequest

PendingRequest attach(string|array $name, string $contents = '', string|null $filename = null, array $headers = [])

No description

Parameters

string|array $name
string $contents
string|null $filename
array $headers

Return Value

PendingRequest

PendingRequest baseUrl(string $url)

No description

Parameters

string $url

Return Value

PendingRequest

PendingRequest beforeSending(callable $callback)

No description

Parameters

callable $callback

Return Value

PendingRequest

PendingRequest bodyFormat(string $format)

No description

Parameters

string $format

Return Value

PendingRequest

PendingRequest contentType(string $contentType)

No description

Parameters

string $contentType

Return Value

PendingRequest

PendingRequest dd()

No description

Return Value

PendingRequest

PendingRequest dump()

No description

Return Value

PendingRequest

PendingRequest retry(int $times, int $sleep, ?callable $when = null)

No description

Parameters

int $times
int $sleep
?callable $when

Return Value

PendingRequest

PendingRequest sink(string|resource $to)

No description

Parameters

string|resource $to

Return Value

PendingRequest

PendingRequest stub(callable $callback)

No description

Parameters

callable $callback

Return Value

PendingRequest

PendingRequest timeout(int $seconds)

No description

Parameters

int $seconds

Return Value

PendingRequest

PendingRequest withBasicAuth(string $username, string $password)

No description

Parameters

string $username
string $password

Return Value

PendingRequest

PendingRequest withBody(resource|string $content, string $contentType)

No description

Parameters

resource|string $content
string $contentType

Return Value

PendingRequest

PendingRequest withCookies(array $cookies, string $domain)

No description

Parameters

array $cookies
string $domain

Return Value

PendingRequest

PendingRequest withDigestAuth(string $username, string $password)

No description

Parameters

string $username
string $password

Return Value

PendingRequest

PendingRequest withHeaders(array $headers)

No description

Parameters

array $headers

Return Value

PendingRequest

PendingRequest withMiddleware(callable $middleware)

No description

Parameters

callable $middleware

Return Value

PendingRequest

PendingRequest withOptions(array $options)

No description

Parameters

array $options

Return Value

PendingRequest

PendingRequest withToken(string $token, string $type = 'Bearer')

No description

Parameters

string $token
string $type

Return Value

PendingRequest

PendingRequest withUserAgent(string $userAgent)

No description

Parameters

string $userAgent

Return Value

PendingRequest

PendingRequest withoutRedirecting()

No description

Return Value

PendingRequest

PendingRequest withoutVerifying()

No description

Return Value

PendingRequest

array pool(callable $callback)

No description

Parameters

callable $callback

Return Value

array

Response delete(string $url, array $data = [])

No description

Parameters

string $url
array $data

Return Value

Response

Response get(string $url, array|string|null $query = null)

No description

Parameters

string $url
array|string|null $query

Return Value

Response

Response head(string $url, array|string|null $query = null)

No description

Parameters

string $url
array|string|null $query

Return Value

Response

Response patch(string $url, array $data = [])

No description

Parameters

string $url
array $data

Return Value

Response

Response post(string $url, array $data = [])

No description

Parameters

string $url
array $data

Return Value

Response

Response put(string $url, array $data = [])

No description

Parameters

string $url
array $data

Return Value

Response

Response send(string $method, string $url, array $options = [])

No description

Parameters

string $method
string $url
array $options

Return Value

Response