Files
librenms-librenms/lib/influxdb-php-sdk/tests/unit/ClientFactoryTest.php

136 lines
4.0 KiB
PHP
Raw Normal View History

<?php
namespace InfluxDB;
class ClientFactoryTest extends \PHPUnit_Framework_TestCase
{
2014-09-26 22:06:41 +02:00
/**
* @group factory
*
* @expectedException InvalidArgumentException
*/
public function testEmptyOptions()
{
$client = ClientFactory::create([]);
}
/**
* @group factory
* @expectedException InvalidArgumentException
*/
public function testInvalidAdapter()
{
$client = ClientFactory::create(["adapter" => ["name" => "UdpAdapter"]]);
}
/**
* @group factory
* @group udp
*/
public function testCreateUdpClient()
{
$options = [
"adapter" => [
"name" => "InfluxDB\\Adapter\\UdpAdapter",
],
"options" => [
"host" => "127.0.0.1",
"username" => "user",
"password" => "pass",
],
];
$client = ClientFactory::create($options);
$this->assertInstanceOf("InfluxDB\\Client", $client);
$this->assertInstanceOf("InfluxDB\\Adapter\\UdpAdapter", $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());
}
/**
* @group factory
* @group tcp
* @dataProvider getHttpAdapters
*/
public function testCreateTcpClient($adapter)
{
$options = [
"adapter" => [
"name" => $adapter,
],
"options" => [
"host" => "127.0.0.1",
"username" => "user",
"password" => "pass",
],
];
$client = ClientFactory::create($options);
$this->assertInstanceOf("InfluxDB\\Client", $client);
$this->assertInstanceOf($adapter, $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());
}
2014-09-14 18:04:58 +02:00
/**
* @group factory
* @dataProvider getHttpAdapters
2014-09-14 18:04:58 +02:00
*/
public function testCreateTcpClientWithAllOptions($adapter)
2014-09-14 18:04:58 +02:00
{
$options = [
"adapter" => [
"name" => $adapter,
2014-09-14 18:04:58 +02:00
],
"options" => [
"host" => "127.0.0.1",
"username" => "user",
"password" => "pass",
"retention_policy" => "too_many_data",
"tags" => [
"region" => "eu",
"env" => "prod",
],
2014-09-14 18:04:58 +02:00
],
];
$client = ClientFactory::create($options);
$this->assertInstanceOf("InfluxDB\\Client", $client);
$this->assertInstanceOf($adapter, $client->getAdapter());
2014-09-14 18:04:58 +02:00
$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->assertEquals(["region" => "eu", "env" => "prod"], $client->getAdapter()->getOptions()->getTags());
$this->assertEquals("too_many_data", $client->getAdapter()->getOptions()->getRetentionPolicy());
2014-09-14 18:04:58 +02:00
}
public function getHttpAdapters()
{
return [
["InfluxDB\\Adapter\\GuzzleAdapter"],
];
}
2015-06-23 20:49:44 +02:00
/**
* @expectedException InvalidArgumentException
* @dataProvider getInvalidClasses
2015-06-23 20:49:44 +02:00
*/
public function testInvalidProviderThrowsException($class)
2015-06-23 20:49:44 +02:00
{
$client = ClientFactory::create([
"adapter" => [
"name" => $class,
2015-06-23 20:49:44 +02:00
],
]);
}
public function getInvalidClasses()
{
return [["InvalidClass"],["stdClass"]];
}
}