Open Journal Systems  3.3.0
Guzzle\Plugin\Mock\MockPlugin Class Reference
Inheritance diagram for Guzzle\Plugin\Mock\MockPlugin:
Guzzle\Common\AbstractHasDispatcher Symfony\Component\EventDispatcher\EventSubscriberInterface Guzzle\Common\HasDispatcherInterface

Public Member Functions

 __construct (array $items=null, $temporary=false, $readBodies=false)
 
 addException (CurlException $e)
 
 addResponse ($response)
 
 clearQueue ()
 
 count ()
 
 dequeue (RequestInterface $request)
 
 flush ()
 
 getQueue ()
 
 getReceivedRequests ()
 
 isTemporary ()
 
 onRequestBeforeSend (Event $event)
 
 readBodies ($readBodies)
 
- Public Member Functions inherited from Guzzle\Common\AbstractHasDispatcher
 addSubscriber (EventSubscriberInterface $subscriber)
 
 dispatch ($eventName, array $context=array())
 
 getEventDispatcher ()
 
 setEventDispatcher (EventDispatcherInterface $eventDispatcher)
 

Static Public Member Functions

static getAllEvents ()
 
static getMockFile ($path)
 
static getSubscribedEvents ()
 

Protected Attributes

 $queue = array()
 
 $readBodies
 
 $received = array()
 
 $temporary = false
 
- Protected Attributes inherited from Guzzle\Common\AbstractHasDispatcher
 $eventDispatcher
 

Detailed Description

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

Definition at line 17 of file MockPlugin.php.

Constructor & Destructor Documentation

◆ __construct()

Guzzle\Plugin\Mock\MockPlugin::__construct ( array  $items = null,
  $temporary = false,
  $readBodies = false 
)
Parameters
array$itemsArray of responses or exceptions to queue
bool$temporarySet to TRUE to remove the plugin when the queue is empty
bool$readBodiesSet to TRUE to consume the entity body when a mock is served

Definition at line 48 of file MockPlugin.php.

References Guzzle\Plugin\Mock\MockPlugin\$readBodies, Guzzle\Plugin\Mock\MockPlugin\$temporary, Guzzle\Plugin\Mock\MockPlugin\addException(), Guzzle\Plugin\Mock\MockPlugin\addResponse(), and Guzzle\Plugin\Mock\MockPlugin\readBodies().

Member Function Documentation

◆ addException()

Guzzle\Plugin\Mock\MockPlugin::addException ( CurlException  $e)

Add an exception to the end of the queue

Parameters
CurlException$eException to throw when the request is executed
Returns
MockPlugin

Definition at line 145 of file MockPlugin.php.

Referenced by Guzzle\Plugin\Mock\MockPlugin\__construct().

◆ addResponse()

Guzzle\Plugin\Mock\MockPlugin::addResponse (   $response)

Add a response to the end of the queue

Parameters
string | Response$responseResponse object or path to response file
Returns
MockPlugin
Exceptions
InvalidArgumentExceptionif a string or Response is not passed

Definition at line 124 of file MockPlugin.php.

References Guzzle\Plugin\Mock\MockPlugin\getMockFile().

Referenced by Guzzle\Plugin\Mock\MockPlugin\__construct().

◆ clearQueue()

Guzzle\Plugin\Mock\MockPlugin::clearQueue ( )

Clear the queue

Returns
MockPlugin

Definition at line 157 of file MockPlugin.php.

◆ count()

Guzzle\Plugin\Mock\MockPlugin::count ( )

Returns the number of remaining mock responses

Returns
int

Definition at line 111 of file MockPlugin.php.

Referenced by Guzzle\Plugin\Mock\MockPlugin\onRequestBeforeSend().

◆ dequeue()

Guzzle\Plugin\Mock\MockPlugin::dequeue ( RequestInterface  $request)

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

Parameters
RequestInterface$requestRequest to mock
Returns
self
Exceptions
CurlExceptionWhen request.send is called and an exception is queued

Definition at line 192 of file MockPlugin.php.

References Guzzle\Common\AbstractHasDispatcher\dispatch(), Guzzle\Common\HasDispatcherInterface\getEventDispatcher(), Guzzle\Plugin\Mock\MockPlugin\readBodies(), Guzzle\Http\Message\RequestInterface\setResponse(), Guzzle\Http\Message\RequestInterface\setState(), and Guzzle\Http\Message\RequestInterface\STATE_ERROR.

