예제 #1
0
 private function _getClient()
 {
     $response = 'REMOTE';
     $body = new Horde_Support_StringStream($response);
     $response = new Horde_Http_Response_Mock('', $body->fopen());
     $response->code = 200;
     $request = new Horde_Http_Request_Mock();
     $request->setResponse($response);
     return new Horde_Http_Client(array('request' => $request));
 }
예제 #2
0
 public function testPreparedResponse()
 {
     $body = 'Test';
     $stream = new Horde_Support_StringStream($body);
     $response = new Horde_Http_Response_Mock('', $stream->fopen());
     $mock = new Horde_Http_Request_Mock();
     $mock->setResponse($response);
     $client = new Horde_Http_Client(array('request' => $mock));
     $this->assertEquals('Test', $client->get()->getBody());
 }
예제 #3
0
 public function testStreamOutput()
 {
     $output = 'BODY';
     $body = new Horde_Support_StringStream($output);
     $response = new Horde_Controller_Response();
     $response->setBody($body->fopen());
     $writer = new Horde_Controller_ResponseWriter_Web();
     ob_start();
     $writer->writeResponse($response);
     $this->assertEquals('BODY', ob_get_clean());
 }
예제 #4
0
 /**
  * Set the HTTP response(s) to be returned by this adapter as an array of strings.
  *
  * @param array $responses
  */
 public function setResponses($responses)
 {
     foreach ($responses as $response) {
         $body = new Horde_Support_StringStream($response['body']);
         $r = new Horde_Http_Response_Mock(isset($response['uri']) ? $response['uri'] : '', $body->fopen(), isset($response['headers']) ? $response['headers'] : array());
         if (isset($response['code'])) {
             $r->code = $response['code'];
         }
         $this->_responses[] = $r;
     }
 }
예제 #5
0
 private function _getRemoteDependencies()
 {
     if (!class_exists('Horde_Http_Client')) {
         $this->markTestSkipped('Horde_Http is missing!');
     }
     $string = serialize(array('required' => array('package' => array('name' => 'test'))));
     $body = new Horde_Support_StringStream($string);
     $response = new Horde_Http_Response_Mock('', $body->fopen());
     $response->code = 200;
     $request = new Horde_Http_Request_Mock();
     $request->setResponse($response);
     return $this->createRemote($request);
 }
예제 #6
0
    protected function getRemoteList($list = null)
    {
        if (!class_exists('Horde_Http_Client')) {
            $this->markTestSkipped('Horde_Http is missing!');
        }
        if ($list === null) {
            $list = '<?xml version="1.0" encoding="UTF-8" ?>
<l><p xlink:href="/rest/p/a">A</p><p xlink:href="/rest/p/b">B</p></l>';
        }
        $body = new Horde_Support_StringStream($list);
        $response = new Horde_Http_Response_Mock('', $body->fopen());
        $response->code = 200;
        $request = new Horde_Http_Request_Mock();
        $request->setResponse($response);
        return $this->createRemote($request);
    }
예제 #7
0
 public function testMemoryUsage()
 {
     $bytes = 1024 * 1024;
     $string = str_repeat('*', $bytes);
     $memoryUsage = memory_get_usage();
     $stream = new Horde_Support_StringStream($string);
     $memoryUsage2 = memory_get_usage();
     $this->assertLessThan($memoryUsage + $bytes, $memoryUsage2);
     $fp = $stream->fopen();
     $memoryUsage3 = memory_get_usage();
     $this->assertLessThan($memoryUsage + $bytes, $memoryUsage3);
     while (!feof($fp)) {
         fread($fp, 1024);
     }
     $memoryUsage4 = memory_get_usage();
     $this->assertLessThan($memoryUsage + $bytes, $memoryUsage4);
 }
예제 #8
0
 private function _getRest($code = 200)
 {
     if (!class_exists('Horde_Http_Client')) {
         $this->markTestSkipped('Horde_Http is missing!');
     }
     $string = 'RESPONSE';
     $body = new Horde_Support_StringStream($string);
     $response = new Horde_Http_Response_Mock('', $body->fopen());
     $response->code = $code;
     $request = new Horde_Http_Request_Mock();
     $request->setResponse($response);
     return new Horde_Pear_Rest(new Horde_Http_Client(array('request' => $request)), '');
 }
