mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 16:08:55 +02:00
Added filters on factory method
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user