| @@ 17-74 (lines=58) @@ | ||
| 14 | * |
|
| 15 | * @author gbprod <[email protected]> |
|
| 16 | */ |
|
| 17 | class CreateIndexCommand extends atoum |
|
| 18 | { |
|
| 19 | public function testCreateIndexCallsHandler() |
|
| 20 | { |
|
| 21 | $this |
|
| 22 | ->given($this->newTestedInstance) |
|
| 23 | ->and($handler = $this->newCreateIndexHandler()) |
|
| 24 | ->and($client = $this->newClient()) |
|
| 25 | ->and($container = $this->createContainer($client, $handler)) |
|
| 26 | ->and($this->testedInstance->setContainer($container)) |
|
| 27 | ->and($input = new ArrayInput([ |
|
| 28 | 'index' => 'my_index', |
|
| 29 | '--client' => 'my_client', |
|
| 30 | ])) |
|
| 31 | ->and($output = new OutputInterface()) |
|
| 32 | ->if($this->testedInstance->run($input, $output)) |
|
| 33 | ->then |
|
| 34 | ->mock($handler) |
|
| 35 | ->call('handle') |
|
| 36 | ->withArguments($client, 'my_index') |
|
| 37 | ->once() |
|
| 38 | ; |
|
| 39 | } |
|
| 40 | ||
| 41 | private function newCreateIndexHandler() |
|
| 42 | { |
|
| 43 | $this->mockGenerator->shuntParentClassCalls(); |
|
| 44 | $this->mockGenerator->orphanize('__construct'); |
|
| 45 | ||
| 46 | $handler = new CreateIndexHandler(); |
|
| 47 | ||
| 48 | $this->mockGenerator->unshuntParentClassCalls(); |
|
| 49 | ||
| 50 | return $handler; |
|
| 51 | } |
|
| 52 | ||
| 53 | private function newClient() |
|
| 54 | { |
|
| 55 | $this->mockGenerator->shuntParentClassCalls(); |
|
| 56 | $this->mockGenerator->orphanize('__construct'); |
|
| 57 | ||
| 58 | $client = new Client(); |
|
| 59 | ||
| 60 | $this->mockGenerator->unshuntParentClassCalls(); |
|
| 61 | ||
| 62 | return $client; |
|
| 63 | } |
|
| 64 | ||
| 65 | public function createContainer($client, $handler) |
|
| 66 | { |
|
| 67 | $container = new Container(); |
|
| 68 | ||
| 69 | $container->set('gbprod.elasticsearch_extra.create_index_handler', $handler); |
|
| 70 | $container->set('m6web_elasticsearch.client.my_client', $client); |
|
| 71 | ||
| 72 | return $container; |
|
| 73 | } |
|
| 74 | } |
|
| 75 | ||
| @@ 17-74 (lines=58) @@ | ||
| 14 | * |
|
| 15 | * @author gbprod <[email protected]> |
|
| 16 | */ |
|
| 17 | class PutIndexSettingsCommand extends atoum |
|
| 18 | { |
|
| 19 | public function testCreateIndexCallsHandler() |
|
| 20 | { |
|
| 21 | $this |
|
| 22 | ->given($this->newTestedInstance) |
|
| 23 | ->and($handler = $this->newPutIndexSettingsHandler()) |
|
| 24 | ->and($client = $this->newClient()) |
|
| 25 | ->and($container = $this->createContainer($client, $handler)) |
|
| 26 | ->and($this->testedInstance->setContainer($container)) |
|
| 27 | ->and($input = new ArrayInput([ |
|
| 28 | '--client' => 'my_client', |
|
| 29 | 'index' => 'my_index', |
|
| 30 | ])) |
|
| 31 | ->and($output = new OutputInterface()) |
|
| 32 | ->if($this->testedInstance->run($input, $output)) |
|
| 33 | ->then |
|
| 34 | ->mock($handler) |
|
| 35 | ->call('handle') |
|
| 36 | ->withArguments($client, 'my_index') |
|
| 37 | ->once() |
|
| 38 | ; |
|
| 39 | } |
|
| 40 | ||
| 41 | private function newPutIndexSettingsHandler() |
|
| 42 | { |
|
| 43 | $this->mockGenerator->shuntParentClassCalls(); |
|
| 44 | $this->mockGenerator->orphanize('__construct'); |
|
| 45 | ||
| 46 | $handler = new PutIndexSettingsHandler(); |
|
| 47 | ||
| 48 | $this->mockGenerator->unshuntParentClassCalls(); |
|
| 49 | ||
| 50 | return $handler; |
|
| 51 | } |
|
| 52 | ||
| 53 | private function newClient() |
|
| 54 | { |
|
| 55 | $this->mockGenerator->shuntParentClassCalls(); |
|
| 56 | $this->mockGenerator->orphanize('__construct'); |
|
| 57 | ||
| 58 | $client = new Client(); |
|
| 59 | ||
| 60 | $this->mockGenerator->unshuntParentClassCalls(); |
|
| 61 | ||
| 62 | return $client; |
|
| 63 | } |
|
| 64 | ||
| 65 | public function createContainer($client, $handler) |
|
| 66 | { |
|
| 67 | $container = new Container(); |
|
| 68 | ||
| 69 | $container->set('gbprod.elasticsearch_extra.put_index_settings_handler', $handler); |
|
| 70 | $container->set('m6web_elasticsearch.client.my_client', $client); |
|
| 71 | ||
| 72 | return $container; |
|
| 73 | } |
|
| 74 | } |
|
| 75 | ||