Class Guzzle\Plugin\Mock\MockPlugin

InheritanceGuzzle\Plugin\Mock\MockPlugin » Guzzle\Common\AbstractHasDispatcher
ImplementsCountable, Guzzle\Common\HasDispatcherInterface, Symfony\Component\EventDispatcher\EventSubscriberInterface

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

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$eventDispatcher Symfony\Component\EventDispatcher\EventDispatcherInterface Guzzle\Common\AbstractHasDispatcher
$queue array Array of mock responses / exceptions Guzzle\Plugin\Mock\MockPlugin
$readBodies bool Whether or not to consume an entity body when a mock response is served Guzzle\Plugin\Mock\MockPlugin
$received array Array of requests that were mocked Guzzle\Plugin\Mock\MockPlugin
$temporary bool Whether or not to remove the plugin when the queue is empty Guzzle\Plugin\Mock\MockPlugin

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Guzzle\Plugin\Mock\MockPlugin
addException() Add an exception to the end of the queue Guzzle\Plugin\Mock\MockPlugin
addResponse() Add a response to the end of the queue Guzzle\Plugin\Mock\MockPlugin
addSubscriber() Guzzle\Common\AbstractHasDispatcher
clearQueue() Clear the queue Guzzle\Plugin\Mock\MockPlugin
count() Returns the number of remaining mock responses Guzzle\Plugin\Mock\MockPlugin
dequeue() Get a response from the front of the list and add it to a request Guzzle\Plugin\Mock\MockPlugin
dispatch() Guzzle\Common\AbstractHasDispatcher
flush() Clear the array of received requests Guzzle\Plugin\Mock\MockPlugin
getAllEvents() Guzzle\Plugin\Mock\MockPlugin
getEventDispatcher() Guzzle\Common\AbstractHasDispatcher
getMockFile() Get a mock response from a file Guzzle\Plugin\Mock\MockPlugin
getQueue() Returns an array of mock responses remaining in the queue Guzzle\Plugin\Mock\MockPlugin
getReceivedRequests() Get an array of requests that were mocked by this plugin Guzzle\Plugin\Mock\MockPlugin
getSubscribedEvents() Guzzle\Plugin\Mock\MockPlugin
isTemporary() Check if this is a temporary plugin Guzzle\Plugin\Mock\MockPlugin
onRequestBeforeSend() Called when a request is about to be sent Guzzle\Plugin\Mock\MockPlugin
readBodies() Set whether or not to consume the entity body of a request when a mock response is used Guzzle\Plugin\Mock\MockPlugin
setEventDispatcher() Guzzle\Common\AbstractHasDispatcher

Property Details

$queue protected property

Array of mock responses / exceptions

protected array $queue = []
$readBodies protected property

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

protected bool $readBodies null
$received protected property

Array of requests that were mocked

protected array $received = []
$temporary protected property

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

protected bool $temporary false

Method Details

__construct() public method

public void __construct ( array $items null, $temporary false, $readBodies false )
$items array

Array of responses or exceptions to queue

$temporary bool

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

$readBodies bool

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

addException() public method

Add an exception to the end of the queue

public Guzzle\Plugin\Mock\MockPlugin addException ( Guzzle\Http\Exception\CurlException $e )
$e Guzzle\Http\Exception\CurlException

Exception to throw when the request is executed

addResponse() public method

Add a response to the end of the queue

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

Response object or path to response file

throws Guzzle\Common\Exception\InvalidArgumentException

if a string or Response is not passed

clearQueue() public method

Clear the queue

public Guzzle\Plugin\Mock\MockPlugin clearQueue ( )
count() public method

Returns the number of remaining mock responses

public int count ( )
dequeue() public method

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

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

Request to mock

throws Guzzle\Http\Exception\CurlException

When request.send is called and an exception is queued

flush() public method

Clear the array of received requests

public void flush ( )
getAllEvents() public static method

public static void getAllEvents ( )
getMockFile() public static method

Get a mock response from a file

public static Guzzle\Http\Message\Response getMockFile ( $path )
$path string

File to retrieve a mock response from

throws Guzzle\Common\Exception\InvalidArgumentException

if the file is not found

getQueue() public method

Returns an array of mock responses remaining in the queue

public array getQueue ( )
getReceivedRequests() public method

Get an array of requests that were mocked by this plugin

public array getReceivedRequests ( )
getSubscribedEvents() public static method

public static void getSubscribedEvents ( )
isTemporary() public method

Check if this is a temporary plugin

public bool isTemporary ( )
onRequestBeforeSend() public method

Called when a request is about to be sent

public void onRequestBeforeSend ( Guzzle\Common\Event $event )
$event Guzzle\Common\Event
throws OutOfBoundsException

When queue is empty

readBodies() public method

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

public self readBodies ( $readBodies )
$readBodies bool

Set to true to read and consume entity bodies