Completed
Push — master ( 5018c3...5108e7 )
by GBProd
07:07
created

RegistryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 53.49 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 46
loc 86
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testGetProvidersEmptyIfNoProviders() 0 7 1
A testGetProvidersReturnAllProviders() 0 20 1
A testGetProvidersReturnProvidersForAnIndex() 23 23 1
A testGetProvidersReturnProvidersForAnIndexAndAType() 23 23 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 Tests\GBProd\ElasticsearchDataProviderBundle\DataProvider;
4
5
use GBProd\ElasticsearchDataProviderBundle\DataProvider\Registry;
6
use GBProd\ElasticsearchDataProviderBundle\DataProvider\DataProvider;
7
8
/**
9
 * Tests for DataProvider registry
10
 * 
11
 * @author gbprod <[email protected]>
12
 */
13
class RegistryTest extends \PHPUnit_Framework_TestCase
14
{
15
    private $testedInstance;
16
    
17
    public function setUp()
18
    {
19
        $this->testedInstance = new Registry();    
20
    }
21
    
22
    public function testGetProvidersEmptyIfNoProviders()
23
    {
24
        $this->assertEquals(
25
            [], 
26
            $this->testedInstance->getProviders()
27
        );
28
    }
29
    
30
    public function testGetProvidersReturnAllProviders()
31
    {
32
        $provider1 = $this->getMock(DataProvider::class);
33
        $provider2 = $this->getMock(DataProvider::class);
34
        $provider3 = $this->getMock(DataProvider::class);
35
        
36
        $this->testedInstance
37
            ->addProvider($provider1, 'index', 'type1')
38
            ->addProvider($provider2, 'index', 'type2')
39
            ->addProvider($provider3, 'index2', 'type')
40
        ;
41
        
42
        $providers = $this->testedInstance->getProviders();
43
        
44
        $this->assertCount(3, $providers);
45
        
46
        $this->assertContains($provider1, $providers);
47
        $this->assertContains($provider2, $providers);
48
        $this->assertContains($provider3, $providers);
49
    }
50
    
51 View Code Duplication
    public function testGetProvidersReturnProvidersForAnIndex()
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...
52
    {
53
        $provider1 = $this->getMock(DataProvider::class);
54
        $provider2 = $this->getMock(DataProvider::class);
55
        $provider3 = $this->getMock(DataProvider::class);
56
        $provider4 = $this->getMock(DataProvider::class);
57
        
58
        $this->testedInstance
59
            ->addProvider($provider1, 'index2', 'type')
60
            ->addProvider($provider2, 'index', 'type')
61
            ->addProvider($provider3, 'index2', 'type')
62
            ->addProvider($provider4, 'index', 'type2')
63
        ;
64
        
65
        $providers = $this->testedInstance->getProviders('index');
66
        
67
        $this->assertCount(2, $providers);
68
        
69
        $this->assertNotContains($provider1, $providers);
70
        $this->assertContains($provider2, $providers);
71
        $this->assertNotContains($provider3, $providers);
72
        $this->assertContains($provider4, $providers);
73
    }
74
    
75 View Code Duplication
    public function testGetProvidersReturnProvidersForAnIndexAndAType()
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...
76
    {
77
        $provider1 = $this->getMock(DataProvider::class);
78
        $provider2 = $this->getMock(DataProvider::class);
79
        $provider3 = $this->getMock(DataProvider::class);
80
        $provider4 = $this->getMock(DataProvider::class);
81
        
82
        $this->testedInstance
83
            ->addProvider($provider1, 'index', 'type2')
84
            ->addProvider($provider2, 'index2', 'type2')
85
            ->addProvider($provider3, 'index2', 'type')
86
            ->addProvider($provider4, 'index', 'type')
87
        ;
88
        
89
        $providers = $this->testedInstance->getProviders('index', 'type');
90
        
91
        $this->assertCount(1, $providers);
92
        
93
        $this->assertNotContains($provider1, $providers);
94
        $this->assertNotContains($provider2, $providers);
95
        $this->assertNotContains($provider3, $providers);
96
        $this->assertContains($provider4, $providers);
97
    }
98
}