| 1 | <?php |
||
| 17 | class HandlerTest extends \PHPUnit_Framework_TestCase |
||
| 18 | { |
||
| 19 | private $client; |
||
| 20 | private $registry; |
||
| 21 | private $dispatcher; |
||
| 22 | |||
| 23 | public function setUp() |
||
| 24 | { |
||
| 25 | $this->client = $this |
||
| 26 | ->getMockBuilder(Client::class) |
||
| 27 | ->disableOriginalConstructor() |
||
| 28 | ->getMock() |
||
| 29 | ; |
||
| 30 | |||
| 31 | $this->registry = new Registry(); |
||
| 32 | $this->dispatcher = $this->getMock(EventDispatcherInterface::class); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function testHandlerRunEveryProviders() |
||
| 36 | { |
||
| 37 | $this->registry |
||
| 38 | ->add( |
||
| 39 | new RegistryEntry( |
||
| 40 | $this->createProviderExpectingRun('my_index', 'my_type'), |
||
| 41 | 'my_index', |
||
| 42 | 'my_type' |
||
| 43 | ) |
||
| 44 | ) |
||
| 45 | ->add( |
||
| 46 | new RegistryEntry( |
||
| 47 | $this->createProviderExpectingRun('my_index', 'my_type_2'), |
||
| 48 | 'my_index', |
||
| 49 | 'my_type_2' |
||
| 50 | ) |
||
| 51 | ) |
||
| 52 | ; |
||
| 53 | |||
| 54 | $handler = new Handler($this->registry, $this->dispatcher); |
||
| 55 | |||
| 56 | $handler->handle($this->client, 'my_index', null); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return DataProvider |
||
| 61 | */ |
||
| 62 | private function createProviderExpectingRun($index, $type) |
||
| 63 | { |
||
| 64 | $provider = $this->getMock(DataProvider::class); |
||
| 65 | |||
| 66 | $provider |
||
| 67 | ->expects($this->once()) |
||
| 68 | ->method('run') |
||
| 69 | ->with($this->client, $index, $type, $this->dispatcher) |
||
| 70 | ; |
||
| 71 | |||
| 72 | return $provider; |
||
| 73 | } |
||
| 74 | } |
||
| 75 |