A testing-purposes adapter.

Should be used to test all components that rely on Zend\Http\Client, without actually performing an HTTP request. You should instantiate this object manually, and then set it as the client's adapter. Then, you can set the expected response using the setResponse() method.

package Default

 Methods

Adapter constructor, currently empty. Config is set using setOptions()

__construct() 

Add another response to the response buffer.

addResponse(string|\Zend\Http\Response $response) 

Parameters

$response

string\Zend\Http\Response

Close the connection (dummy)

close() 
inherited_from \Zend\Http\Client\Adapter\AdapterInterface::close()

Connect to the remote server

connect(string $host, integer $port = 80, boolean $secure = false
inherited_from \Zend\Http\Client\Adapter\AdapterInterface::connect()

Parameters

$host

string

$port

integer

$secure

boolean

Exceptions

\Zend\Http\Client\Adapter\Exception\RuntimeException

Return the response set in $this->setResponse()

read() : string
inherited_from \Zend\Http\Client\Adapter\AdapterInterface::read()

Returns

string

Set the nextRequestWillFail flag

setNextRequestWillFail(boolean $flag) : \Zend\Http\Client\Adapter\Test

Parameters

$flag

boolean

Returns

\Zend\Http\Client\Adapter\Test

Set the configuration array for the adapter

setOptions(array|\Traversable $options = array()
inherited_from \Zend\Http\Client\Adapter\AdapterInterface::setOptions()

Parameters

$options

array\Traversable

Exceptions

\Zend\Http\Client\Adapter\Exception\InvalidArgumentException

Set the HTTP response(s) to be returned by this adapter

setResponse(\Zend\Http\Response|array|string $response) 

Parameters

$response

\Zend\Http\Responsearraystring

Sets the position of the response buffer. Selects which response will be returned on the next call to read().

setResponseIndex(integer $index) 

Parameters

$index

integer

Exceptions

\Zend\Http\Client\Adapter\Exception\OutOfRangeException

Send request to the remote server

write(string $method, \Zend\Uri\Uri $uri, string $httpVer = '1.1', array $headers = array(), string $body = '') : string
inherited_from \Zend\Http\Client\Adapter\AdapterInterface::write()

Parameters

$method

string

$uri

\Zend\Uri\Uri

$httpVer

string

$headers

array

$body

string

Returns

stringRequest as string

 Properties

 

Parameters array

$config : array

Default

array()
 

Whether or not the next request will fail with an exception

$nextRequestWillFail : boolean

Default

false
 

Current position in the response buffer

$responseIndex : integer

Default

0
 

Buffer of responses to be returned by the read() method. Can be set using setResponse() and addResponse().

$responses : array

Default

array("HTTP/1.1 400 Bad Request\r\n\r\n")