Moved default options for factory

This commit is contained in:
Walter Dal Mut
2014-09-26 22:06:41 +02:00
parent 3c61199815
commit d0966dd5a4
2 changed files with 41 additions and 12 deletions
+12 -12
View File
@@ -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)) {
+29
View File
@@ -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