2015-06-18 14:59:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
2015-06-23 09:19:24 +02:00
|
|
|
namespace InfluxDB\Test;
|
2015-06-18 14:59:00 +02:00
|
|
|
|
2015-06-23 09:19:24 +02:00
|
|
|
use InfluxDB\Client;
|
2015-07-06 15:58:29 +02:00
|
|
|
use InfluxDB\ResultSet;
|
2015-06-18 14:59:00 +02:00
|
|
|
|
|
|
|
|
class ClientTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** @var Client $client */
|
|
|
|
|
protected $client = null;
|
2015-07-03 17:20:35 +02:00
|
|
|
|
2015-06-18 14:59:00 +02:00
|
|
|
public function testBaseURl()
|
|
|
|
|
{
|
2015-07-03 17:20:35 +02:00
|
|
|
$client = new Client('localhost', 8086);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$client->getBaseURI(), 'http://localhost:8086'
|
2015-06-18 14:59:00 +02:00
|
|
|
);
|
|
|
|
|
}
|
2015-07-03 17:29:25 +02:00
|
|
|
|
|
|
|
|
public function testSelectDbShouldReturnDatabaseInstance()
|
|
|
|
|
{
|
|
|
|
|
$client = new Client('localhost', 8086);
|
|
|
|
|
|
|
|
|
|
$dbName = 'test-database';
|
|
|
|
|
$db = $client->selectDB($dbName);
|
|
|
|
|
|
|
|
|
|
$this->assertInstanceOf('\InfluxDB\Database', $db);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($dbName, $db->getName());
|
|
|
|
|
}
|
2015-07-06 15:58:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
2015-06-18 14:59:00 +02:00
|
|
|
}
|