diff --git a/src/InfluxDB/ClientFactory.php b/src/InfluxDB/ClientFactory.php index 1fe7846d1..035b7f53d 100644 --- a/src/InfluxDB/ClientFactory.php +++ b/src/InfluxDB/ClientFactory.php @@ -12,6 +12,9 @@ abstract class ClientFactory "options" => [], ], "options" => [], + "filters" => [ + "query" => false + ], ]; public static function create(array $options) @@ -42,6 +45,10 @@ abstract class ClientFactory $client = new Client(); $client->setAdapter($adapter); + if ($options["filters"]["query"]) { + $client->setFilter(new $options["filters"]["query"]["name"]); + } + return $client; } } diff --git a/tests/InfluxDB/ClientFactoryTest.php b/tests/InfluxDB/ClientFactoryTest.php index febd80294..058de134b 100644 --- a/tests/InfluxDB/ClientFactoryTest.php +++ b/tests/InfluxDB/ClientFactoryTest.php @@ -54,4 +54,37 @@ class ClientFactoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals("user", $client->getAdapter()->getOptions()->getUsername()); $this->assertEquals("pass", $client->getAdapter()->getOptions()->getPassword()); } + + /** + * @group factory + * @group filters + */ + public function testCreateTcpClientWithFilter() + { + $options = [ + "adapter" => [ + "name" => "InfluxDB\\Adapter\\GuzzleAdapter", + ], + "options" => [ + "host" => "127.0.0.1", + "username" => "user", + "password" => "pass", + ], + "filters" => [ + "query" => [ + "name" => "InfluxDB\\Filter\\ColumnsPointsFilter", + ], + ], + ]; + + $client = ClientFactory::create($options); + $this->assertInstanceOf("InfluxDB\\Client", $client); + + $this->assertInstanceOf("InfluxDB\\Adapter\\GuzzleAdapter", $client->getAdapter()); + $this->assertEquals("127.0.0.1", $client->getAdapter()->getOptions()->getHost()); + $this->assertEquals("user", $client->getAdapter()->getOptions()->getUsername()); + $this->assertEquals("pass", $client->getAdapter()->getOptions()->getPassword()); + + $this->assertInstanceOf("InfluxDB\\Filter\\ColumnsPointsFilter", $client->getFilter()); + } }