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

testGetProvidersReturnProvidersForAnIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 16

Duplication

Lines 23
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 23
loc 23
rs 9.0856
cc 1
eloc 16
nc 1
nop 0
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
}