diff --git a/VERSION b/VERSION index 0d91a54c7d..9e11b32fca 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.0 +0.3.1 diff --git a/spec/InfluxDB/Filter/ColumnsPointsFilterSpec.php b/spec/InfluxDB/Filter/ColumnsPointsFilterSpec.php index 4e85f88fc2..efe19eeb05 100644 --- a/spec/InfluxDB/Filter/ColumnsPointsFilterSpec.php +++ b/spec/InfluxDB/Filter/ColumnsPointsFilterSpec.php @@ -19,7 +19,7 @@ class ColumnsPointsFilterSpec extends ObjectBehavior function it_should_map_columns_with_points() { - $response = json_decode('[{"name":"hd_used","columns":["time","sequence_number","value","host","mount","time_precision"],"points":[[1410591684,11820001,23.2,"serverA","/mnt","s"]]}]'); + $response = json_decode('[{"name":"hd_used","columns":["time","sequence_number","value","host","mount","time_precision"],"points":[[1410591684,11820001,23.2,"serverA","/mnt","s"]]}]', true); $this->filter($response)->shouldBeEqualTo([ "hd_used" => [ @@ -37,7 +37,7 @@ class ColumnsPointsFilterSpec extends ObjectBehavior function it_should_map_also_a_series_list() { - $response = json_decode('[{"name":"list_series_result","columns":["time","name"],"points":[[0,"hd_used"]]}]'); + $response = json_decode('[{"name":"list_series_result","columns":["time","name"],"points":[[0,"hd_used"]]}]', true); $this->filter($response)->shouldBeEqualTo([ "list_series_result" => [ @@ -51,7 +51,7 @@ class ColumnsPointsFilterSpec extends ObjectBehavior function it_should_reply_to_an_empty_set() { - $response = json_decode('[]'); + $response = json_decode('[]', true); $this->filter($response)->shouldBeEqualTo([]); } diff --git a/src/InfluxDB/Filter/ColumnsPointsFilter.php b/src/InfluxDB/Filter/ColumnsPointsFilter.php index 54e9ff127e..dcc974d399 100644 --- a/src/InfluxDB/Filter/ColumnsPointsFilter.php +++ b/src/InfluxDB/Filter/ColumnsPointsFilter.php @@ -15,11 +15,11 @@ class ColumnsPointsFilter implements FilterInterface $response = []; foreach ($metrics as $metric) { - $columns = $metric->columns; - $response[$metric->name] = []; + $columns = $metric["columns"]; + $response[$metric["name"]] = []; - foreach ($metric->points as $point) { - $response[$metric->name][] = array_combine($columns, $point); + foreach ($metric["points"] as $point) { + $response[$metric["name"]][] = array_combine($columns, $point); } } diff --git a/tests/InfluxDB/ClientTest.php b/tests/InfluxDB/ClientTest.php index 45ea0397e2..2a4bf78ea4 100644 --- a/tests/InfluxDB/ClientTest.php +++ b/tests/InfluxDB/ClientTest.php @@ -5,6 +5,7 @@ use InfluxDB\Adapter\GuzzleAdapter as InfluxHttpAdapter; use InfluxDB\Options; use InfluxDB\Adapter\UdpAdapter; use GuzzleHttp\Client as GuzzleHttpClient; +use InfluxDB\Filter\ColumnsPointsFilter; class ClientTest extends \PHPUnit_Framework_TestCase { @@ -146,6 +147,21 @@ class ClientTest extends \PHPUnit_Framework_TestCase $this->assertEquals("udp.test", $body[0]["name"]); } + /** + * @group filter + */ + public function testColumnsPointsFilterWorksCorrectly() + { + $this->object->setFilter(new ColumnsPointsFilter()); + $this->object->mark("tcp.test", ["time" => 1410591552, "mark" => "element"], "s"); + + $body = $this->object->query("select mark from tcp.test", "ms"); + + $this->assertCount(1, $body); + $this->assertEquals("element", $body["tcp.test"][0]["mark"]); + $this->assertSame(1410591552000, $body["tcp.test"][0]["time"]); + } + public function testListActiveDatabses() { $databases = $this->object->getDatabases(); diff --git a/tests/InfluxDB/HttpAdapterTest.php b/tests/InfluxDB/HttpAdapterTest.php index 9d6871c83c..d6f8689828 100644 --- a/tests/InfluxDB/HttpAdapterTest.php +++ b/tests/InfluxDB/HttpAdapterTest.php @@ -3,6 +3,7 @@ namespace InfluxDB; use InfluxDB\Adapter\HttpAdapter; use InfluxDB\Adapter\UdpAdapter; +use InfluxDB\Filter\ColumnsPointsFilter; class HttpAdapterTest extends \PHPUnit_Framework_TestCase { @@ -109,6 +110,21 @@ class HttpAdapterTest extends \PHPUnit_Framework_TestCase $this->assertEquals("1410591552000", $body[0]["points"][0][0]); } + /** + * @group filter + */ + public function testColumnsPointsFilterWorksCorrectly() + { + $this->object->setFilter(new ColumnsPointsFilter()); + $this->object->mark("tcp.test", ["time" => 1410591552, "mark" => "element"], "s"); + + $body = $this->object->query("select mark from tcp.test", "ms"); + + $this->assertCount(1, $body); + $this->assertEquals("element", $body["tcp.test"][0]["mark"]); + $this->assertSame(1410591552000, $body["tcp.test"][0]["time"]); + } + public function testListActiveDatabses() { $databases = $this->object->getDatabases();