2014-09-13 11:36:17 +02:00
|
|
|
<?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"]]);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-13 11:36:17 +02:00
|
|
|
/**
|
|
|
|
|
* @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
|
2015-03-02 21:37:37 +02:00
|
|
|
* @dataProvider getTcpAdapters
|
2014-09-13 11:36:17 +02:00
|
|
|
*/
|
2015-03-02 21:37:37 +02:00
|
|
|
public function testCreateTcpClient($adapter)
|
2014-09-13 11:36:17 +02:00
|
|
|
{
|
|
|
|
|
$options = [
|
|
|
|
|
"adapter" => [
|
2015-03-02 21:37:37 +02:00
|
|
|
"name" => $adapter,
|
2014-09-13 11:36:17 +02:00
|
|
|
],
|
|
|
|
|
"options" => [
|
|
|
|
|
"host" => "127.0.0.1",
|
|
|
|
|
"username" => "user",
|
|
|
|
|
"password" => "pass",
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$client = ClientFactory::create($options);
|
|
|
|
|
$this->assertInstanceOf("InfluxDB\\Client", $client);
|
|
|
|
|
|
2015-03-02 21:37:37 +02:00
|
|
|
$this->assertInstanceOf($adapter, $client->getAdapter());
|
2014-09-13 11:36:17 +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());
|
|
|
|
|
}
|
2014-09-14 18:04:58 +02:00
|
|
|
|
2015-03-02 21:37:37 +02:00
|
|
|
public function getTcpAdapters()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
["InfluxDB\\Adapter\\GuzzleAdapter"],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-14 18:04:58 +02:00
|
|
|
/**
|
|
|
|
|
* @group factory
|
2015-03-02 21:37:37 +02:00
|
|
|
* @dataProvider getTcpAdapters
|
2014-09-14 18:04:58 +02:00
|
|
|
*/
|
2015-03-02 21:37:37 +02:00
|
|
|
public function testCreateTcpClientWithFilter($adapter)
|
2014-09-14 18:04:58 +02:00
|
|
|
{
|
|
|
|
|
$options = [
|
|
|
|
|
"adapter" => [
|
2015-03-02 21:37:37 +02:00
|
|
|
"name" => $adapter,
|
2014-09-14 18:04:58 +02:00
|
|
|
],
|
|
|
|
|
"options" => [
|
|
|
|
|
"host" => "127.0.0.1",
|
|
|
|
|
"username" => "user",
|
|
|
|
|
"password" => "pass",
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$client = ClientFactory::create($options);
|
|
|
|
|
$this->assertInstanceOf("InfluxDB\\Client", $client);
|
|
|
|
|
|
2015-03-02 21:37:37 +02:00
|
|
|
$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());
|
|
|
|
|
}
|
2014-09-13 11:36:17 +02:00
|
|
|
}
|