\Guzzle\Plugin\MockMockPlugin

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

Summary

Methods
Properties
Constants
getAllEvents()
setEventDispatcher()
getEventDispatcher()
dispatch()
addSubscriber()
__construct()
getSubscribedEvents()
getMockFile()
readBodies()
count()
addResponse()
addException()
clearQueue()
getQueue()
isTemporary()
dequeue()
flush()
getReceivedRequests()
onRequestBeforeSend()
No public properties found
No constants found
No protected methods found
$eventDispatcher
$queue
$temporary
$received
$readBodies
N/A
No private methods found
No private properties found
N/A

Properties

$queue

$queue : array

Type

array — Array of mock responses / exceptions

$temporary

$temporary : boolean

Type

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

$received

$received : array

Type

array — Array of requests that were mocked

$readBodies

$readBodies : boolean

Type

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

Methods

getAllEvents()

getAllEvents() : array

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

Returns

array

dispatch()

dispatch(string  $eventName, array  $context = array()) : \Guzzle\Common\Event

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

Parameters

string $eventName

Name of the event to dispatch

array $context

Context of the event

Returns

\Guzzle\Common\Event

Returns the created event object

__construct()

__construct(array  $items = null, boolean  $temporary = false, boolean  $readBodies = false) 

Parameters

array $items

Array of responses or exceptions to queue

boolean $temporary

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

boolean $readBodies

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

getSubscribedEvents()

getSubscribedEvents() : array

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

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')))

Returns

array —

The event names to listen to

getMockFile()

getMockFile(string  $path) : \Guzzle\Http\Message\Response

Get a mock response from a file

Parameters

string $path

File to retrieve a mock response from

Throws

\Guzzle\Common\Exception\InvalidArgumentException

if the file is not found

Returns

\Guzzle\Http\Message\Response

readBodies()

readBodies(boolean  $readBodies) : self

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

Parameters

boolean $readBodies

Set to true to read and consume entity bodies

Returns

self

count()

count() : integer

Returns the number of remaining mock responses

Returns

integer

addResponse()

addResponse(string|\Guzzle\Http\Message\Response  $response) : \Guzzle\Plugin\Mock\MockPlugin

Add a response to the end of the queue

Parameters

string|\Guzzle\Http\Message\Response $response

Response object or path to response file

Throws

\Guzzle\Common\Exception\InvalidArgumentException

if a string or Response is not passed

Returns

\Guzzle\Plugin\Mock\MockPlugin

getQueue()

getQueue() : array

Returns an array of mock responses remaining in the queue

Returns

array

isTemporary()

isTemporary() : boolean

Check if this is a temporary plugin

Returns

boolean

dequeue()

dequeue(\Guzzle\Http\Message\RequestInterface  $request) : self

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

Parameters

\Guzzle\Http\Message\RequestInterface $request

Request to mock

Throws

\Guzzle\Http\Exception\CurlException

When request.send is called and an exception is queued

Returns

self

flush()

flush() 

Clear the array of received requests

getReceivedRequests()

getReceivedRequests() : array

Get an array of requests that were mocked by this plugin

Returns

array

onRequestBeforeSend()

onRequestBeforeSend(\Guzzle\Common\Event  $event) 

Called when a request is about to be sent

Parameters

\Guzzle\Common\Event $event

Throws

\OutOfBoundsException

When queue is empty