本文整理汇总了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());
}
示例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);
}
示例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));
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例8: testSetTimeout
/**
* @covers ::setTimeout
*/
public function testSetTimeout()
{
$this->internalClient->expects($this->once())->method('setDefaultOption')->with('timeout', 4);
$this->client->setTimeout('4');
}
示例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'));
}
示例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));
}