diff --git a/.travis.yml b/.travis.yml index 7c33ebc..933ae5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: php script: phpunit php: + - 5.3 - 5.4 - 5.5 @@ -9,4 +10,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/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 61b043f..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); } @@ -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/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 630b019..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,11 +82,11 @@ 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($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..b4b35a5 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() { @@ -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); @@ -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); }