Completed
Push — master ( 6fac71...0b5ba2 )
by Thanos
08:43
created

StatsdClientTest::testIncrement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 7
loc 7
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Werkspot\Bundle\StatsdBundle\Tests\Client;
4
5
use Domnikl\Statsd\Connection;
6
use Mockery;
7
use Mockery\MockInterface;
8
use Werkspot\Bundle\StatsdBundle\Client\StatsdClient;
9
10
class StatsdClientTest extends \PHPUnit_Framework_TestCase
11
{
12
    /** @var StatsdClient */
13
    private $statsdClient;
14
15
    /** @var Connection|MockInterface */
16
    private $mockConnection;
17
18
    protected function setUp()
19
    {
20
        $this->mockConnection = Mockery::mock(Connection::class);
21
        $this->statsdClient = new StatsdClient($this->mockConnection, 'test');
22
    }
23
24 View Code Duplication
    public function testIncrement()
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...
25
    {
26
        $mockKey = uniqid();
27
        $this->mockConnection->shouldReceive('send')->once()->with('test.'.$mockKey . ':1|c');
1 ignored issue
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Domnikl\Statsd\Connection.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
28
29
        $this->statsdClient->increment($mockKey);
30
    }
31
32 View Code Duplication
    public function testDecrement()
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...
33
    {
34
        $mockKey = uniqid();
35
        $this->mockConnection->shouldReceive('send')->once()->with('test.'.$mockKey . ':-1|c');
1 ignored issue
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Domnikl\Statsd\Connection.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
36
37
        $this->statsdClient->decrement($mockKey);
38
    }
39
40 View Code Duplication
    public function testCount()
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...
41
    {
42
        $mockKey = uniqid();
43
        $this->mockConnection->shouldReceive('send')->once()->with('test.'.$mockKey . ':1234|c');
1 ignored issue
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Domnikl\Statsd\Connection.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
44
45
        $this->statsdClient->count($mockKey, 1234);
46
    }
47
}
48