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

newPutIndexMappingsHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
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\PutIndexMappingsHandler;
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 PutIndexMappingsCommand
14
 *
15
 * @author gbprod <[email protected]>
16
 */
17
class PutIndexMappingsCommand extends atoum
18
{
19
    public function testCreateIndexCallsHandler()
20
    {
21
        $this
22
            ->given($this->newTestedInstance)
23
                ->and($handler = $this->newPutIndexMappingsHandler())
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
                    'type'     => 'my_type',
31
                ]))
32
                ->and($output = new OutputInterface())
33
            ->if($this->testedInstance->run($input, $output))
34
            ->then
35
                ->mock($handler)
36
                    ->call('handle')
37
                        ->withArguments($client, 'my_index', 'my_type')
38
                        ->once()
39
        ;
40
    }
41
42
    private function newPutIndexMappingsHandler()
43
    {
44
        $this->mockGenerator->shuntParentClassCalls();
45
        $this->mockGenerator->orphanize('__construct');
46
47
        $handler = new PutIndexMappingsHandler();
48
49
        $this->mockGenerator->unshuntParentClassCalls();
50
51
        return $handler;
52
    }
53
54
    private function newClient()
55
    {
56
        $this->mockGenerator->shuntParentClassCalls();
57
        $this->mockGenerator->orphanize('__construct');
58
59
        $client = new Client();
60
61
        $this->mockGenerator->unshuntParentClassCalls();
62
63
        return $client;
64
    }
65
66
    public function createContainer($client, $handler)
67
    {
68
        $container = new Container();
69
70
        $container->set('gbprod.elasticsearch_extra.put_index_mappings_handler', $handler);
71
        $container->set('m6web_elasticsearch.client.my_client', $client);
72
73
        return $container;
74
    }
75
}
76