1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
namespace Algatux\InfluxDbBundle\unit\Services\Clients; |
4
|
|
|
|
5
|
|
|
use Algatux\InfluxDbBundle\Model\PointsCollection; |
6
|
|
|
use Algatux\InfluxDbBundle\Services\Clients\Contracts\ClientInterface; |
7
|
|
|
use Algatux\InfluxDbBundle\Services\Clients\Contracts\WriterInterface; |
8
|
|
|
use Algatux\InfluxDbBundle\Services\Clients\InfluxDbClientFactory; |
9
|
|
|
use Algatux\InfluxDbBundle\Services\Clients\WriterClient; |
10
|
|
|
use InfluxDB\Client; |
11
|
|
|
use InfluxDB\Database; |
12
|
|
|
use Prophecy\Argument; |
13
|
|
|
|
14
|
|
|
class WriterClientTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
public function test_http_client_construction() |
18
|
|
|
{ |
19
|
|
|
$factory = $this->prophesize(InfluxDbClientFactory::class); |
20
|
|
|
$factory->buildHttpClient()->shouldBeCalledTimes(1); |
21
|
|
|
|
22
|
|
|
$writer = new WriterClient($factory->reveal(), ClientInterface::HTTP_CLIENT); |
23
|
|
|
|
24
|
|
|
$this->assertInstanceOf(WriterInterface::class, $writer); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function test_udp_client_construction() |
28
|
|
|
{ |
29
|
|
|
$factory = $this->prophesize(InfluxDbClientFactory::class); |
30
|
|
|
$factory->buildUdpClient()->shouldBeCalledTimes(1); |
31
|
|
|
|
32
|
|
|
$writer = new WriterClient($factory->reveal(), ClientInterface::UDP_CLIENT); |
33
|
|
|
|
34
|
|
|
$this->assertInstanceOf(WriterInterface::class, $writer); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function test_write() |
38
|
|
|
{ |
39
|
|
|
$idbDatabase = $this->prophesize(Database::class); |
40
|
|
|
$idbDatabase->writePoints(Argument::type('array'),Argument::type('string')) |
41
|
|
|
->shouldBeCalledTimes(1) |
42
|
|
|
->willReturn(true); |
43
|
|
|
|
44
|
|
|
$factory = $this->prophesize(InfluxDbClientFactory::class); |
45
|
|
|
$factory->buildHttpClient()->shouldBeCalledTimes(1)->willReturn($idbDatabase->reveal()); |
46
|
|
|
|
47
|
|
|
$writer = new WriterClient($factory->reveal(), ClientInterface::HTTP_CLIENT); |
48
|
|
|
$writer->write(new PointsCollection(),'test'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|