From 90277f14a8abf3fabd3f511ae6d9143d12bf30dd Mon Sep 17 00:00:00 2001 From: danibrutal Date: Fri, 19 Jun 2015 12:04:25 +0200 Subject: [PATCH] Writing Points tests --- src/Leaseweb/InfluxDB/Database.php | 8 ++++++++ src/Leaseweb/InfluxDB/Point.php | 2 ++ tests/unit/DatabaseTest.php | 18 +++++++++--------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Leaseweb/InfluxDB/Database.php b/src/Leaseweb/InfluxDB/Database.php index 4f92ba3f36..b757e602ac 100644 --- a/src/Leaseweb/InfluxDB/Database.php +++ b/src/Leaseweb/InfluxDB/Database.php @@ -51,6 +51,14 @@ class Database } + /** + * @return string db name + */ + public function getName() + { + return $this->name; + } + /** * Query influxDB * diff --git a/src/Leaseweb/InfluxDB/Point.php b/src/Leaseweb/InfluxDB/Point.php index debc659c33..2df53855e8 100644 --- a/src/Leaseweb/InfluxDB/Point.php +++ b/src/Leaseweb/InfluxDB/Point.php @@ -20,6 +20,8 @@ class Point private $timestamp; /** + * todo: Handle optional timestamp + * * @param $measurement * @param array $tags * @param array $fields diff --git a/tests/unit/DatabaseTest.php b/tests/unit/DatabaseTest.php index cbb255b85b..e4dddc3e13 100644 --- a/tests/unit/DatabaseTest.php +++ b/tests/unit/DatabaseTest.php @@ -33,10 +33,8 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase $this->dataToInsert = file_get_contents(dirname(__FILE__) . '/input.example.json'); } - /** - * todo: - */ - public function testWrite() + + public function testWritePointsInASingleCall() { $point1 = new Point( 'cpu_load_short', @@ -44,7 +42,6 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase array('value' => 0.64), 'myTime' ); - $point2 = new Point( 'cpu_load_short', array('host' =>'server01', 'region'=>'us-west'), @@ -52,10 +49,13 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase 'myTime' ); - //$this->db->writePoints(array($point1, $point2)); + $payloadExpected ="$point1\n$point2"; - $this->assertTrue( - true - ); + $this->mockClient->expects($this->once()) + ->method('query') + ->with($this->equalTo($this->db->getName()), $this->equalTo($payloadExpected)) + ->will($this->returnValue($this->equalTo('http://localhost:8086'))); + + $this->db->writePoints(array($point1, $point2)); } } \ No newline at end of file