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


PHP ClientInterface::expects方法代码示例

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


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

示例1: testFetch

 public function testFetch()
 {
     $url = 'http://google.com';
     $redirect = 'https://www.google.com';
     $ua = 'IO Crawler/1.0';
     $body = 'test';
     $headers = ['content-length' => [1234], 'content-type' => ['text/plain']];
     $response = new GuzzleResponse(200, $headers, $body);
     $this->guzzle->expects($this->once())->method('request')->with('GET', $url, $this->callback(function (array $options) use($ua) {
         $this->assertArraySubset(['headers' => ['User-Agent' => $ua]], $options);
         return true;
     }))->will($this->returnCallback(function () use($url, $redirect, $response) {
         $this->client->setEffectiveUri($url, $redirect);
         return $response;
     }));
     $result = $this->client->fetch($url, $ua);
     $this->assertInternalType('array', $result);
     $this->assertCount(2, $result);
     /** @var ResponseInterface $response */
     list($effectiveUrl, $response) = $result;
     $this->assertEquals($redirect, $effectiveUrl);
     $this->assertInstanceOf(ResponseInterface::class, $response);
     $this->assertArraySubset($headers, $response->getHeaders());
     $this->assertEquals($body, $response->getBody()->getContents());
 }
开发者ID:treehouselabs,项目名称:io-bundle,代码行数:25,代码来源:GuzzleClientTest.php

示例2: testDeleteIndexRequestContent

 public function testDeleteIndexRequestContent()
 {
     $request = new DeleteIndexRequest();
     $httpRequest = $this->getMock('GuzzleHttp\\Message\\RequestInterface');
     $httpResponse = $this->getMock('GuzzleHttp\\Message\\ResponseInterface');
     $this->client->expects($this->once())->method('createRequest')->with($this->equalTo('DELETE'), $this->equalTo('/search/index/index-name'))->willReturn($httpRequest);
     $this->client->expects($this->once())->method('send')->with($this->equalTo($httpRequest))->willReturn($httpResponse);
     $request->name = 'index-name';
     $this->assertInstanceOf('Riak\\Client\\Core\\Message\\Search\\DeleteIndexResponse', $this->instance->send($request));
 }
开发者ID:php-riak,项目名称:riak-client,代码行数:10,代码来源:HttpDeleteIndexTest.php

示例3: testUnexpectedHttpStatusCode

 /**
  * @expectedException Riak\Client\Core\Transport\RiakTransportException
  * @expectedExceptionMessage Unexpected status code : "555"
  */
 public function testUnexpectedHttpStatusCode()
 {
     $request = new MapReduceRequest();
     $httpQuery = $this->getMock('GuzzleHttp\\Query');
     $httpRequest = $this->getMock('GuzzleHttp\\Message\\RequestInterface');
     $httpResponse = $this->getMock('GuzzleHttp\\Message\\ResponseInterface');
     $this->client->expects($this->once())->method('createRequest')->willReturn($httpRequest);
     $this->client->expects($this->once())->method('send')->willReturn($httpResponse);
     $httpRequest->expects($this->once())->method('getQuery')->willReturn($httpQuery);
     $httpQuery->expects($this->once())->method('add')->willReturn($httpRequest);
     $httpResponse->expects($this->any())->method('getStatusCode')->willReturn(555);
     $request->request = '';
     $this->instance->send($request);
 }
开发者ID:php-riak,项目名称:riak-client,代码行数:18,代码来源:HttpMapReduceTest.php

示例4: testGetSchemaRequestContent

 public function testGetSchemaRequestContent()
 {
     $request = new GetSchemaRequest();
     $body = Stream::factory('schema-content');
     $httpRequest = $this->getMock('GuzzleHttp\\Message\\RequestInterface');
     $httpResponse = $this->getMock('GuzzleHttp\\Message\\ResponseInterface');
     $this->client->expects($this->once())->method('createRequest')->with($this->equalTo('GET'), $this->equalTo('/search/schema/schema-name'))->willReturn($httpRequest);
     $this->client->expects($this->once())->method('send')->with($this->equalTo($httpRequest))->willReturn($httpResponse);
     $httpResponse->expects($this->once())->method('getBody')->willReturn($body);
     $request->name = 'schema-name';
     $response = $this->instance->send($request);
     $this->assertInstanceOf('Riak\\Client\\Core\\Message\\Search\\GetSchemaResponse', $response);
     $this->assertEquals((string) $body, $response->content);
     $this->assertEquals('schema-name', $response->name);
 }
开发者ID:php-riak,项目名称:riak-client,代码行数:15,代码来源:HttpGetSchemaTest.php

