Completed
Push — master ( d72a06...ba0ad0 )
by GBProd
04:38
created

PutIndexSettingsCommand::newClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace GBProd\Tests\Units\ElasticsearchExtraBundle\Command;
4
5
use atoum;
6
use mock\Elasticsearch\Client;
7
use mock\GBProd\ElasticsearchExtraBundle\Handler\PutIndexSettingsHandler;
8
use mock\Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Input\ArrayInput;
10
use Symfony\Component\DependencyInjection\Container;
11
12
/**
13
 * Tests for PutIndexSettingsCommandœ
14
 *
15
 * @author gbprod <[email protected]>
16
 */
17 View Code Duplication
class PutIndexSettingsCommand extends atoum
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
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