| @@ 16-83 (lines=68) @@ | ||
| 13 | * |
|
| 14 | * @author gbprod <[email protected]> |
|
| 15 | */ |
|
| 16 | class CreateIndexHandler extends atoum |
|
| 17 | { |
|
| 18 | public function testHandle() |
|
| 19 | { |
|
| 20 | $this |
|
| 21 | ->given($config = ['my' => ['awesome' => 'config']]) |
|
| 22 | ->and($indices = $this->newIndices()) |
|
| 23 | ->and($client = $this->newClient($indices)) |
|
| 24 | ->and($configRepository = $this->newConfigRepository('my_index', $config)) |
|
| 25 | ->and($this->newTestedInstance($configRepository)) |
|
| 26 | ->if($this->testedInstance->handle($client, 'my_index')) |
|
| 27 | ->then |
|
| 28 | ->mock($indices) |
|
| 29 | ->call('create') |
|
| 30 | ->withArguments( |
|
| 31 | [ |
|
| 32 | 'index' => 'my_index', |
|
| 33 | 'body' => $config, |
|
| 34 | ] |
|
| 35 | ) |
|
| 36 | ->once() |
|
| 37 | ; |
|
| 38 | } |
|
| 39 | ||
| 40 | private function newIndices() |
|
| 41 | { |
|
| 42 | $this->mockGenerator->shuntParentClassCalls(); |
|
| 43 | $this->mockGenerator->orphanize('__construct'); |
|
| 44 | ||
| 45 | return new IndicesNamespace(); |
|
| 46 | } |
|
| 47 | ||
| 48 | private function newClient($indices) |
|
| 49 | { |
|
| 50 | $this->mockGenerator->shuntParentClassCalls(); |
|
| 51 | $this->mockGenerator->orphanize('__construct'); |
|
| 52 | ||
| 53 | $client = new Client(); |
|
| 54 | ||
| 55 | $this->calling($client)->indices = function() use ($indices) { |
|
| 56 | return $indices; |
|
| 57 | }; |
|
| 58 | ||
| 59 | return $client; |
|
| 60 | } |
|
| 61 | ||
| 62 | private function newConfigRepository($index, $config) |
|
| 63 | { |
|
| 64 | $this->mockGenerator->shuntParentClassCalls(); |
|
| 65 | $this->mockGenerator->orphanize('__construct'); |
|
| 66 | ||
| 67 | $configRepository = new IndexConfigurationRepository(); |
|
| 68 | ||
| 69 | $this->calling($configRepository)->get = |
|
| 70 | function($indexParam) use ($index, $config) { |
|
| 71 | if ($index == $indexParam) { |
|
| 72 | return $config; |
|
| 73 | } |
|
| 74 | ||
| 75 | return null; |
|
| 76 | } |
|
| 77 | ; |
|
| 78 | ||
| 79 | $this->mockGenerator->unshuntParentClassCalls(); |
|
| 80 | ||
| 81 | return $configRepository; |
|
| 82 | } |
|
| 83 | } |
|
| 84 | ||
| @@ 16-81 (lines=66) @@ | ||
| 13 | * |
|
| 14 | * @author gbprod <[email protected]> |
|
| 15 | */ |
|
| 16 | class DeleteIndexHandler extends atoum |
|
| 17 | { |
|
| 18 | public function testHandle() |
|
| 19 | { |
|
| 20 | $this |
|
| 21 | ->given($config = ['my' => ['awesome' => 'config']]) |
|
| 22 | ->and($indices = $this->newIndices()) |
|
| 23 | ->and($client = $this->newClient($indices)) |
|
| 24 | ->and($configRepository = $this->newConfigRepository('my_index', $config)) |
|
| 25 | ->and($this->newTestedInstance($configRepository)) |
|
| 26 | ->if($this->testedInstance->handle($client, 'my_index')) |
|
| 27 | ->then |
|
| 28 | ->mock($indices) |
|
| 29 | ->call('delete') |
|
| 30 | ->withArguments([ |
|
| 31 | 'index' => 'my_index', |
|
| 32 | ] |
|
| 33 | ) |
|
| 34 | ->once() |
|
| 35 | ; |
|
| 36 | } |
|
| 37 | ||
| 38 | private function newIndices() |
|
| 39 | { |
|
| 40 | $this->mockGenerator->shuntParentClassCalls(); |
|
| 41 | $this->mockGenerator->orphanize('__construct'); |
|
| 42 | ||
| 43 | return new IndicesNamespace(); |
|
| 44 | } |
|
| 45 | ||
| 46 | private function newClient($indices) |
|
| 47 | { |
|
| 48 | $this->mockGenerator->shuntParentClassCalls(); |
|
| 49 | $this->mockGenerator->orphanize('__construct'); |
|
| 50 | ||
| 51 | $client = new Client(); |
|
| 52 | ||
| 53 | $this->calling($client)->indices = function() use ($indices) { |
|
| 54 | return $indices; |
|
| 55 | }; |
|
| 56 | ||
| 57 | return $client; |
|
| 58 | } |
|
| 59 | ||
| 60 | private function newConfigRepository($index, $config) |
|
| 61 | { |
|
| 62 | $this->mockGenerator->shuntParentClassCalls(); |
|
| 63 | $this->mockGenerator->orphanize('__construct'); |
|
| 64 | ||
| 65 | $configRepository = new IndexConfigurationRepository(); |
|
| 66 | ||
| 67 | $this->calling($configRepository)->get = |
|
| 68 | function($indexParam) use ($index, $config) { |
|
| 69 | if ($index == $indexParam) { |
|
| 70 | return $config; |
|
| 71 | } |
|
| 72 | ||
| 73 | return null; |
|
| 74 | } |
|
| 75 | ; |
|
| 76 | ||
| 77 | $this->mockGenerator->unshuntParentClassCalls(); |
|
| 78 | ||
| 79 | return $configRepository; |
|
| 80 | } |
|
| 81 | } |
|
| 82 | ||