当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::fromMessage方法代码示例

本文整理汇总了PHP中Guzzle\Http\Message\Response::fromMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::fromMessage方法的具体用法?PHP Response::fromMessage怎么用?PHP Response::fromMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Http\Message\Response的用法示例。


在下文中一共展示了Response::fromMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testValidatesSuccessfulMd5OfBody

 /**
  * @expectedException \Aws\Sqs\Exception\SqsException
  * @expectedExceptionMessage Body MD5 mismatch for
  */
 public function testValidatesSuccessfulMd5OfBody()
 {
     $mock = new MockPlugin(array(Response::fromMessage("HTTP/1.1 200 OK\r\nContent-Type: application/xml\r\n\r\n" . "<ReceiveMessageResponse>\n                  <ReceiveMessageResult>\n                    <Message>\n                      <MD5OfBody>fooo</MD5OfBody>\n                      <Body>This is a test message</Body>\n                    </Message>\n                  </ReceiveMessageResult>\n                </ReceiveMessageResponse>")));
     $sqs = SqsClient::factory(array('key' => 'abc', 'secret' => '123', 'region' => 'us-east-1'));
     $sqs->addSubscriber($mock);
     $sqs->receiveMessage(array('QueueUrl' => 'http://foo.com'));
 }
开发者ID:njbhatt18,项目名称:Amazon_API,代码行数:11,代码来源:SqsClientTest.php

