1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GBProd\Tests\Units\ElasticsearchExtraBundle\Command; |
4
|
|
|
|
5
|
|
|
use mock\Elasticsearch\Client; |
6
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
7
|
|
|
use Symfony\Component\DependencyInjection\Container; |
8
|
|
|
use atoum; |
9
|
|
|
use mock\GBProd\ElasticsearchExtraBundle\Handler\CreateIndexHandler; |
10
|
|
|
use mock\Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Tests for CreateIndexCommand |
14
|
|
|
* |
15
|
|
|
* @author gbprod <[email protected]> |
16
|
|
|
*/ |
17
|
|
View Code Duplication |
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
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.