/**
  * 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());
 }
 /**
  * @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);
 }
 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));
 }
 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());
 }
 /**
  * @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);
 }
 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);
 }
 /**
  * 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);
 }
Exemple #8
0
 /**
  * @covers ::setTimeout
  */
 public function testSetTimeout()
 {
     $this->internalClient->expects($this->once())->method('setDefaultOption')->with('timeout', 4);
     $this->client->setTimeout('4');
 }
 /**
  * @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'));
 }
 /**
  * @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));
 }