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

HandlerTest::testHandlerRunEveryProviders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 23
rs 9.0856
cc 1
eloc 14
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
use GBProd\ElasticsearchDataProviderBundle\DataProvider\DataProviderInterface;
8
use GBProd\ElasticsearchDataProviderBundle\DataProvider\Handler;
9
use Elasticsearch\Client;
10
11
/**
12
 * Tests for handler
13
 * 
14
 * @author gbprod <[email protected]>
15
 */
16
class HandlerTest extends \PHPUnit_Framework_TestCase
17
{
18
    private $client;
19
    private $registry;
20
    
21
    public function setUp()
22
    {
23
        $this->client = $this
24
            ->getMockBuilder(Client::class)
25
            ->disableOriginalConstructor()
26
            ->getMock()
27
        ;
28
        
29
        $this->registry = new Registry();
30
    }
31
    
32
    public function testHandlerRunEveryProviders()
33
    {
34
        $this->registry
35
            ->add(
36
                new RegistryEntry(
37
                    $this->createProviderExpectingRun('my_index', 'my_type'),
38
                    'my_index', 
39
                    'my_type'
40
                )
41
            )
42
            ->add(
43
                new RegistryEntry(
44
                    $this->createProviderExpectingRun('my_index', 'my_type_2'),
45
                    'my_index', 
46
                    'my_type_2'
47
                )
48
            )
49
        ;
50
        
51
        $handler = new Handler($this->registry);
52
        
53
        $handler->handle($this->client, 'my_index', null);
54
    }
55
    
56
    private function createProviderExpectingRun($index, $type)
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...
57
    {
58
        $provider = $this->getMock(DataProviderInterface::class);
59
        
60
        $provider
61
            ->expects($this->once())
62
            ->method('run')
63
            ->with($this->client, $index, $type)
64
        ;
65
        
66
        return $provider;    
67
    }
68
}