예제 #9
0
파일: Contents.php 프로젝트: horde/horde
 /**
  * Returns base header information.
  *
  * @param integer $type  See getHeader().
  * @param boolean $seen  Mark message as seen?
  *
  * @return mixed  See getHeader().
  */
 protected function _getHeader($type, $seen)
 {
     if (!isset($this->_header)) {
         if (!$this->_indices) {
             $this->_header = $this->_message->addMimeHeaders();
         } else {
             $query = new Horde_Imap_Client_Fetch_Query();
             $query->headerText(array('peek' => !$seen));
             $this->_header = ($res = $this->_fetchData($query)) ? $res : new Horde_Imap_Client_Data_Fetch();
         }
     }
     switch ($type) {
         case self::HEADER_OB:
             return $this->_indices ? $this->_header->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE) : $this->_header;
         case self::HEADER_TEXT:
             return $this->_indices ? $this->_header->getHeaderText() : $this->_header->toString();
         case self::HEADER_STREAM:
             if ($this->_indices) {
                 return $this->_header->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
             }
             $stream = new Horde_Support_StringStream($this->_header->toString());
             $stream->fopen();
             return $stream;
     }
 }
예제 #10
0
 /**
  * Parses a file from the timezone database.
  *
  * @param string $file  A file location.
  */
 protected function _parse($file)
 {
     $stream = new Horde_Support_StringStream($file);
     $fp = $stream->fopen();
     $zone = null;
     while (($line = fgets($fp)) !== false) {
         $line = trim($line);
         if (!strlen($line) || $line[0] == '#') {
             continue;
         }
         $column = preg_split('/\\s+/', preg_replace('/\\s*#.*$/', '', $line));
         switch ($column[0]) {
             case 'Rule':
                 if (!isset($this->_rules[$column[1]])) {
                     $this->_rules[$column[1]] = new Horde_Timezone_Rule($column[1]);
                 }
                 $this->_rules[$column[1]]->add($column);
                 $zone = null;
                 break;
             case 'Link':
                 $this->_links[$column[2]] = $column[1];
                 $zone = null;
                 break;
             case 'Zone':
                 $zone = $column[1];
                 $this->_zones[$zone] = new Horde_Timezone_Zone($zone, $this);
                 array_splice($column, 0, 2);
                 // Fall through.
             // Fall through.
             default:
                 if (empty($zone) || !isset($this->_zones[$zone])) {
                     break;
                 }
                 $this->_zones[$zone]->add($column);
                 break;
         }
     }
 }
예제 #11
0
 private function _getDependencyAccess()
 {
     if (!class_exists('Horde_Http_Client')) {
         $this->markTestSkipped('Horde_Http is missing!');
     }
     $string = 'b:1;';
     $body = new Horde_Support_StringStream($string);
     $response = new Horde_Http_Response_Mock('', $body->fopen());
     $response->code = 200;
     $request = new Horde_Http_Request_Mock();
     $request->setResponse($response);
     return $this->_createAccess($request);
 }
예제 #12
0
파일: Base.php 프로젝트: horde/horde
 /**
  * Returns a stream pointing to the response body that can be used with all
  * standard PHP stream functions.
  */
 public function getStream()
 {
     $string_body = $this->getBody();
     $body = new Horde_Support_StringStream($string_body);
     return $body->fopen();
 }
예제 #13
0
 protected function getHttpClient($body, $code = 200)
 {
     if (!is_resource($body)) {
         $stream = new Horde_Support_StringStream($body);
         $response = new Horde_Http_Response_Mock('', $stream->fopen());
     } else {
         $response = new Horde_Http_Response_Mock('', $body);
     }
     $response->code = $code;
     $request = new Horde_Http_Request_Mock();
     $request->setResponse($response);
     return new Horde_Http_Client(array('request' => $request));
 }
예제 #14
0
 private function _getStubbedGravatar($response_string)
 {
     $body = new Horde_Support_StringStream($response_string);
     $response = new Horde_Http_Response_Mock('', $body->fopen());
     $request = new Horde_Http_Request_Mock();
     $request->setResponse($response);
     return new Horde_Service_Gravatar(Horde_Service_Gravatar::STANDARD, new Horde_Http_Client(array('request' => $request)));
 }
예제 #15
0
파일: Mock.php 프로젝트: horde/horde
 /**
  * Adds a response to the stack of responses.
  *
  * @param string|resourse $body    The response body content.
  * @param string          $code    The response code.
  * @param string          $uri     The request uri.
  * @param array           $headers Response headers. This can be one string
  *                                 representing the whole header or an array
  *                                 of strings with one string per header
  *                                 line.
  *
  * @return 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;
 }