Completed
Push — master ( cb575d...8e212c )
by Alessandro
02:01
created

WriterClientTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 47.37 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 5
dl 18
loc 38
rs 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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