mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 16:08:55 +02:00
Moved default options for factory
This commit is contained in:
@@ -6,20 +6,20 @@ use GuzzleHttp\Client as GuzzleClient;
|
||||
|
||||
abstract class ClientFactory
|
||||
{
|
||||
private static $options = [
|
||||
"adapter" => [
|
||||
"name" => false,
|
||||
"options" => [],
|
||||
],
|
||||
"options" => [],
|
||||
"filters" => [
|
||||
"query" => false
|
||||
],
|
||||
];
|
||||
|
||||
public static function create(array $options)
|
||||
{
|
||||
$options = array_replace_recursive(self::$options, $options);
|
||||
$defaultOptions = [
|
||||
"adapter" => [
|
||||
"name" => false,
|
||||
"options" => [],
|
||||
],
|
||||
"options" => [],
|
||||
"filters" => [
|
||||
"query" => false
|
||||
],
|
||||
];
|
||||
|
||||
$options = array_replace_recursive($defaultOptions, $options);
|
||||
|
||||
$adapterName = $options["adapter"]["name"];
|
||||
if (!class_exists($adapterName)) {
|
||||
|
||||
@@ -3,6 +3,35 @@ namespace InfluxDB;
|
||||
|
||||
class ClientFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @group factory
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testEmptyOptions()
|
||||
{
|
||||
$client = ClientFactory::create([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group factory
|
||||
*/
|
||||
public function testDefaultParams()
|
||||
{
|
||||
$client = ClientFactory::create(["adapter" => ["name" => "InfluxDB\\Adapter\\GuzzleAdapter"]]);
|
||||
|
||||
$this->assertNull($client->getFilter());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group factory
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidAdapter()
|
||||
{
|
||||
$client = ClientFactory::create(["adapter" => ["name" => "UdpAdapter"]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group factory
|
||||
* @group udp
|
||||
|
||||
Reference in New Issue
Block a user