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


PHP Client::expects方法代码示例

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


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

示例1: testFetchDog

 /**
  * Tests retrieving a dog
  */
 public function testFetchDog()
 {
     // init vars
     $apiKey = 'this-is-another-api-key';
     // request expectations
     $tag = GiphyProvider::TYPE_DOG;
     $request = ['query' => ['api_key' => $apiKey, 'tag' => $tag]];
     // response expectations
     $id = 23457;
     $imageUrl = 'this-is-another-test-image-url';
     $imageWidth = 200;
     $imageHeight = 400;
     $response = new ResponseFake();
     $response->setBody(['data' => ['id' => $id, 'image_url' => $imageUrl, 'image_width' => $imageWidth, 'image_height' => $imageHeight]]);
     // init client
     $this->client->expects($this->any())->method('get')->with($this->anything(), $this->equalTo($request))->will($this->returnValue($response));
     // get the cat
     $provider = new GiphyProvider($this->client, $apiKey);
     $animal = $provider->fetchDog();
     // assert an animal with expected data is returned
     $this->assertInstanceOf('TimeInc\\CatsVsDogsBundle\\Document\\Dog', $animal);
     $this->assertEquals($id, $animal->getId());
     $this->assertEquals($imageUrl, $animal->getImageSrc());
     $this->assertEquals($imageWidth, $animal->getWidth());
     $this->assertEquals($imageHeight, $animal->getHeight());
 }
开发者ID:ngarnier,项目名称:code-challenge-2015,代码行数:29,代码来源:GiphyProviderTest.php

示例2: canRemoveAValidCore

 /**
  * @test
  */
 public function canRemoveAValidCore()
 {
     $core = new Core('testcore', 'typo3', 'english', '4.8', 1);
     $responseMock = $this->getMock(Response::class, array('getBody', 'getStatusCode'), array(), '', false);
     $responseMock->expects($this->any())->method('getStatusCode')->will($this->returnValue(204));
     $expectedDeleteEndpoint = 'https://myendpoint.com/api/solr_cores/1.json?api_token=foo&secret_token=bar';
     $this->httpClientMock->expects($this->once())->method('delete')->with($expectedDeleteEndpoint)->will($this->returnValue($responseMock));
     $result = $this->coreRestStorageBackend->remove($core);
     $this->assertTrue($result);
 }
开发者ID:timohund,项目名称:hosted_solr-php-api,代码行数:13,代码来源:CoreRestStorageBackendTest.php

示例3: testSendCachedWithCacheReturnsCache

 public function testSendCachedWithCacheReturnsCache()
 {
     $cacheKey = 'CACHE_KEY';
     $body = 'BODY';
     $this->cachedRequestMock->expects($this->any())->method('getCacheKey')->willReturn($cacheKey);
     $this->cachedRequestMock->expects($this->never())->method('getCacheFor');
     $this->guzzleClientMock->expects($this->never())->method('send');
     $this->memcacheMock->expects($this->once())->method('get')->with($cacheKey)->willReturn($body);
     $this->memcacheMock->expects($this->never())->method('set');
     $client = new ClientCached($this->guzzleClientMock, $this->memcacheMock);
     $this->assertSame($body, $client->sendCached($this->cachedRequestMock));
 }
开发者ID:assertis,项目名称:http-lib,代码行数:12,代码来源:CachedClientTest.php

示例4: testSendPostRequestReturnsZboziApiResponse

 public function testSendPostRequestReturnsZboziApiResponse()
 {
     $this->loggerMock->expects(self::once())->method('log');
     $requestUrl = 'someUrl';
     $requestBody = ['autoMarkDelivered' => true];
     $headers = [RequestMaker::HEADER_API_SECRET => $this->apiSecret, RequestMaker::HEADER_PARTNER_TOKEN => $this->partnerToken];
     $request = new \GuzzleHttp\Message\Request('POST', $requestUrl, $headers);
     $responseData = ['expectedDeliveryDate' => '2012-01-01'];
     $this->httpClientMock->expects(self::once())->method('createRequest')->with('POST', $requestUrl)->willReturn($request);
     $this->httpClientMock->expects(self::once())->method('send')->willReturn($this->createFutureResponse(200, json_encode($responseData)));
     $requestMaker = $this->createRequestMaker();
     $response = $requestMaker->sendPostRequest($requestUrl, $requestBody);
     $this->assertInstanceOf('SlevomatZboziApi\\Response\\ZboziApiResponse', $response);
     $this->assertSame(200, $response->getStatusCode());
     $this->assertSame($responseData, $response->getBody());
 }
