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

Class: HTTP_Request2_Adapter_Mock

Source Location: /HTTP_Request2-2.2.1/HTTP/Request2/Adapter/Mock.php

Class Overview

HTTP_Request2_Adapter
   |
   --HTTP_Request2_Adapter_Mock

Mock adapter intended for testing


Author(s):

Version:

  • Release: 2.2.1

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 50]
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 56]

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

Type:   array


[ Top ]



Method Detail

addResponse   [line 107]

void addResponse( mixed $response, [string $url = null])

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

Parameters:

mixed   $response   —  either a string, a pointer to an open file, an instance of HTTP_Request2_Response or Exception
string   $url   —  A request URL this response should be valid for (see http://pear.php.net/bugs/bug.php?id=19276)

[ Top ]

createResponseFromFile   [line 152]

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 129]

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   —  string containing HTTP response message

[ Top ]

sendRequest   [line 71]

HTTP_Request2_Response sendRequest( HTTP_Request2 $request)

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

Only responses without explicit URLs or with URLs equal to request URL will be considered. If matching response is not found or the queue is empty then default empty response with status 400 will be returned, 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   —  HTTP request message

[ Top ]


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