## API Documentation

# Http/Client/Adapter/Test.php

Zend Framework

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.

category
  Zend
copyright
  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
license
  New BSD License
package
  Zend_Http
subpackage
  Client_Adapter
version
  $Id: Test.php 24309 2011-07-30 02:52:32Z ramon $

## \Zend_Http_Client_Adapter_Test
jump to top

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.

Implements
  \Zend_Http_Client_Adapter_Interface
category
  Zend
copyright
  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
license
  New BSD License
package
  Zend_Http
subpackage
  Client_Adapter

### Properties

`boolean $_nextRequestWillFail= 'false'`

Wether or not the next request will fail with an exception

Default value `false` Details

Type
  boolean

`array $config= 'array'`

Parameters array

Default value `array` Details

Type
  array

`integer $responseIndex= '0'`

Current position in the response buffer

Default value `0` Details

Type
  integer

`array $responses= 'array'`

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

Default value `array` Details

Type
  array

### Methods

`__construct( ) : void`

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

`addResponse( string $response ) : void`

Add another response to the response buffer.

Parameters

Name | Type | Description
--- | --- | ---
$response | string | Zend_Http_Response|$response

`close( ) : void`

Close the connection (dummy)

`connect( string $host, int $port = 80, boolean $secure = false ) : void`

Connect to the remote server

Parameters

Name | Type | Description
--- | --- | ---
$host | string |
$port | int |
$secure | boolean |

Throws

Exception | Description
--- | ---
\Zend_Http_Client_Adapter_Exception |

`getConfig( ) : array`

Retrieve the array of all configuration options

Returns

Type | Description
--- | ---
array |

`read( ) : string`

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

Returns

Type | Description
--- | ---
string |

`setConfig( \Zend_Config $config = array ) : void`

Set the configuration array for the adapter

Parameters

Name | Type | Description
--- | --- | ---
$config | \Zend_Config | | array $config

`setNextRequestWillFail( boolean $flag ) : \Zend_Http_Client_Adapter_Test`

Set the nextRequestWillFail flag

Parameters

Name | Type | Description
--- | --- | ---
$flag | boolean |

Returns

Type | Description
--- | ---
\Zend_Http_Client_Adapter_Test |

`setResponse( \Zend_Http_Response|array|string $response ) : void`

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

Parameters

Name | Type | Description
--- | --- | ---
$response | \Zend_Http_Response|array|string |

`setResponseIndex( integer $index ) : void`

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

Parameters

Name | Type | Description
--- | --- | ---
$index | integer |

`write( string $method, \Zend_Uri_Http $uri, string $http_ver = 1.1, array $headers = array, string $body ) : string`

Send request to the remote server

Parameters

Name | Type | Description
--- | --- | ---
$method | string |
$uri | \Zend_Uri_Http |
$http_ver | string |
$headers | array |
$body | string |

Returns

Type | Description
--- | ---
string | Request as string

Documentation was generated by DocBlox 0.13.3.