Removed influxdb-php as using composer

This commit is contained in:
laf
2015-08-18 18:59:59 +00:00
parent 087762c651
commit adfcec33fd
35 changed files with 0 additions and 3618 deletions

View File

@@ -1,7 +0,0 @@
<?php
/**
* @author Stephen "TheCodeAssassin" Hoogendijk
*/
// autoload dependencies
require __DIR__ . '/../vendor/autoload.php';

View File

@@ -1,124 +0,0 @@
<?php
/**
* @author Stephen "TheCodeAssassin" Hoogendijk
*/
namespace InfluxDB\Test;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use InfluxDB\Client;
use InfluxDB\Database;
use InfluxDB\Driver\Guzzle;
use InfluxDB\ResultSet;
use PHPUnit_Framework_MockObject_MockObject;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\Response;
/**
* @property mixed resultData
*/
abstract class AbstractTest extends \PHPUnit_Framework_TestCase
{
/** @var Client|PHPUnit_Framework_MockObject_MockObject $client */
protected $mockClient;
/**
* @var string
*/
protected $emptyResult = '{"results":[{}]}';
/**
* @var ResultSet
*/
protected $mockResultSet;
/** @var Database $database */
protected $database = null;
public function setUp()
{
$this->mockClient = $this->getMockBuilder('\InfluxDB\Client')
->disableOriginalConstructor()
->getMock();
$this->resultData = file_get_contents(dirname(__FILE__) . '/result.example.json');
$this->mockClient->expects($this->any())
->method('getBaseURI')
->will($this->returnValue($this->equalTo('http://localhost:8086')));
$this->mockClient->expects($this->any())
->method('query')
->will($this->returnValue(new ResultSet($this->resultData)));
$httpMockClient = new Guzzle($this->buildHttpMockClient(''));
// make sure the client has a valid driver
$this->mockClient->expects($this->any())
->method('getDriver')
->will($this->returnValue($httpMockClient));
$this->database = new Database('influx_test_db', $this->mockClient);
}
/**
* @return mixed
*/
public function getMockResultSet()
{
return $this->mockResultSet;
}
/**
* @param mixed $mockResultSet
*/
public function setMockResultSet($mockResultSet)
{
$this->mockResultSet = $mockResultSet;
}
/**
* @return GuzzleClient
*/
public function buildHttpMockClient($body)
{
// Create a mock and queue two responses.
$mock = new MockHandler([new Response(200, array(), $body)]);
$handler = HandlerStack::create($mock);
return new GuzzleClient(['handler' => $handler]);
}
/**
* @return string
*/
public function getEmptyResult()
{
return $this->emptyResult;
}
/**
* @param bool $emptyResult
*
* @return PHPUnit_Framework_MockObject_MockObject|Client
*/
public function getClientMock($emptyResult = false)
{
$mockClient = $this->getMockBuilder('\InfluxDB\Client')
->disableOriginalConstructor()
->getMock();
if ($emptyResult) {
$mockClient->expects($this->once())
->method('query')
->will($this->returnValue(new ResultSet($this->getEmptyResult())));
}
return $mockClient;
}
}

View File

@@ -1,72 +0,0 @@
<?php
namespace InfluxDB\Test;
use InfluxDB\Client;
use InfluxDB\Database;
use InfluxDB\Driver\Guzzle;
use InfluxDB\Point;
use InfluxDB\ResultSet;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit_Framework_TestCase;
class AdminTest extends AbstractTest
{
/**
*
*/
public function setUp()
{
parent::setUp();
}
/**
*
*/
public function testCreateUser()
{
$adminObject = $this->getAdminObject(true);
$this->assertEquals(
new ResultSet($this->emptyResult),
$adminObject->createUser('test', 'test', Client\Admin::PRIVILEGE_ALL)
);
}
public function testChangeUserPassword()
{
$adminObject = $this->getAdminObject(true);
$this->assertEquals(
new ResultSet($this->emptyResult),
$adminObject->changeUserPassword('test', 'test')
);
}
public function testShowUsers()
{
$testJson = file_get_contents(dirname(__FILE__) . '/result-test-users.example.json');
$clientMock = $this->getClientMock();
$testResult = new ResultSet($testJson);
$clientMock->expects($this->once())
->method('query')
->will($this->returnValue($testResult));
$adminMock = new Client\Admin($clientMock);
$this->assertEquals($testResult, $adminMock->showUsers());
}
/**
* @return Client\Admin
*/
private function getAdminObject()
{
return new Client\Admin($this->getClientMock(true));
}
}