示例5: testGetIndexRequestContent

 public function testGetIndexRequestContent()
 {
     $request = new GetIndexRequest();
     $httpRequest = $this->getMock('GuzzleHttp\\Message\\RequestInterface');
     $httpResponse = $this->getMock('GuzzleHttp\\Message\\ResponseInterface');
     $this->client->expects($this->once())->method('createRequest')->with($this->equalTo('GET'), $this->equalTo('/search/index/index-name'))->willReturn($httpRequest);
     $this->client->expects($this->once())->method('send')->with($this->equalTo($httpRequest))->willReturn($httpResponse);
     $httpResponse->expects($this->once())->method('json')->willReturn(['n_val' => 3, 'name' => 'index-name', 'schema' => 'schema-name']);
     $request->name = 'index-name';
     $response = $this->instance->send($request);
     $this->assertInstanceOf('Riak\\Client\\Core\\Message\\Search\\GetIndexResponse', $response);
     $this->assertEquals('schema-name', $response->schema);
     $this->assertEquals('index-name', $response->name);
     $this->assertEquals(3, $response->nVal);
 }
开发者ID:php-riak,项目名称:riak-client,代码行数:15,代码来源:HttpGetIndexTest.php

示例6: testWrappedExceptioThrownByGuzzle

 /**
  * @expectedException Riak\Client\Core\Transport\RiakTransportException
  * @expectedExceptionMessage Not Found
  * @expectedExceptionCode 404
  */
 public function testWrappedExceptioThrownByGuzzle()
 {
     $request = new GetRequest();
     $httpRequest = $this->getMock('GuzzleHttp\\Message\\RequestInterface');
     $httpResponse = $this->getMock('GuzzleHttp\\Message\\ResponseInterface');
     $httpQuery = $this->getMock('GuzzleHttp\\Query');
     $request->notfoundOk = false;
     $this->client->expects($this->once())->method('createRequest')->with($this->equalTo('GET'), $this->equalTo('/types/default/buckets/test_bucket/keys/1'))->willReturn($httpRequest);
     $httpResponse->expects($this->once())->method('getStatusCode')->willReturn(404);
     $httpRequest->expects($this->once())->method('getQuery')->willReturn($httpQuery);
     $this->client->expects($this->once())->method('send')->with($this->equalTo($httpRequest))->willThrowException(new ClientException('Not Found', $httpRequest, $httpResponse));
     $request->bucket = 'test_bucket';
     $request->type = 'default';
     $request->key = '1';
     $this->instance->send($request);
 }
开发者ID:php-riak,项目名称:riak-client,代码行数:21,代码来源:RiakHttpAdpterTest.php

示例7: setGuzzleExpectations

 /**
  * Sets Guzzle expectations.
  *
  * @param string $action
  * @param mixed $contentId
  * @param int $contentTypeId
  * @param int $customerId
  * @param string $serverUri
  * @param string $licenseKey
  * @param string $apiEndpoint
  */
 protected function setGuzzleExpectations($action, $contentId, $contentTypeId, $customerId, $serverUri, $licenseKey, $apiEndpoint)
 {
     if (method_exists($this->guzzleClientMock, 'post')) {
         $this->guzzleClientMock->expects($this->once())->method('post')->with($this->equalTo($this->getExpectedEndpoint($apiEndpoint, $customerId)), $this->equalTo($this->getNotificationBody($action, $contentId, $contentTypeId, $serverUri, $customerId, $licenseKey)))->will($this->returnValue(new Response(202)));
     } else {
         $this->guzzleClientMock->expects($this->once())->method('requestAsync')->with('POST', $this->equalTo($this->getExpectedEndpoint($apiEndpoint, $customerId)), $this->equalTo($this->getNotificationBody($action, $contentId, $contentTypeId, $serverUri, $customerId, $licenseKey)))->will($this->returnValue(new Promise()));
     }
 }
开发者ID:kamilmusial,项目名称:EzSystemsRecommendationBundle,代码行数:19,代码来源:YooChooseNotifierTest.php

