Completed
Push — master ( a86091...f009d3 )
by GBProd
02:31
created

PutIndexMappingsCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateIndexCallsHandler() 20 20 1
A newPutIndexMappingsHandler() 11 11 1
A createContainer() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace GBProd\Tests\Units\ElasticsearchExtraBundle\Command;
4
5
use atoum;
6
use mock\GBProd\ElasticsearchExtraBundle\Handler\PutIndexMappingsHandler;
7
use Symfony\Component\Console\Input\ArrayInput;
8
use mock\Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\DependencyInjection\Container;
10
11
/**
12
 * Tests for PutIndexMappingsCommand
13
 * 
14
 * @author gbprod <[email protected]>
15
 */
16 View Code Duplication
class PutIndexMappingsCommand 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...
17
{
18
    public function testCreateIndexCallsHandler()
19
    {
20
        $this
21
            ->given($this->newTestedInstance)
22
                ->and($handler = $this->newPutIndexMappingsHandler())
23
                ->and($container = $this->createContainer($handler))
24
                ->and($this->testedInstance->setContainer($container))
25
                ->and($input = new ArrayInput([
26
                    'client_id' => 'my_client', 
27
                    'index_id'  => 'my_index',
28
                ]))
29
                ->and($output = new OutputInterface())
30
            ->if($this->testedInstance->run($input, $output))
31
            ->then
32
                ->mock($handler)
33
                    ->call('handle')
34
                        ->withArguments('my_client', 'my_index')
35
                        ->once()
36
        ;
37
    }
38
    
39
    private function newPutIndexMappingsHandler()
40
    {
41
        $this->mockGenerator->shuntParentClassCalls();
42
        $this->mockGenerator->orphanize('__construct');
43
        
44
        $handler = new PutIndexMappingsHandler();
45
        
46
        $this->mockGenerator->unshuntParentClassCalls();
47
        
48
        return $handler;
49
    }
50
    
51
    public function createContainer($handler)
52
    {
53
        $container = new Container();
54
        $container->set(
55
            'gbprod.elasticsearch_extra.put_index_mappings_handler',
56
            $handler 
57
        );
58
        
59
        return $container;
60
    }
61
}