HTTP_Request2
[ class tree: HTTP_Request2 ] [ index: HTTP_Request2 ] [ all elements ]

Class: HTTP_Request2_Adapter_Mock

Source Location: /HTTP_Request2-0.3.0/Request2/Adapter/Mock.php

Class Overview

HTTP_Request2_Adapter
   |
   --HTTP_Request2_Adapter_Mock

Mock adapter intended for testing


Author(s):

Version:

  • Release: 0.3.0

Variables

Methods


Inherited Variables

Inherited Methods

Class: HTTP_Request2_Adapter

HTTP_Request2_Adapter::calculateRequestLength()
Calculates length of the request body, adds proper headers
HTTP_Request2_Adapter::sendRequest()
Sends request to the remote server and returns its response

Class Details

[line 71]
Mock adapter intended for testing

Can be used to test applications depending on HTTP_Request2 package without actually performing any HTTP requests. This adapter will return responses previously added via addResponse()

  1.  $mock = new HTTP_Request2_Adapter_Mock();
  2.  $mock->addResponse("HTTP/1.1 ... ");
  3.  
  4.  $request = new HTTP_Request2();
  5.  $request->setAdapter($mock);
  6.  
  7.  // This will return the response set above
  8.  $response $req->send();



[ Top ]


Class Variables

$responses = array()

[line 77]

A queue of responses to be returned by sendRequest()
  • Access: protected

Type:   array


[ Top ]



Method Detail

addResponse   [line 114]

void addResponse( mixed $response)

Adds response to the queue
  • Throws: HTTP_Request2_Exception
  • Access: public

Parameters:

mixed   $response   —  either a string, a pointer to an open file, a HTTP_Request2_Response or Exception object

[ Top ]

createResponseFromFile   [line 157]

HTTP_Request2_Response createResponseFromFile( resource $fp)

Creates a new HTTP_Request2_Response object from a file
  • Throws: HTTP_Request2_Exception
  • Access: public

Parameters:

resource   $fp   —  file pointer returned by fopen()

[ Top ]

createResponseFromString   [line 135]

HTTP_Request2_Response createResponseFromString( string $str)

Creates a new HTTP_Request2_Response object from a string
  • Throws: HTTP_Request2_Exception
  • Access: public

Parameters:

string   $str   — 

[ Top ]

sendRequest   [line 89]

HTTP_Request2_Response sendRequest( HTTP_Request2 $request)

Returns the next response from the queue built by addResponse()

If the queue is empty will return default empty response with status 400, if an Exception object was added to the queue it will be thrown.

  • Throws: Exception
  • Access: public

Overrides HTTP_Request2_Adapter::sendRequest() (Sends request to the remote server and returns its response)

Parameters:

HTTP_Request2   $request   — 

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:28:59 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.