View File

@@ -1,60 +0,0 @@
<?php
namespace InfluxDB\Test;
use InfluxDB\Client;
use InfluxDB\Driver\Guzzle;
class ClientTest extends AbstractTest
{
/**
*
*/
public function setUp()
{
parent::setUp();
}
/** @var Client $client */
protected $client = null;
public function testBaseURl()
{
$client = new Client('localhost', 8086);
$this->assertEquals($client->getBaseURI(), 'http://localhost:8086');
}
public function testSelectDbShouldReturnDatabaseInstance()
{
$client = new Client('localhost', 8086);
$dbName = 'test-database';
$database = $client->selectDB($dbName);
$this->assertInstanceOf('\InfluxDB\Database', $database);
$this->assertEquals($dbName, $database->getName());
}
/**
*/
public function testGuzzleQuery()
{
$client = new Client('localhost', 8086);
$query = "some-bad-query";
$bodyResponse = file_get_contents(dirname(__FILE__) . '/result.example.json');
$httpMockClient = $this->buildHttpMockClient($bodyResponse);
$client->setDriver(new Guzzle($httpMockClient));
/** @var \InfluxDB\ResultSet $result */
$result = $client->query(null, $query);
$this->assertInstanceOf('\InfluxDB\ResultSet', $result);
}
}

View File

@@ -1,100 +0,0 @@
<?php
namespace InfluxDB\Test;
use InfluxDB\Client;
use InfluxDB\Database;
use InfluxDB\Driver\Guzzle;
use InfluxDB\Point;
use InfluxDB\ResultSet;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit_Framework_TestCase;
class DatabaseTest extends AbstractTest
{
/**
* @var string
*/
protected $dataToInsert;
/**
* @var
*/
protected $mockResultSet;
public function setUp()
{
parent::setUp();
$this->resultData = file_get_contents(dirname(__FILE__) . '/result.example.json');
$this->mockClient->expects($this->any())
->method('listDatabases')
->will($this->returnValue(array('test123', 'test')));
$this->dataToInsert = file_get_contents(dirname(__FILE__) . '/input.example.json');
}
/**
*
*/
public function testQuery()
{
$testResultSet = new ResultSet($this->resultData);
$this->assertEquals($this->database->query('SELECT * FROM test_metric'), $testResultSet);
}
public function testCreateRetentionPolicy()
{
$retentionPolicy = new Database\RetentionPolicy('test', '1d', 1, true);
$mockClient = $this->getClientMock(true);
$database = new Database('test', $mockClient);
$this->assertEquals($database->createRetentionPolicy($retentionPolicy), new ResultSet($this->getEmptyResult()));
}
/**
* @expectedException \InvalidArgumentException
*/
public function testEmptyDatabaseName()
{
new Database(null, $this->mockClient);
}
public function testExists()
{
$database = new Database('test', $this->mockClient);
$this->assertEquals($database->exists(), true);
}
public function testNotExists()
{
$database = new Database('test_not_exists', $this->mockClient);
$this->assertEquals($database->exists(), false);
}
public function testWritePointsInASingleCall()
{
$point1 = new Point(
'cpu_load_short',
0.64,
array('host' => 'server01', 'region' => 'us-west'),
array('cpucount' => 10),
1435222310
);
$point2 = new Point(
'cpu_load_short',
0.84
);
$this->assertEquals(true, $this->database->writePoints(array($point1, $point2)));
}
}

View File

@@ -1,30 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: dmartinez
* Date: 18-6-15
* Time: 17:39
*/
namespace InfluxDB\Test;
use InfluxDB\Point;
class PointTest extends \PHPUnit_Framework_TestCase
{
public function testPointStringRepresentation()
{
$expected = 'cpu_load_short,host=server01,region=us-west cpucount=10,value=0.64 1435222310';
$point = new Point(
'cpu_load_short',
0.64,
array('host' => 'server01', 'region' => 'us-west'),
array('cpucount' => 10),
1435222310
);
$this->assertEquals($expected, (string) $point);
}
}

View File

