NatsDataCollectorTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 94
Duplicated Lines 62.77 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 3
dl 59
loc 94
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_collectIsCalled__returnDataWithCommandsArrayKey() 0 10 1
A test_callGetCommandCount_twoCommands_returnTwo() 17 17 1
A test_callGetErrorCommandsCount_aLoggerWithAnError_returnOne() 21 21 1
A test_getTimeIsCalled_oneCommandInLogger_returnTime() 21 21 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
2
/*
3
 * This file is part of the NatsBundle package.
4
 *
5
 * (c) Issel Guberna <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Octante\NatsBundle\Tests\Unit\DataCollector;
12
13
use Octante\NatsBundle\DataCollector\NatsDataCollector;
14
15
class NatsDataCollectorTest extends \PHPUnit_Framework_TestCase
16
{
17
    /**
18
     * when: collectIsCalled
19
     * should: returnDataWithCommandsArrayKey
20
     */
21
    public function test_collectIsCalled__returnDataWithCommandsArrayKey()
22
    {
23
        $natsLoggerMock = $this->getMock('Octante\NatsBundle\Logger\NatsLogger');
24
        $requestMock = $this->getMock('Symfony\Component\HttpFoundation\Request');
25
        $responseMock = $this->getMock('Symfony\Component\HttpFoundation\Response');
26
27
        $sut = new NatsDataCollector($natsLoggerMock);
28
        $sut->collect($requestMock, $responseMock);
29
        $this->assertNull($sut->getCommands());
30
    }
31
32
    /**
33
     * when: callGetCommandCount
34
     * with: twoCommands
35
     * should: returnTwo
36
     */
37 View Code Duplication
    public function test_callGetCommandCount_twoCommands_returnTwo()
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...
38
    {
39
        $natsLoggerMock = $this->getMockBuilder('Octante\NatsBundle\Logger\NatsLogger')
40
            ->disableOriginalConstructor()
41
            ->getMock();
42
43
        $natsLoggerMock->expects($this->once())
44
            ->method('getCommands')
45
            ->willReturn(array(1,2));
46
47
        $requestMock = $this->getMock('Symfony\Component\HttpFoundation\Request');
48
        $responseMock = $this->getMock('Symfony\Component\HttpFoundation\Response');
49
50
        $sut = new NatsDataCollector($natsLoggerMock);
51
        $sut->collect($requestMock, $responseMock);
52
        $this->assertEquals(2, $sut->getCommandCount());
53
    }
54
55
    /**
56
     * when: callGetErrorCommandsCount
57
     * with: aLoggerWithAnError
58
     * should: returnOne
59
     */
60 View Code Duplication
    public function test_callGetErrorCommandsCount_aLoggerWithAnError_returnOne()
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...
61
    {
62
        $natsLoggerMock = $this->getMockBuilder('Octante\NatsBundle\Logger\NatsLogger')
63
            ->disableOriginalConstructor()
64
            ->getMock();
65
66
        $natsLoggerMock->expects($this->once())
67
            ->method('getCommands')
68
            ->willReturn(
69
                array(
70
                    'commands' => array('error' => null)
71
                )
72
            );
73
74
        $requestMock = $this->getMock('Symfony\Component\HttpFoundation\Request');
75
        $responseMock = $this->getMock('Symfony\Component\HttpFoundation\Response');
76
77
        $sut = new NatsDataCollector($natsLoggerMock);
78
        $sut->collect($requestMock, $responseMock);
79
        $this->assertEquals(1, $sut->getErrorCommandsCount());
80
    }
81
82
    /**
83
     * when: getTimeIsCalled
84
     * with: oneCommandInLogger
85
     * should: returnTime
86
     */
87 View Code Duplication
    public function test_getTimeIsCalled_oneCommandInLogger_returnTime()
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...
88
    {
89
        $natsLoggerMock = $this->getMockBuilder('Octante\NatsBundle\Logger\NatsLogger')
90
            ->disableOriginalConstructor()
91
            ->getMock();
92
93
        $natsLoggerMock->expects($this->once())
94
            ->method('getCommands')
95
            ->willReturn(
96
                array(
97
                    'commands' => array('executionMS' => 1000)
98
                )
99
            );
100
101
        $requestMock = $this->getMock('Symfony\Component\HttpFoundation\Request');
102
        $responseMock = $this->getMock('Symfony\Component\HttpFoundation\Response');
103
104
        $sut = new NatsDataCollector($natsLoggerMock);
105
        $sut->collect($requestMock, $responseMock);
106
        $this->assertEquals(1000, $sut->getTime());
107
    }
108
}
109