Horde_Http_Request_Mock::addResponse PHP Метод

addResponse() публичный Метод

Adds a response to the stack of responses.
public addResponse ( string | resourse $body, string $code = 200, string $uri = '', array $headers = [] ) : Horde_Http_Response_Mock
$body string | resourse The response body content.
$code string The response code.
$uri string The request uri.
$headers array Response headers. This can be one string representing the whole header or an array of strings with one string per header line.
Результат Horde_Http_Response_Mock The response.
    public function addResponse($body, $code = 200, $uri = '', $headers = array())
    {
        if (is_string($body)) {
            $stream = new Horde_Support_StringStream($body);
            $response = new Horde_Http_Response_Mock($uri, $stream->fopen(), $headers);
        } else {
            $response = new Horde_Http_Response_Mock($uri, $body, $headers);
        }
        $response->code = $code;
        $this->_responses[] = $response;
    }

Usage Example

Пример #1
0
 public function testAddResponseHeader()
 {
     $mock = new Horde_Http_Request_Mock();
     $mock->addResponse('Test', 404, 'http://example.org', array('test: TEST'));
     $client = new Horde_Http_Client(array('request' => $mock));
     $this->assertEquals('TEST', $client->get()->getHeader('test'));
 }
All Usage Examples Of Horde_Http_Request_Mock::addResponse