diff --git a/src/InfluxDB/ClientFactory.php b/src/InfluxDB/ClientFactory.php index 035b7f53d..cd94929f6 100644 --- a/src/InfluxDB/ClientFactory.php +++ b/src/InfluxDB/ClientFactory.php @@ -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)) { diff --git a/tests/InfluxDB/ClientFactoryTest.php b/tests/InfluxDB/ClientFactoryTest.php index 058de134b..ddaf37898 100644 --- a/tests/InfluxDB/ClientFactoryTest.php +++ b/tests/InfluxDB/ClientFactoryTest.php @@ -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