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

InfluxDbEventListenerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 84.21 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 6
dl 32
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\Events\Listeners;
4
5
use Algatux\InfluxDbBundle\Events\InfluxDbEvent;
6
use Algatux\InfluxDbBundle\Events\Listeners\InfluxDbEventListener;
7
use Algatux\InfluxDbBundle\Model\PointsCollection;
8
use Algatux\InfluxDbBundle\Services\Clients\Contracts\ClientInterface;
9
use Algatux\InfluxDbBundle\Services\Clients\WriterClient;
10
use InfluxDB\Database;
11
use Prophecy\Argument;
12
13
class InfluxDbEventListenerTest extends \PHPUnit_Framework_TestCase
14
{
15
16
    public function test_listening_for_udp_infuxdb_event()
17
    {
18
        $event = new InfluxDbEvent(new PointsCollection(), Database::PRECISION_SECONDS, ClientInterface::UDP_CLIENT);
19
20
        $httpWriter = $this->prophesize(WriterClient::class);
21
        $httpWriter->write(Argument::cetera())
22
            ->shouldNotBeCalled();
23
24
        $udpWriter = $this->prophesize(WriterClient::class);
25
        $udpWriter->write(Argument::type(PointsCollection::class), Database::PRECISION_SECONDS)
26
            ->shouldBeCalledTimes(1)
27
            ->willReturn(true);
28
29
        $listener = new InfluxDbEventListener($httpWriter->reveal(), $udpWriter->reveal());
30
        $listener->onInfluxDbEventDispatched($event);
31
    }
32
33
    public function test_listening_for_http_infuxdb_event()
34
    {
35
        $event = new InfluxDbEvent(new PointsCollection(), Database::PRECISION_SECONDS, ClientInterface::HTTP_CLIENT);
36
37
        $udpWriter = $this->prophesize(WriterClient::class);
38
        $udpWriter->write(Argument::cetera())
39
            ->shouldNotBeCalled();
40
41
        $httpWriter = $this->prophesize(WriterClient::class);
42
        $httpWriter->write(Argument::type(PointsCollection::class), Database::PRECISION_SECONDS)
43
            ->shouldBeCalledTimes(1)
44
            ->willReturn(true);
45
46
        $listener = new InfluxDbEventListener($httpWriter->reveal(), $udpWriter->reveal());
47
        $listener->onInfluxDbEventDispatched($event);
48
    }
49
50
}
51