Completed
Push — master ( 6e4d29...c8305f )
by Alessandro
02:31
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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_listening_for_udp_infuxdb_event() 16 16 1
A test_listening_for_http_infuxdb_event() 16 16 1

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
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 13 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\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 View Code Duplication
    public function test_listening_for_udp_infuxdb_event()
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...
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 View Code Duplication
    public function test_listening_for_http_infuxdb_event()
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...
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