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

DeleteIndexCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 80
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testDeleleIndexCallsHandler() 0 22 1
A newDeleteIndexHandler() 0 11 1
A newClient() 0 11 1
A createContainer() 0 9 1
A testDeleleDoesnotCallHandlerIfNotForced() 0 20 1
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\DeleteIndexHandler;
10
use mock\Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Tests for CreateIndexCommand
14
 *
15
 * @author gbprod <[email protected]>
16
 */
17
class DeleteIndexCommand extends atoum
18
{
19
    public function testDeleleIndexCallsHandler()
20
    {
21
        $this
22
            ->given($this->newTestedInstance)
23
                ->and($handler = $this->newDeleteIndexHandler())
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
                    '--force'  => true,
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')
38
                        ->once()
39
        ;
40
    }
41
42
    private function newDeleteIndexHandler()
43
    {
44
        $this->mockGenerator->shuntParentClassCalls();
45
        $this->mockGenerator->orphanize('__construct');
46
47
        $handler = new DeleteIndexHandler();
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.delete_index_handler', $handler);
71
        $container->set('m6web_elasticsearch.client.my_client', $client);
72
73
        return $container;
74
    }
75
76
    public function testDeleleDoesnotCallHandlerIfNotForced()
77
    {
78
        $this
79
            ->given($this->newTestedInstance)
80
                ->and($handler = $this->newDeleteIndexHandler())
81
                ->and($client = $this->newClient())
82
                ->and($container = $this->createContainer($client, $handler))
83
                ->and($this->testedInstance->setContainer($container))
84
                ->and($input = new ArrayInput([
85
                    '--client' => 'my_client',
86
                    'index'    => 'my_index',
87
                ]))
88
                ->and($output = new OutputInterface())
89
            ->if($this->testedInstance->run($input, $output))
90
            ->then
91
                ->mock($handler)
92
                    ->call('handle')
93
                        ->never()
94
        ;
95
    }
96
}
97