@@ -1,141 +0,0 @@
<?php
namespace InfluxDB\Test;
use InfluxDB\ResultSet;
class ResultSetTest extends \PHPUnit_Framework_TestCase
{
/** @var ResultSet $resultSet*/
protected $resultSet;
public function setUp()
{
$resultJsonExample = file_get_contents(dirname(__FILE__) . '/result.example.json');
$this->resultSet = new ResultSet($resultJsonExample);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testThrowsExceptionIfJSONisNotValid()
{
$invalidJSON = 'foo';
new ResultSet($invalidJSON);
}
/**
* Throws Exception if something went wrong with influxDB
* @expectedException \InfluxDB\Exception
*/
public function testThrowsInfluxDBException()
{
$errorResult = <<<EOD
{
"series": [],
"error": "Big error, many problems."
}
EOD;
new ResultSet($errorResult);
}
/**
* Throws Exception if something went wrong with influxDB after processing the query
* @expectedException \InfluxDB\Exception
*/
public function testThrowsInfluxDBExceptionIfAnyErrorInSeries()
{
$errorResult = <<<EOD
{
"results": [
{
"series": [],
"error": "There was an error after querying"
}
]
}
EOD;
new ResultSet($errorResult);
}
/**
* We can get points from measurement
*/
public function testGetPointsFromNameWithoudTags()
{
$resultJsonExample = file_get_contents(dirname(__FILE__) . '/result-no-tags.example.json');
$this->resultSet = new ResultSet($resultJsonExample);
$measurementName = 'cpu_load_short';
$expectedNumberOfPoints = 2;
$points = $this->resultSet->getPoints($measurementName);
$this->assertTrue(is_array($points));
$this->assertCount($expectedNumberOfPoints, $points);
}
/**
* We can get points from measurement
*/
public function testGetPoints()
{
$expectedNumberOfPoints = 3;
$points = $this->resultSet->getPoints();
$this->assertTrue(
is_array($points)
);
$this->assertCount($expectedNumberOfPoints, $points);
}
/**
* We can get points from measurement
*/
public function testGetPointsFromMeasurementName()
{
$measurementName = 'cpu_load_short';
$expectedNumberOfPoints = 2;
$expectedValueFromFirstPoint = 0.64;
$points = $this->resultSet->getPoints($measurementName);
$this->assertTrue(
is_array($points)
);
$this->assertCount($expectedNumberOfPoints, $points);
$somePoint = array_shift($points);
$this->assertEquals($expectedValueFromFirstPoint, $somePoint['value']);
}
public function testGetPointsFromTags()
{
$tags = array("host" => "server01");
$expectedNumberOfPoints = 2;
$points = $this->resultSet->getPoints('', $tags);
$this->assertTrue(is_array($points));
$this->assertCount($expectedNumberOfPoints, $points);
}
public function testGetPointsFromNameAndTags()
{
$tags = array("host" => "server01");
$expectedNumberOfPoints = 2;
$points = $this->resultSet->getPoints('', $tags);
$this->assertTrue(is_array($points));
$this->assertCount($expectedNumberOfPoints, $points);
}
}

View File

@@ -1,17 +0,0 @@
{
"database": "mydb",
"retentionPolicy": "mypolicy",
"points": [
{
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"value": 0.64
}
}
]
}

View File

@@ -1,47 +0,0 @@
{
"results": [
{
"series": [
{
"name": "cpu_load_short",
"columns": [
"time",
"value"
],
"values": [
[
"2015-01-29T21:51:28.968422294Z",
0.64
]
]
},
{
"name": "cpu_load_short",
"columns": [
"time",
"value"
],
"values": [
[
"2015-01-29T21:51:28.968422294Z",
0.65
]
]
},
{
"name": "other_serie",
"columns": [
"time",
"value"
],
"values": [
[
"2015-01-29T21:51:28.968422294Z",
0.66
]
]
}
]
}
]
}

View File

@@ -1,24 +0,0 @@
{
"results": [
{
"series": [
{
"columns": [
"user",
"admin"
],
"values": [
[
"test1",
true
],
[
"test2",
false
]
]
}
]
}
]
}

View File

@@ -1,59 +0,0 @@
{
"results": [
{
"series": [
{
"name": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"columns": [
"time",
"value"
],
"values": [
[
"2015-01-29T21:51:28.968422294Z",
0.64
]
]
},
{
"name": "cpu_load_short",
"tags": {
"host": "server02",
"region": "us-west"
},
"columns": [
"time",
"value"
],
"values": [
[
"2015-01-29T21:51:28.968422294Z",
0.65
]
]
},
{
"name": "other_serie",
"tags": {
"host": "server01",
"region": "us-west"
},
"columns": [
"time",
"value"
],
"values": [
[
"2015-01-29T21:51:28.968422294Z",
0.66
]
]
}
]
}
]
}