From 20e2527a920a4a89195c2008f2f5c70103639765 Mon Sep 17 00:00:00 2001 From: danibrutal Date: Fri, 19 Jun 2015 11:33:44 +0200 Subject: [PATCH] Changing Client Exception, testing Point --- src/Leaseweb/InfluxDB/Client/Exception.php | 13 +++++++++++++ src/Leaseweb/InfluxDB/Database.php | 2 +- src/Leaseweb/InfluxDB/InfluxDBClientError.php | 12 ------------ src/Leaseweb/InfluxDB/Point.php | 19 ++++++++++++++----- src/Leaseweb/InfluxDB/ResultSet.php | 12 +++++++----- tests/unit/PointTest.php | 5 +---- tests/unit/ResultSetTest.php | 4 ++-- 7 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 src/Leaseweb/InfluxDB/Client/Exception.php delete mode 100644 src/Leaseweb/InfluxDB/InfluxDBClientError.php diff --git a/src/Leaseweb/InfluxDB/Client/Exception.php b/src/Leaseweb/InfluxDB/Client/Exception.php new file mode 100644 index 000000000..8d4c258d0 --- /dev/null +++ b/src/Leaseweb/InfluxDB/Client/Exception.php @@ -0,0 +1,13 @@ +a(); + //$point->a(); } } diff --git a/src/Leaseweb/InfluxDB/InfluxDBClientError.php b/src/Leaseweb/InfluxDB/InfluxDBClientError.php deleted file mode 100644 index 75b8dbc22..000000000 --- a/src/Leaseweb/InfluxDB/InfluxDBClientError.php +++ /dev/null @@ -1,12 +0,0 @@ -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); } + } \ No newline at end of file diff --git a/src/Leaseweb/InfluxDB/ResultSet.php b/src/Leaseweb/InfluxDB/ResultSet.php index f9c932b91..4380c33f9 100644 --- a/src/Leaseweb/InfluxDB/ResultSet.php +++ b/src/Leaseweb/InfluxDB/ResultSet.php @@ -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']; diff --git a/tests/unit/PointTest.php b/tests/unit/PointTest.php index 32916d2a8..ea693cf76 100644 --- a/tests/unit/PointTest.php +++ b/tests/unit/PointTest.php @@ -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); } - } \ No newline at end of file diff --git a/tests/unit/ResultSetTest.php b/tests/unit/ResultSetTest.php index 024da364f..d68da1cd8 100644 --- a/tests/unit/ResultSetTest.php +++ b/tests/unit/ResultSetTest.php @@ -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() {