From 42d2c2d1f0629f70900adbef5bf6f13b5c5ab360 Mon Sep 17 00:00:00 2001 From: Pablo Lopez Torres Date: Thu, 4 Sep 2014 18:28:50 +0200 Subject: [PATCH 1/2] fixing the TravisCI build with InfluxDB new features: - dbs is changed to db in the latest InfluxDB when listing dbs - username is changed to name in the latest InfluxDB when creating user - PHPUnit_Framework_TestCase instead of phpunit_framework_testcase - Grouping by anything but time does not return time anymore --- .travis.yml | 1 + lib/InfluxPHP/Client.php | 2 +- lib/InfluxPHP/DB.php | 4 ++-- tests/DBTest.php | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7c33ebc..71bb864 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,5 @@ before_script: - curl -s http://getcomposer.org/installer | php - wget http://s3.amazonaws.com/influxdb/influxdb_latest_amd64.deb - sudo dpkg -i influxdb_latest_amd64.deb + - travis_retry sudo service influxdb restart - php composer.phar install diff --git a/lib/InfluxPHP/Client.php b/lib/InfluxPHP/Client.php index 61b043f..98ec21e 100644 --- a/lib/InfluxPHP/Client.php +++ b/lib/InfluxPHP/Client.php @@ -68,7 +68,7 @@ class Client extends BaseHTTP $self = $this; return array_map(function($obj) use($self) { return new DB($self, $obj['name']); - }, $this->get('dbs')); + }, $this->get('db')); } public function getDatabase($name) diff --git a/lib/InfluxPHP/DB.php b/lib/InfluxPHP/DB.php index 630b019..15d6fd6 100644 --- a/lib/InfluxPHP/DB.php +++ b/lib/InfluxPHP/DB.php @@ -85,8 +85,8 @@ class DB extends BaseHTTP return new Cursor($this->get('series', ['q' => $sql, 'time_precision' => $this->timePrecision])); } - public function createUser($username, $password) + public function createUser($name, $password) { - return $this->post('users', compact('username', 'password')); + return $this->post('users', compact('name', 'password')); } } diff --git a/tests/DBTest.php b/tests/DBTest.php index 621a032..de67e6a 100644 --- a/tests/DBTest.php +++ b/tests/DBTest.php @@ -2,7 +2,7 @@ use crodas\InfluxPHP\Client; use crodas\InfluxPHP\DB; -class DBTest extends \phpunit_framework_testcase +class DBTest extends \PHPUnit_Framework_TestCase { public function testCreate() { @@ -103,17 +103,17 @@ class DBTest extends \phpunit_framework_testcase $db = $client->test_xxx; $client->setTimePrecision('u'); - foreach ($db->query("SELECT mean(karma) FROM foobar GROUP BY type") as $row) { + foreach ($db->query("SELECT mean(karma) FROM foobar GROUP BY type, time(1h)") as $row) { $this->assertTrue($row->time > time()*1000); } $client->setTimePrecision('m'); - foreach ($db->query("SELECT mean(karma) FROM foobar GROUP BY type") as $row) { + foreach ($db->query("SELECT mean(karma) FROM foobar GROUP BY type, time(1h)") as $row) { $this->assertTrue($row->time < time()*10000); } $client->setTimePrecision('s'); - foreach ($db->query("SELECT mean(karma) FROM foobar GROUP BY type") as $row) { + foreach ($db->query("SELECT mean(karma) FROM foobar GROUP BY type, time(1h)") as $row) { $this->assertTrue($row->time < time()+20); } From 581ad939e6185fdaec31db4c00aceb7c0edac4c4 Mon Sep 17 00:00:00 2001 From: Pablo Lopez Torres Date: Thu, 4 Sep 2014 18:33:45 +0200 Subject: [PATCH 2/2] Compatibility with PHP5.3: Changing [] syntax to array() --- .travis.yml | 1 + lib/InfluxPHP/BaseHTTP.php | 16 ++++++++-------- lib/InfluxPHP/Client.php | 2 +- lib/InfluxPHP/Cursor.php | 2 +- lib/InfluxPHP/DB.php | 8 ++++---- tests/DBTest.php | 8 ++++---- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 71bb864..933ae5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: php script: phpunit php: + - 5.3 - 5.4 - 5.5 diff --git a/lib/InfluxPHP/BaseHTTP.php b/lib/InfluxPHP/BaseHTTP.php index 55efb0d..8b98dd5 100644 --- a/lib/InfluxPHP/BaseHTTP.php +++ b/lib/InfluxPHP/BaseHTTP.php @@ -64,9 +64,9 @@ class BaseHTTP $c->children[] = $this; } - protected function getCurl($url, array $args = []) + protected function getCurl($url, array $args = array()) { - $args = array_merge($args, ['u' => $this->user, 'p' => $this->pass]); + $args = array_merge($args, array('u' => $this->user, 'p' => $this->pass)); $url = "http://{$this->host}:{$this->port}/{$this->base}{$url}"; $url .= "?" . http_build_query($args); $ch = curl_init($url); @@ -89,9 +89,9 @@ class BaseHTTP protected function delete($url) { $ch = $this->getCurl($url); - curl_setopt_array($ch, [ + curl_setopt_array($ch, array( CURLOPT_CUSTOMREQUEST => "DELETE", - ]); + )); return $this->execCurl($ch); } @@ -119,19 +119,19 @@ class BaseHTTP throw new \InvalidArgumentException("Expecting s, m or u as time precision"); } - protected function get($url, array $args = []) + protected function get($url, array $args = array()) { $ch = $this->getCurl($url, $args); return $this->execCurl($ch, true); } - protected function post($url, array $body, array $args = []) + protected function post($url, array $body, array $args = array()) { $ch = $this->getCurl($url, $args); - curl_setopt_array($ch, [ + curl_setopt_array($ch, array( CURLOPT_POST => 1, CURLOPT_POSTFIELDS => json_encode($body), - ]); + )); return $this->execCurl($ch); } diff --git a/lib/InfluxPHP/Client.php b/lib/InfluxPHP/Client.php index 98ec21e..a304b2c 100644 --- a/lib/InfluxPHP/Client.php +++ b/lib/InfluxPHP/Client.php @@ -59,7 +59,7 @@ class Client extends BaseHTTP public function createDatabase($name) { - $this->post('db', ['name' => $name]); + $this->post('db', array('name' => $name)); return new DB($this, $name); } diff --git a/lib/InfluxPHP/Cursor.php b/lib/InfluxPHP/Cursor.php index 60f73a6..717a4a1 100644 --- a/lib/InfluxPHP/Cursor.php +++ b/lib/InfluxPHP/Cursor.php @@ -43,7 +43,7 @@ class Cursor extends ArrayIterator { public function __construct(array $resultset) { - $rows = []; + $rows = array(); foreach ($resultset as $set) { foreach ($set['points'] as $row) { $row = (object)array_combine($set['columns'], $row); diff --git a/lib/InfluxPHP/DB.php b/lib/InfluxPHP/DB.php index 15d6fd6..01b92b5 100644 --- a/lib/InfluxPHP/DB.php +++ b/lib/InfluxPHP/DB.php @@ -62,17 +62,17 @@ class DB extends BaseHTTP public function insert($name, array $data) { - $points = []; + $points = array(); $first = current($data); if (!is_array($first)) { - return $this->insert($name, [$data]); + return $this->insert($name, array($data)); } $columns = array_keys($first); foreach ($data as $value) { $points[] = array_values($value); } $body = compact('name', 'columns', 'points'); - return $this->post('series', [$body], ['time_precision' => $this->timePrecision]); + return $this->post('series', array($body), array('time_precision' => $this->timePrecision)); } public function first($sql) @@ -82,7 +82,7 @@ class DB extends BaseHTTP public function query($sql) { - return new Cursor($this->get('series', ['q' => $sql, 'time_precision' => $this->timePrecision])); + return new Cursor($this->get('series', array('q' => $sql, 'time_precision' => $this->timePrecision))); } public function createUser($name, $password) diff --git a/tests/DBTest.php b/tests/DBTest.php index de67e6a..b4b35a5 100644 --- a/tests/DBTest.php +++ b/tests/DBTest.php @@ -69,7 +69,7 @@ class DBTest extends \PHPUnit_Framework_TestCase public function testInvalidTimePrecision() { $client = new Client; - $client->SetTimePrecision([]); + $client->SetTimePrecision(array()); } public function testQuery() @@ -78,9 +78,9 @@ class DBTest extends \PHPUnit_Framework_TestCase $db = $client->createDatabase("test_xxx"); $db->createUser("root", "root"); - $db->insert("foobar", ['type' => '/foobar', 'karma' => 10]); - $db->insert("foobar", ['type' => '/foobar', 'karma' => 20]); - $db->insert("foobar", ['type' => '/barfoo', 'karma' => 30]); + $db->insert("foobar", array('type' => '/foobar', 'karma' => 10)); + $db->insert("foobar", array('type' => '/foobar', 'karma' => 20)); + $db->insert("foobar", array('type' => '/barfoo', 'karma' => 30)); $this->assertEquals($db->first("SELECT max(karma) FROM foobar")->max, 30); $this->assertEquals($db->first("SELECT min(karma) FROM foobar")->min, 10);