示例8: testUnexpectedHttpStatusCode

 /**
  * @expectedException Riak\Client\Core\Transport\RiakTransportException
  * @expectedExceptionMessage Unexpected status code : "555"
  */
 public function testUnexpectedHttpStatusCode()
 {
     $request = new PutRequest();
     $httpQuery = $this->getMock('GuzzleHttp\\Query');
     $httpRequest = $this->getMock('GuzzleHttp\\Message\\RequestInterface');
     $httpResponse = $this->getMock('GuzzleHttp\\Message\\ResponseInterface');
     $this->client->expects($this->once())->method('createRequest')->willReturn($httpRequest);
     $this->client->expects($this->once())->method('send')->willReturn($httpResponse);
     $httpRequest->expects($this->once())->method('getQuery')->willReturn($httpQuery);
     $httpQuery->expects($this->any())->method('add')->willReturn($httpRequest);
     $httpResponse->expects($this->any())->method('getStatusCode')->willReturn(555);
     $request->op = new CounterOp(10);
     $request->bucket = 'test_bucket';
     $request->type = 'default';
     $request->key = '1';
     $this->instance->send($request);
 }
开发者ID:php-riak,项目名称:riak-client,代码行数:21,代码来源:HttpPutTest.php

示例9: testImport

 /**
  * @covers \Smartling\File\FileApi::import
  */
 public function testImport()
 {
     $locale = 'en-EN';
     $endpointUrl = vsprintf('%s/%s/locales/%s/file/import', [FileApi::ENDPOINT_URL, $this->projectId, $locale]);
     $this->client->expects(self::once())->method('request')->with('POST', $endpointUrl, ['headers' => ['Accept' => 'application/json', 'Authorization' => vsprintf(' %s %s', [$this->authProvider->getTokenType(), $this->authProvider->getAccessToken()])], 'http_errors' => false, 'multipart' => [['name' => 'file', 'contents' => $this->streamPlaceholder], ['name' => 'fileUri', 'contents' => 'test.xml'], ['name' => 'fileType', 'contents' => 'xml'], ['name' => 'translationState', 'contents' => 'PUBLISHED'], ['name' => 'overwrite', 'contents' => '0']]])->willReturn($this->responseMock);
     $this->invokeMethod($this->object, 'setAuth', [$this->authProvider]);
     $this->object->import($locale, 'test.xml', 'xml', 'tests/resources/test.xml', 'PUBLISHED', false);
 }
开发者ID:smartling,项目名称:api-sdk-php,代码行数:11,代码来源:FileApiTest.php

示例10: testPutSchemaRequestContent

 public function testPutSchemaRequestContent()
 {
     $request = new PutSchemaRequest();
     $body = Stream::factory('schema-content');
     $httpRequest = $this->getMock('GuzzleHttp\\Message\\RequestInterface');
     $httpResponse = $this->getMock('GuzzleHttp\\Message\\ResponseInterface');
     $callback = function ($subject) {
         $this->assertInstanceOf('GuzzleHttp\\Stream\\Stream', $subject);
         $this->assertEquals('schema-content', (string) $subject);
         return true;
     };
     $this->client->expects($this->once())->method('createRequest')->with($this->equalTo('PUT'), $this->equalTo('/search/schema/schema-name'))->willReturn($httpRequest);
     $this->client->expects($this->once())->method('send')->with($this->equalTo($httpRequest))->willReturn($httpResponse);
     $httpRequest->expects($this->once())->method('setBody')->with($this->callback($callback))->willReturn($body);
     $request->name = 'schema-name';
     $request->content = 'schema-content';
     $this->assertInstanceOf('Riak\\Client\\Core\\Message\\Search\\PutSchemaResponse', $this->instance->send($request));
 }
开发者ID:php-riak,项目名称:riak-client,代码行数:18,代码来源:HttpPutSchemaTest.php

示例11: setUpExceptionTest

 /**
  * Setup pieces for testing exception passing
  *
  * @param string $message
  */
 protected function setUpExceptionTest($message)
 {
     $secondWarning = rand();
     $this->guzzle->expects($this->at(1))->method('request')->will($this->throwException(new Exception($secondWarning)));
     $logger = $this->getMock('\\Psr\\Log\\LoggerInterface');
     $logger->expects($this->at(0))->method('warning')->with($this->equalTo($message));
     $logger->expects($this->at(1))->method('warning')->with($this->equalTo('Message: `' . $secondWarning . '`'));
     $this->fixture->setLogger($logger);
 }
开发者ID:jimlind,项目名称:tivo-php,代码行数:14,代码来源:VideoDownloaderTest.php

示例12: testSendConnectorException

 /**
  * Make sure that an exception with a error response is wrapped properly.
  *
  * @return void
  */
 public function testSendConnectorException()
 {
     $this->response->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue('application/json'));
     $data = ['error_code' => 'ERROR_CODE_1', 'error_messages' => ['Oh dear...', 'Oh no...'], 'correlation_id' => 'corr_id_1'];
     $this->response->expects($this->once())->method('json')->will($this->returnValue($data));
     $exception = new RequestException('Something went terribly wrong', $this->request, $this->response);
     $this->client->expects($this->once())->method('send')->with($this->request)->will($this->throwException($exception));
     $this->setExpectedException('Klarna\\Rest\\Transport\\Exception\\ConnectorException', 'ERROR_CODE_1: Oh dear..., Oh no... (#corr_id_1)');
     $this->object->send($this->request);
 }
