Completed
Push — master ( 6e4d29...c8305f )
by Alessandro
02:31
created

WriterClientTest::test_http_client_construction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 14 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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 View Code Duplication
    public function test_http_client_construction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
    public function test_udp_client_construction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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