Completed
Push — master ( b587fb...d05392 )
by David
20:34
created

CollectorTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 64.1 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 50
loc 78
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testCollectClientNames() 0 10 1
A testActivateStack() 13 13 1
A testDeactivateStack() 11 11 1
A testDeactivateStackSetParentAsActiveStack() 13 13 1
A testAddStack() 0 10 1
A testResetAction() 13 13 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
namespace Http\HttplugBundle\Tests\Unit\Collector;
4
5
use Http\HttplugBundle\Collector\Collector;
6
use Http\HttplugBundle\Collector\Stack;
7
use PHPUnit\Framework\TestCase;
8
9
class CollectorTest extends TestCase
10
{
11
    public function testCollectClientNames()
12
    {
13
        $collector = new Collector();
14
15
        $collector->addStack(new Stack('default', 'GET / HTTP/1.1'));
16
        $collector->addStack(new Stack('acme', 'GET / HTTP/1.1'));
17
        $collector->addStack(new Stack('acme', 'GET / HTTP/1.1'));
18
19
        $this->assertEquals(['default', 'acme'], $collector->getClients());
20
    }
21
22 View Code Duplication
    public function testActivateStack()
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...
23
    {
24
        $parent = new Stack('acme', 'GET / HTTP/1.1');
25
        $stack = new Stack('acme', 'GET / HTTP/1.1');
26
27
        $collector = new Collector();
28
29
        $collector->activateStack($parent);
30
        $collector->activateStack($stack);
31
32
        $this->assertEquals($parent, $stack->getParent());
33
        $this->assertEquals($stack, $collector->getActiveStack());
34
    }
35
36 View Code Duplication
    public function testDeactivateStack()
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...
37
    {
38
        $stack = new Stack('acme', 'GET / HTTP/1.1');
39
        $collector = new Collector();
40
41
        $collector->activateStack($stack);
42
        $this->assertNotNull($collector->getActiveStack());
43
44
        $collector->deactivateStack($stack);
45
        $this->assertNull($collector->getActiveStack());
46
    }
47
48 View Code Duplication
    public function testDeactivateStackSetParentAsActiveStack()
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...
49
    {
50
        $parent = new Stack('acme', 'GET / HTTP/1.1');
51
        $stack = new Stack('acme', 'GET / HTTP/1.1');
52
53
        $collector = new Collector();
54
55
        $collector->activateStack($parent);
56
        $collector->activateStack($stack);
57
        $collector->deactivateStack($stack);
58
59
        $this->assertEquals($parent, $collector->getActiveStack());
60
    }
61
62
    public function testAddStack()
63
    {
64
        $stack = new Stack('acme', 'GET / HTTP/1.1');
65
        $collector = new Collector();
66
67
        $collector->addStack($stack);
68
69
        $this->assertEquals(['acme'], $collector->getClients());
70
        $this->assertEquals([$stack], $collector->getClientRootStacks('acme'));
71
    }
72
73 View Code Duplication
    public function testResetAction()
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...
74
    {
75
        $stack = new Stack('acme', 'GET / HTTP/1.1');
76
77
        $collector = new Collector();
78
        $collector->addStack($stack);
79
        $collector->activateStack($stack);
80
81
        $collector->reset();
82
83
        $this->assertNull($collector->getActiveStack());
84
        $this->assertEmpty($collector->getStacks());
85
    }
86
}
87