示例2: getMockFile

 /**
  * Get a mock response from a file
  *
  * @param string $path File to retrieve a mock response from
  *
  * @return Response
  * @throws InvalidArgumentException if the file is not found
  */
 public static function getMockFile($path)
 {
     if (!file_exists($path)) {
         throw new InvalidArgumentException('Unable to open mock file: ' . $path);
     }
     return Response::fromMessage(file_get_contents($path));
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:15,代码来源:MockPlugin.php

示例3: testParsesServerErrorResponsesWithMixedCasing

 public function testParsesServerErrorResponsesWithMixedCasing()
 {
     $request = new Request('GET', 'http://example.com');
     $response = Response::fromMessage("HTTP/1.1 500 Internal Server Error\r\n" . "x-amzn-requestid: 123\r\n\r\n" . '{ "__Type": "abc#bazFault", "Message": "dolor" }');
     $parser = new JsonQueryExceptionParser();
     $this->assertEquals(array('code' => 'baz', 'message' => 'dolor', 'type' => 'server', 'request_id' => '123', 'parsed' => array('__type' => 'abc#bazFault', 'message' => 'dolor')), $parser->parse($request, $response));
 }
开发者ID:njbhatt18,项目名称:Amazon_API,代码行数:7,代码来源:JsonQueryExceptionParserTest.php

示例4: testAddsResponseObjectsToQueue

 public function testAddsResponseObjectsToQueue()
 {
     $p = new MockPlugin();
     $response = Response::fromMessage("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
     $p->addResponse($response);
     $this->assertEquals(array($response), $p->getQueue());
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:7,代码来源:MockPluginTest.php

示例5: testRevalidatesResponsesAgainstOriginServer

 /**
  * @dataProvider cacheRevalidationDataProvider
  */
 public function testRevalidatesResponsesAgainstOriginServer($can, $request, $response, $validate = null, $result = null)
 {
     // Send some responses to the test server for cache validation
     $server = $this->getServer();
     $server->flush();
     if ($validate) {
         $server->enqueue($validate);
     }
     $request = RequestFactory::getInstance()->fromMessage("GET / HTTP/1.1\r\nHost: 127.0.0.1:" . $server->getPort() . "\r\n" . $request);
     $response = Response::fromMessage($response);
     $request->setClient(new Client());
     $plugin = new CachePlugin(new DoctrineCacheAdapter(new ArrayCache()));
     $this->assertEquals($can, $plugin->canResponseSatisfyRequest($request, $response), '-> ' . $request . "\n" . $response);
     if ($result) {
         $result = Response::fromMessage($result);
         $result->removeHeader('Date');
         $request->getResponse()->removeHeader('Date');
         $request->getResponse()->removeHeader('Connection');
         // Get rid of dates
         $this->assertEquals((string) $result, (string) $request->getResponse());
     }
     if ($validate) {
         $this->assertEquals(1, count($server->getReceivedRequests()));
     }
 }
开发者ID:alvarobfdev,项目名称:applog,代码行数:28,代码来源:DefaultRevalidationTest.php

示例6: testParsesResponseWith301

 public function testParsesResponseWith301()
 {
     $response = Response::fromMessage("HTTP/1.1 301 Moved Permanently\r\n\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?><Error><Code>PermanentRedirect</Code><Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message><RequestId>DUMMY_REQUEST_ID</RequestId><Bucket>DUMMY_BUCKET_NAME</Bucket><HostId>DUMMY_HOST_ID</HostId><Endpoint>s3.amazonaws.com</Endpoint></Error>");
     $parser = new S3ExceptionParser();
     $result = $parser->parse($response);
     $this->assertEquals('PermanentRedirect', $result['code']);
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:7,代码来源:S3ExceptionParserTest.php

示例7: testParsesClientErrorResponseWithCodeInHeader

 public function testParsesClientErrorResponseWithCodeInHeader()
 {
     $request = new Request('GET', 'http://example.com');
     $response = Response::fromMessage("HTTP/1.1 400 Bad Request\r\n" . "x-amzn-RequestId: xyz\r\n" . "x-amzn-ErrorType: foo:bar\r\n\r\n" . '{ "message": "lorem ipsum"}');
     $parser = new JsonRestExceptionParser();
     $this->assertEquals(array('code' => 'foo', 'message' => 'lorem ipsum', 'type' => 'client', 'request_id' => 'xyz', 'parsed' => array('message' => 'lorem ipsum')), $parser->parse($request, $response));
 }
开发者ID:njbhatt18,项目名称:Amazon_API,代码行数:7,代码来源:JsonRestExceptionParserTest.php

示例8: testParsesResponsesWithNoBody

 public function testParsesResponsesWithNoBody()
 {
     $response = Response::fromMessage("HTTP/1.1 400 Bad Request\r\nX-Amz-Request-ID: Foo\r\n\r\n");
     $parser = new DefaultXmlExceptionParser();
     $result = $parser->parse($response);
     $this->assertEquals('400 Bad Request (Request-ID: Foo)', $result['message']);
     $this->assertEquals('Foo', $result['request_id']);
 }
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:8,代码来源:DefaultXmlExceptionParserTest.php

示例9: getHttpFixture

 /**
  * 
  * @param string $fixtureName
  * @return \Guzzle\Http\Message\Response
  */
 protected function getHttpFixture($fixtureName = '', $contentType = 'application/xml')
 {
     $message = "HTTP/1.0 200 OK\nContent-Type:" . $contentType . "\n\n";
     if ($fixtureName != '') {
         $message .= $this->getFixture($fixtureName);
     }
     return \Guzzle\Http\Message\Response::fromMessage($message);
 }
开发者ID:webignition,项目名称:sitemap-model,代码行数:13,代码来源:BaseTest.php

示例10: testParsesResponsesWithNoBody

 /**
  * @dataProvider getDataForParsingTest
  */
 public function testParsesResponsesWithNoBody($url, $message, $code)
 {
     $request = new Request('HEAD', $url);
     $response = Response::fromMessage("HTTP/1.1 {$message}\r\n\r\n");
     $response->setRequest($request);
     $parser = new S3ExceptionParser();
     $result = $parser->parse($response);
     $this->assertEquals($code, $result['code']);
 }
开发者ID:cstuder,项目名称:nagios-plugins,代码行数:12,代码来源:S3ExceptionParserTest.php

示例11: getMockFile

 /**
  * Get a mock response from a file
  *
  * @param string $file File to retrieve a mock response from
  *
  * @return Response
  * @throws InvalidArgumentException if the file is not found
  */
 public static function getMockFile($path)
 {
     if (!file_exists($path)) {
         throw new InvalidArgumentException('Unable to open mock file: ' . $path);
     }
     $parts = explode("\n\n", file_get_contents($path), 2);
     // Convert \n to \r\n in headers
     $data = isset($parts[1]) ? str_replace("\n", "\r\n", $parts[0]) . "\r\n\r\n" . $parts[1] : $parts[0];
     return Response::fromMessage($data);
 }
开发者ID:norv,项目名称:guzzle,代码行数:18,代码来源:MockPlugin.php

示例12: registerUri

 /**
  * Register a URI.
  *
  * @param string          $uri      URI (either complete or partial)
  * @param Response|string $response Response object, a string response or a path to a file containing a response
  *
  * @return self Reference to the matcher
  */
 public function registerUri($uri, $response)
 {
     if ($response instanceof Response) {
         $this->responses[$uri] = $response;
         return $this;
     }
     if (file_exists($response)) {
         $response = file_get_contents($response);
     }
     $this->responses[$uri] = Response::fromMessage($response);
     return $this;
 }
开发者ID:thewilkybarkid,项目名称:guzzle-mock-matcher,代码行数:20,代码来源:UriRequestMatcher.php

示例13: testExcludeSourceUrlFromHistoryComparison

 public function testExcludeSourceUrlFromHistoryComparison()
 {
     $httpClient = new \Guzzle\Http\Client();
     $mockPlugin = new \Guzzle\Plugin\Mock\MockPlugin();
     $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301' . "\n" . 'Location: http://example.com/'));
     $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301' . "\n" . 'Location: http://example.com/2/'));
     $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301' . "\n" . 'Location: http://example.com/3/'));
     $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301' . "\n" . 'Location: http://example.com/4/'));
     $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301' . "\n" . 'Location: http://example.com/5/'));
     $httpClient->addSubscriber($mockPlugin);
     $detector = new \webignition\HttpRedirectLoopDetector\HttpRedirectLoopDetector();
     $detector->setHttpClient($httpClient);
     $detector->setUrl('https://example.com/');
     $this->assertFalse($detector->test());
 }
开发者ID:webignition,项目名称:http-redirect-loop-detector,代码行数:15,代码来源:HttpRedirectLoopDetectorTest.php

示例14: enqueue

 /**
  * Queue an array of responses or a single response on the server.
  *
  * Any currently queued responses will be overwritten.  Subsequent requests
  * on the server will return queued responses in FIFO order.
  *
  * @param array|Response $responses A single or array of Responses to queue
  * @throws BadResponseException
  */
 public function enqueue($responses)
 {
     $data = array();
     foreach ((array) $responses as $response) {
         // Create the response object from a string
         if (is_string($response)) {
             $response = Response::fromMessage($response);
         } elseif (!$response instanceof Response) {
             throw new BadResponseException('Responses must be strings or implement Response');
         }
         $data[] = array('statusCode' => $response->getStatusCode(), 'reasonPhrase' => $response->getReasonPhrase(), 'headers' => $response->getHeaders()->toArray(), 'body' => $response->getBody(true));
     }
     $request = $this->client->put('guzzle-server/responses', null, json_encode($data));
     $request->send();
 }
开发者ID:carlesgutierrez,项目名称:libreobjet.org,代码行数:24,代码来源:Server.php

示例15: onBeforeSendFallback

 public function onBeforeSendFallback(Event $event)
 {
     if (strpos($event['request']->getUrl(), 'tokens') !== false) {
         // auth request must pass
         $message = file_get_contents(__DIR__ . '/_response/Auth.resp');
         $response = Response::fromMessage($message);
         $event['request']->setResponse($response)->setState(Request::STATE_COMPLETE);
         $event->stopPropagation();
     } else {
         // default fallback is a 404
         $response = new Response(200);
         $event['request']->setResponse($response)->setState(Request::STATE_COMPLETE);
         $event->stopPropagation();
     }
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:15,代码来源:MockSubscriber.php


注:本文中的Guzzle\Http\Message\Response::fromMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。