|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\GBProd\ElasticsearchDataProviderBundle\DataProvider; |
|
4
|
|
|
|
|
5
|
|
|
use GBProd\ElasticsearchDataProviderBundle\DataProvider\Registry; |
|
6
|
|
|
use GBProd\ElasticsearchDataProviderBundle\DataProvider\DataProviderInterface; |
|
7
|
|
|
use GBProd\ElasticsearchDataProviderBundle\DataProvider\Handler; |
|
8
|
|
|
use Elasticsearch\Client; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Tests for handler |
|
12
|
|
|
* |
|
13
|
|
|
* @author gbprod <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class HandlerTest extends \PHPUnit_Framework_TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
public function testHandlerRunEveryProviders() |
|
18
|
|
|
{ |
|
19
|
|
|
$client = $this |
|
20
|
|
|
->getMockBuilder(Client::class) |
|
21
|
|
|
->disableOriginalConstructor() |
|
22
|
|
|
->getMock() |
|
23
|
|
|
; |
|
24
|
|
|
|
|
25
|
|
|
$registry = $this->getMock(Registry::class); |
|
26
|
|
|
$registry |
|
27
|
|
|
->expects($this->any()) |
|
28
|
|
|
->method('getProviders') |
|
29
|
|
|
->with('my_index', 'my_type') |
|
30
|
|
|
->willReturn([ |
|
31
|
|
|
$this->createProviderExpectingRun($client, 'my_index', 'my_type'), |
|
32
|
|
|
$this->createProviderExpectingRun($client, 'my_index', 'my_type'), |
|
33
|
|
|
$this->createProviderExpectingRun($client, 'my_index', 'my_type'), |
|
34
|
|
|
]) |
|
35
|
|
|
; |
|
36
|
|
|
|
|
37
|
|
|
$handler = new Handler($registry); |
|
38
|
|
|
|
|
39
|
|
|
$handler->handle($client, 'my_index', 'my_type'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
private function createProviderExpectingRun($client, $index, $type) |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
$provider = $this->getMock(DataProviderInterface::class); |
|
45
|
|
|
|
|
46
|
|
|
$provider |
|
47
|
|
|
->expects($this->once()) |
|
48
|
|
|
->method('run') |
|
49
|
|
|
->with($client, $index, $type) |
|
50
|
|
|
; |
|
51
|
|
|
|
|
52
|
|
|
return $provider; |
|
53
|
|
|
} |
|
54
|
|
|
} |
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
@returnannotation as described here.