Changing Client Exception, testing Point

This commit is contained in:
danibrutal
2015-06-19 11:34:08 +02:00
parent d625efdedc
commit 20e2527a92
7 changed files with 38 additions and 29 deletions
@@ -0,0 +1,13 @@
<?php
namespace Leaseweb\InfluxDB\Client;
/**
* Class Exception
*
* @package Leaseweb\InfluxDB\Client
*/
class Exception extends \Leaseweb\InfluxDB\Exception
{
}
+1 -1
View File
@@ -104,7 +104,7 @@ class Database
public function writePoints(array $points)
{
foreach ($points as $point) {
$point->a();
//$point->a();
}
}
@@ -1,12 +0,0 @@
<?php
namespace Leaseweb\InfluxDB;
/**
* Class InfluxDBClientError
* @package Leaseweb\InfluxDB
*/
class InfluxDBClientError extends \RuntimeException
{
}
+14 -5
View File
@@ -41,15 +41,24 @@ class Point
*/
public function __toString()
{
return "";
/*return sprintf(
return sprintf(
'%s,%s %s %s',
$this->measurement,
implode()
);*/
$this->arrayToString($this->tags),
$this->arrayToString($this->fields),
$this->timestamp
);
}
public function a(){
private function arrayToString(array $arr)
{
$strParts = array();
foreach ($arr as $key=> $value) {
$strParts[]="{$key}={$value}";
}
return implode(",", $strParts);
}
}
+7 -5
View File
@@ -5,6 +5,8 @@
namespace Leaseweb\InfluxDB;
use Leaseweb\InfluxDB\Client\Exception as ClientException;
/**
* Class ResultSet
*
@@ -26,7 +28,7 @@ class ResultSet
* @param $raw
*
* @throws \InvalidArgumentException
* @throws InfluxDBClientError
* @throws Exception
*/
public function __construct($raw)
{
@@ -40,11 +42,11 @@ class ResultSet
// There was an error in the query thrown by influxdb
if (isset($this->parsedResults['error'])) {
throw new InfluxDBClientError($this->parsedResults['error']);
throw new ClientException($this->parsedResults['error']);
// Check if there are errors in the first serie
} elseif (isset($this->parsedResults['results'][0]['error'])) {
throw new InfluxDBClientError($this->parsedResults['results'][0]['error']);
throw new ClientException($this->parsedResults['results'][0]['error']);
}
}
@@ -77,7 +79,7 @@ class ResultSet
* results is an array of objects, one for each query,
* each containing the keys for a series
*
* @throws InfluxDBClientError
* @throws Exception
*
* @return array $series
*/
@@ -86,7 +88,7 @@ class ResultSet
$pickSeries = function ($object) {
if (isset($object['error'])) {
throw new InfluxDBClientError($object['error']);
throw new ClientException($object['error']);
}
return $object['series'];
+1 -4
View File
@@ -13,10 +13,9 @@ use Leaseweb\InfluxDB\Point;
class PointTest extends \PHPUnit_Framework_TestCase
{
public function testPointStringRepresentation()
{
$expected = 'cpu_load_short,host=server01,region=us-west value=0.64 mytime';
$expected = 'cpu_load_short,host=server01,region=us-west value=0.64 myTime';
$point = new Point(
'cpu_load_short',
@@ -25,8 +24,6 @@ class PointTest extends \PHPUnit_Framework_TestCase
'myTime'
);
$this->assertEquals($expected, (string) $point);
}
}
+2 -2
View File
@@ -26,7 +26,7 @@ class ResultSetTest extends \PHPUnit_Framework_TestCase
/**
* Throws Exception if something went wrong with influxDB
* @expectedException \Leaseweb\InfluxDB\InfluxDBClientError
* @expectedException \Leaseweb\InfluxDB\Exception
*/
public function testThrowsInfluxDBException()
{
@@ -42,7 +42,7 @@ EOD;
/**
* Throws Exception if something went wrong with influxDB after processing the query
* @expectedException \Leaseweb\InfluxDB\InfluxDBClientError
* @expectedException \Leaseweb\InfluxDB\Exception
*/
public function testThrowsInfluxDBExceptionIfAnyErrorInSeries()
{