Referenced by Guzzle\Plugin\Mock\MockPlugin\onRequestBeforeSend().

◆ flush()

Guzzle\Plugin\Mock\MockPlugin::flush ( )

Clear the array of received requests

Definition at line 222 of file MockPlugin.php.

◆ getAllEvents()

static Guzzle\Plugin\Mock\MockPlugin::getAllEvents ( )
static

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

Returns
array

Reimplemented from Guzzle\Common\AbstractHasDispatcher.

Definition at line 69 of file MockPlugin.php.

Referenced by Guzzle\Tests\Plugin\Mock\MockPluginTest\testDescribesEvents().

◆ getMockFile()

static Guzzle\Plugin\Mock\MockPlugin::getMockFile (   $path)
static

◆ getQueue()

Guzzle\Plugin\Mock\MockPlugin::getQueue ( )

Returns an array of mock responses remaining in the queue

Returns
array

Definition at line 169 of file MockPlugin.php.

References Guzzle\Plugin\Mock\MockPlugin\$queue.

◆ getReceivedRequests()

Guzzle\Plugin\Mock\MockPlugin::getReceivedRequests ( )

Get an array of requests that were mocked by this plugin

Returns
array

Definition at line 232 of file MockPlugin.php.

References Guzzle\Plugin\Mock\MockPlugin\$received.

◆ getSubscribedEvents()

static Guzzle\Plugin\Mock\MockPlugin::getSubscribedEvents ( )
static

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

Implements Symfony\Component\EventDispatcher\EventSubscriberInterface.

Definition at line 63 of file MockPlugin.php.

Referenced by Guzzle\Tests\Plugin\Mock\MockPluginTest\testDescribesSubscribedEvents().

◆ isTemporary()

Guzzle\Plugin\Mock\MockPlugin::isTemporary ( )

Check if this is a temporary plugin

Returns
bool

Definition at line 179 of file MockPlugin.php.

References Guzzle\Plugin\Mock\MockPlugin\$temporary.

◆ onRequestBeforeSend()

Guzzle\Plugin\Mock\MockPlugin::onRequestBeforeSend ( Event  $event)

Called when a request is about to be sent

Parameters
Event$event
Exceptions

Definition at line 243 of file MockPlugin.php.

References Guzzle\Plugin\Mock\MockPlugin\count(), and Guzzle\Plugin\Mock\MockPlugin\dequeue().

◆ readBodies()

Guzzle\Plugin\Mock\MockPlugin::readBodies (   $readBodies)

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

Parameters
bool$readBodiesSet to true to read and consume entity bodies
Returns
self

Definition at line 99 of file MockPlugin.php.

References Guzzle\Plugin\Mock\MockPlugin\$readBodies.

Referenced by Guzzle\Plugin\Mock\MockPlugin\__construct(), and Guzzle\Plugin\Mock\MockPlugin\dequeue().

Field Documentation

◆ $queue

array Guzzle\Plugin\Mock\MockPlugin::$queue = array()
protected

Array of mock responses / exceptions

Definition at line 23 of file MockPlugin.php.

Referenced by Guzzle\Plugin\Mock\MockPlugin\getQueue().

◆ $readBodies

bool Guzzle\Plugin\Mock\MockPlugin::$readBodies
protected

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

Definition at line 41 of file MockPlugin.php.

Referenced by Guzzle\Plugin\Mock\MockPlugin\__construct(), and Guzzle\Plugin\Mock\MockPlugin\readBodies().

◆ $received

array Guzzle\Plugin\Mock\MockPlugin::$received = array()
protected

Array of requests that were mocked

Definition at line 35 of file MockPlugin.php.

Referenced by Guzzle\Plugin\Mock\MockPlugin\getReceivedRequests().

◆ $temporary

bool Guzzle\Plugin\Mock\MockPlugin::$temporary = false
protected

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

Definition at line 29 of file MockPlugin.php.

Referenced by Guzzle\Plugin\Mock\MockPlugin\__construct(), and Guzzle\Plugin\Mock\MockPlugin\isTemporary().


The documentation for this class was generated from the following file: