Completed
Push — master ( fce8e6...b0acfe )
by GBProd
02:14
created

RegistryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 4
c 4
b 1
f 0
lcom 1
cbo 3
dl 0
loc 58
rs 10
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
    /**
52
     * @return RegistryEntry
53
     */
54
    private function newRegistryMatching($matching)
55
    {
56
        $entry = $this
57
            ->getMockBuilder(RegistryEntry::class)
58
            ->disableOriginalConstructor()
59
            ->getMock()
60
        ;
61
62
        $entry
63
            ->expects($this->any())
64
            ->method('match')
65
            ->willReturn($matching)
66
        ;
67
68
        return $entry;
69
    }
70
}