开发者ID:pepakriz,项目名称:zbozi-api-php-library,代码行数:16,代码来源:RequestMakerTest.php

示例5: testExecuteWithClientExceptionAndHasResponse

 /**
  * @covers \jones\novaposhta\http\Client::execute
  * @expectedException \jones\novaposhta\http\ClientException
  * @expectedExceptionMessage Exception thrown by Guzzle client and has response
  */
 public function testExecuteWithClientExceptionAndHasResponse()
 {
     $message = 'Exception thrown by Guzzle client and has response';
     /** @var \GuzzleHttp\Psr7\Request $request */
     $request = $this->getMockBuilder(GuzzleRequest::class)->disableOriginalConstructor()->getMock();
     $exception = new ClientException($message, $request, $this->response);
     $this->guzzleClient->expects(static::once())->method('post')->willThrowException($exception);
     $this->response->expects(static::never())->method('getBody');
     $this->client->execute($this->request, ConverterInterface::FORMAT_XML, Request::API_URL_XML);
 }
开发者ID:joni-jones,项目名称:yii2-novaposhta,代码行数:15,代码来源:ClientTest.php

示例6: testSendPostRequestWorksWithoutLogger

 public function testSendPostRequestWorksWithoutLogger()
 {
     $this->loggerMock = null;
     $this->httpClientMock->expects(self::once())->method('send')->with($this->callback(function (\GuzzleHttp\Psr7\Request $subject) {
         return $subject->getMethod() === 'POST' && $subject->getUri()->getPath() === 'someUrl';
     }))->willReturn(new \GuzzleHttp\Psr7\Response(200, [], '{"someData":8}'));
     $requestMaker = $this->createRequestMaker();
     $requestMaker->sendPostRequest('someUrl');
     $this->assertTrue(true);
 }
开发者ID:slevomat,项目名称:zbozi-api-php-library,代码行数:10,代码来源:RequestMakerTest.php

示例7: testEnsureMessageCanBeSent

 /**
  * Test to ensure message is able to be sent correctly
  */
 public function testEnsureMessageCanBeSent()
 {
     // Set up the data fixture
     $fh = fopen('tests/Mocking/API/Fixtures/send-data.txt', 'r');
     $response = fread($fh, 4096);
     fclose($fh);
     $channel = 'C04C8KJRC';
     $text = 'This is a test';
     $url = self::BASEURL . 'chat.postMessage';
     $bodyParam = ['body' => ['token' => $this->token, 'channel' => $channel, 'text' => $text]];
     $this->client->expects($this->once())->method('post')->with($url, $bodyParam)->will($this->returnValue($this->response));
     $this->response->expects($this->once())->method('getBody')->will($this->returnValue($response));
     $slack = new Slack($this->client, $this->token);
     $result = $slack->sendMessage($text, $channel);
     $arrayResponse = json_decode($result, true);
     $this->assertTrue($arrayResponse['ok']);
     $this->assertEquals($arrayResponse['channel'], $channel);
     $this->assertEquals($arrayResponse['message']['text'], $text);
 }
开发者ID:WenkeZhou,项目名称:phpunit-tutorial,代码行数:22,代码来源:SlackTest.php

示例8: testSetTimeout

 /**
  * @covers ::setTimeout
  */
 public function testSetTimeout()
 {
     $this->internalClient->expects($this->once())->method('setDefaultOption')->with('timeout', 4);
     $this->client->setTimeout('4');
 }
开发者ID:ChaosPower,项目名称:crate-pdo,代码行数:8,代码来源:ClientTest.php

示例9: getShouldConfigureHeaders

 /**
  * @test
  */
 public function getShouldConfigureHeaders()
 {
     $client = new Client($this->httpClient);
     $this->httpClient->expects($this->once())->method('get')->with('/test?name=Test', ['verify' => false])->willReturn($this->response);
     $this->assertInstanceOf('SimpleXMLElement', $client->get('/test?name=Test'));
 }
开发者ID:leonardorifeli,项目名称:pagseguro,代码行数:9,代码来源:ClientTest.php

示例10: testGetToSink

 /**
  * @param string $url
  * @param \GuzzleHttp\Psr7\Response $response
  * @param string $filePath
  * @param array|int $result
  * @dataProvider getToSinkDataProvider
  */
 public function testGetToSink($url, $response, $filePath, $result)
 {
     $this->clientMock->expects($this->once())->method('get')->with($url, [RequestOptions::SINK => $filePath])->willReturn($response);
     $this->assertEquals($result, $this->httpMock->getToSink($url, $filePath));
 }
开发者ID:subscribepro,项目名称:subscribepro-php,代码行数:12,代码来源:HttpTest.php


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