Tests - ClientTest query method

This commit is contained in:
danibrutal
2015-07-06 15:58:29 +02:00
parent f6be9bedb4
commit 9dc122dccd
2 changed files with 47 additions and 0 deletions
+12
View File
@@ -117,6 +117,18 @@ class Client
}
/**
* For testing
* @param \Guzzle\Http\Client $client
* @return $this
*/
public function setHttpClient(\Guzzle\Http\Client $client)
{
$this->httpClient = $client;
return $this;
}
/**
* Use the given database
*
+35
View File
@@ -3,6 +3,7 @@
namespace InfluxDB\Test;
use InfluxDB\Client;
use InfluxDB\ResultSet;
class ClientTest extends \PHPUnit_Framework_TestCase
{
@@ -30,4 +31,38 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($dbName, $db->getName());
}
/**
*/
public function testQuery()
{
$client = new Client('localhost', 8086);
$query = "some-bad-query";
$bodyResponse = file_get_contents(dirname(__FILE__) . '/result.example.json');
$httpMockClient = $this->buildHttpMockClient($bodyResponse);
$client->setHttpClient($httpMockClient);
/** @var \InfluxDB\ResultSet $result */
$result = $client->query(null, $query);
$this->assertInstanceOf('\InfluxDB\ResultSet', $result);
}
/**
* @return \Guzzle\Http\Client
*/
protected function buildHttpMockClient($body)
{
$plugin = new \Guzzle\Plugin\Mock\MockPlugin();
$response= new \Guzzle\Http\Message\Response(200);
$response->setBody($body);
$plugin->addResponse($response);
$mockedClient = new \Guzzle\Http\Client();
$mockedClient->addSubscriber($plugin);
return $mockedClient;
}
}