开发者ID:NoviumDesign,项目名称:polefitness,代码行数:15,代码来源:ConnectorTest.php

示例13: testGuzzleReturnParsing

 /**
  * Test the NowPlaying string to SimpleXML parsing
  *
  * @param string[]           $xmlList  Array of XML strings
  * @param SimpleXMLElement[] $expected Array of XML Elements
  *
  * @dataProvider guzzleReturnParsingProvider
  */
 public function testGuzzleReturnParsing($xmlList, $expected)
 {
     foreach ($xmlList as $index => $xmlString) {
         $response = $this->getMock('\\Psr\\Http\\Message\\ResponseInterface');
         $response->method('getBody')->willReturn($xmlString);
         $response->method('getStatusCode')->willReturn(200);
         $this->guzzle->expects($this->at($index))->method('send')->will($this->returnValue($response));
     }
     $actual = $this->fixture->download();
     $this->assertEquals($expected, $actual);
 }
开发者ID:jimlind,项目名称:tivo-php,代码行数:19,代码来源:XmlDownloaderTest.php

示例14: testPutIndexRequestContent

 public function testPutIndexRequestContent()
 {
     $request = new PutIndexRequest();
     $body = Stream::factory('index-content');
     $httpRequest = $this->getMock('GuzzleHttp\\Message\\RequestInterface');
     $httpResponse = $this->getMock('GuzzleHttp\\Message\\ResponseInterface');
     $callback = function ($subject) {
         $json = json_decode($subject, true);
         $this->assertEquals('schema-content', $json['schema']);
         $this->assertEquals(3, $json['n_val']);
         return true;
     };
     $this->client->expects($this->once())->method('createRequest')->with($this->equalTo('PUT'), $this->equalTo('/search/index/index-name'))->willReturn($httpRequest);
     $this->client->expects($this->once())->method('send')->with($this->equalTo($httpRequest))->willReturn($httpResponse);
     $httpRequest->expects($this->once())->method('setBody')->with($this->callback($callback))->willReturn($body);
     $request->nVal = 3;
     $request->name = 'index-name';
     $request->schema = 'schema-content';
     $this->assertInstanceOf('Riak\\Client\\Core\\Message\\Search\\PutIndexResponse', $this->instance->send($request));
 }
开发者ID:php-riak,项目名称:riak-client,代码行数:20,代码来源:HttpPutIndexTest.php

示例15: testSearchRequestContent

 public function testSearchRequestContent()
 {
     $request = new SearchRequest();
     $query = $this->getMock('GuzzleHttp\\Query');
     $httpRequest = $this->getMock('GuzzleHttp\\Message\\RequestInterface');
     $httpResponse = $this->getMock('GuzzleHttp\\Message\\ResponseInterface');
     $this->client->expects($this->once())->method('createRequest')->with($this->equalTo('GET'), $this->equalTo('/search/query/index-name'))->willReturn($httpRequest);
     $this->client->expects($this->once())->method('send')->with($this->equalTo($httpRequest))->willReturn($httpResponse);
     $httpRequest->expects($this->once())->method('getQuery')->willReturn($query);
     $httpResponse->expects($this->once())->method('json')->willReturn(['response' => ['numFound' => 2, 'maxScore' => 1, 'docs' => [['name' => 'Fabio B. Silva', 'username' => 'fabios'], ['name' => 'Fabio B. Silva', 'username' => 'FabioBatSilva']]]]);
     $request->index = 'index-name';
     $request->q = 'name:Fabio*';
     $result = $this->instance->send($request);
     $this->assertInstanceOf('Riak\\Client\\Core\\Message\\Search\\SearchResponse', $result);
     $this->assertEquals(2, $result->numFound);
     $this->assertEquals(1, $result->maxScore);
     $this->assertCount(2, $result->docs);
     $this->assertArrayHasKey('name', $result->docs[0]);
     $this->assertArrayHasKey('name', $result->docs[1]);
     $this->assertArrayHasKey('username', $result->docs[0]);
     $this->assertArrayHasKey('username', $result->docs[1]);
 }
开发者ID:php-riak,项目名称:riak-client,代码行数:22,代码来源:HttpSearchTest.php


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