本文整理汇总了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'));
}
示例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));
}
示例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));
}
示例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());
}
示例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()));
}
}
示例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']);
}
示例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));
}
示例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']);
}
示例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);
}
示例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']);
}
示例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);
}
示例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;
}
示例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());
}
示例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();
}
示例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();
}
}