Completed
Push — master ( ebe931...c89697 )
by GBProd
02:12
created

RegistryTest::testGetProvidersReturnProvidersForAnIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 16

Duplication

Lines 23
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
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\RegistryEntry;
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->get()
27
        );
28
    }
29
    
30
    public function testGetReturnMatchingEntries()
31
    {
32
        $entry1 = $this->newRegistryMatching(true);
33
        $entry2 = $this->newRegistryMatching(false);
34
        $entry3 = $this->newRegistryMatching(true);
35
        
36
        $this->testedInstance
37
            ->add($entry1)
38
            ->add($entry2)
39
            ->add($entry3)
40
        ;
41
        
42
        $entries = $this->testedInstance->get();
43
        
44
        $this->assertCount(2, $entries);
45
        
46
        $this->assertContains($entry1, $entries);
47
        $this->assertNotContains($entry2, $entries);
48
        $this->assertContains($entry3, $entries);
49
    }
50
    
51
    private function newRegistryMatching($matching)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
52
    {
53
        $entry = $this
54
            ->getMockBuilder(RegistryEntry::class)
55
            ->disableOriginalConstructor()
56
            ->getMock()
57
        ;
58
    
59
        $entry
60
            ->expects($this->any())
61
            ->method('match')
62
            ->willReturn($matching)
63
        ;
64
        
65
        return $entry;
66
    }
67
}