mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Tests - ClientTest query method
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user