Documentation

MockPlugin extends AbstractHasDispatcher
in package
implements EventSubscriberInterface, Countable

Queues mock responses or exceptions and delivers mock responses or exceptions in a fifo order.

Table of Contents

Interfaces

EventSubscriberInterface
An EventSubscriber knows himself what events he is interested in.
Countable

Properties

$eventDispatcher  : EventDispatcherInterface
$queue  : array<string|int, mixed>
$readBodies  : bool
$received  : array<string|int, mixed>
$temporary  : bool

Methods

__construct()  : mixed
addException()  : MockPlugin
Add an exception to the end of the queue
addResponse()  : MockPlugin
Add a response to the end of the queue
addSubscriber()  : self
Add an event subscriber to the dispatcher
clearQueue()  : MockPlugin
Clear the queue
count()  : int
Returns the number of remaining mock responses
dequeue()  : self
Get a response from the front of the list and add it to a request
dispatch()  : Event
Helper to dispatch Guzzle events and set the event name on the event
flush()  : mixed
Clear the array of received requests
getAllEvents()  : array<string|int, mixed>
Get a list of all of the events emitted from the class
getEventDispatcher()  : EventDispatcherInterface
Get the EventDispatcher of the request
getMockFile()  : Response
Get a mock response from a file
getQueue()  : array<string|int, mixed>
Returns an array of mock responses remaining in the queue
getReceivedRequests()  : array<string|int, mixed>
Get an array of requests that were mocked by this plugin
getSubscribedEvents()  : array<string|int, mixed>
Returns an array of event names this subscriber wants to listen to.
isTemporary()  : bool
Check if this is a temporary plugin
onRequestBeforeSend()  : mixed
Called when a request is about to be sent
readBodies()  : self
Set whether or not to consume the entity body of a request when a mock response is used
setEventDispatcher()  : self
Set the EventDispatcher of the request

Properties

$queue

protected array<string|int, mixed> $queue = array()

Array of mock responses / exceptions

$readBodies

protected bool $readBodies

Whether or not to consume an entity body when a mock response is served

$received

protected array<string|int, mixed> $received = array()

Array of requests that were mocked

$temporary

protected bool $temporary = false

Whether or not to remove the plugin when the queue is empty

Methods

__construct()

public __construct([array<string|int, mixed> $items = null ][, bool $temporary = false ][, bool $readBodies = false ]) : mixed
Parameters
$items : array<string|int, mixed> = null

Array of responses or exceptions to queue

$temporary : bool = false

Set to TRUE to remove the plugin when the queue is empty

$readBodies : bool = false

Set to TRUE to consume the entity body when a mock is served

count()

Returns the number of remaining mock responses

public count() : int
Return values
int

dequeue()

Get a response from the front of the list and add it to a request

public dequeue(RequestInterface $request) : self
Parameters
$request : RequestInterface

Request to mock

Tags
throws
CurlException

When request.send is called and an exception is queued

Return values
self

dispatch()

Helper to dispatch Guzzle events and set the event name on the event

public dispatch(mixed $eventName[, array<string|int, mixed> $context = array() ]) : Event
Parameters
$eventName : mixed

Name of the event to dispatch

$context : array<string|int, mixed> = array()

Context of the event

Return values
Event

Returns the created event object

flush()

Clear the array of received requests

public flush() : mixed

getAllEvents()

Get a list of all of the events emitted from the class

public static getAllEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>

getQueue()

Returns an array of mock responses remaining in the queue

public getQueue() : array<string|int, mixed>
Return values
array<string|int, mixed>

getReceivedRequests()

Get an array of requests that were mocked by this plugin

public getReceivedRequests() : array<string|int, mixed>
Return values
array<string|int, mixed>

getSubscribedEvents()

Returns an array of event names this subscriber wants to listen to.

public static getSubscribedEvents() : array<string|int, mixed>

The array keys are event names and the value can be:

  • The method name to call (priority defaults to 0)
  • An array composed of the method name to call and the priority
  • An array of arrays composed of the method names to call and respective priorities, or 0 if unset

For instance:

  • array('eventName' => 'methodName')
  • array('eventName' => array('methodName', $priority))
  • array('eventName' => array(array('methodName1', $priority), array('methodName2')))
Return values
array<string|int, mixed>

The event names to listen to

isTemporary()

Check if this is a temporary plugin

public isTemporary() : bool
Return values
bool

onRequestBeforeSend()

Called when a request is about to be sent

public onRequestBeforeSend(Event $event) : mixed
Parameters
$event : Event
Tags
throws
OutOfBoundsException

When queue is empty

readBodies()

Set whether or not to consume the entity body of a request when a mock response is used

public readBodies(bool $readBodies) : self
Parameters
$readBodies : bool

Set to true to read and consume entity bodies

Return values
self

        
On this page

Search results