Completed
Push — master ( 4ef090...a7a684 )
by GBProd
02:22
created

testDeleleDoesnotCallHandlerIfNotForced()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 15

Duplication

Lines 19
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 19
loc 19
rs 9.4285
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
namespace GBProd\Tests\Units\ElasticsearchExtraBundle\Command;
4
5
use atoum;
6
use mock\GBProd\ElasticsearchExtraBundle\Handler\DeleteIndexHandler;
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 CreateIndexCommand
13
 * 
14
 * @author gbprod <[email protected]>
15
 */
16
class DeleteIndexCommand extends atoum
17
{
18
    public function testDeleleIndexCallsHandler()
19
    {
20
        $this
21
            ->given($this->newTestedInstance)
22
                ->and($handler = $this->newDeleteIndexHandler())
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
                    '--force'   => true,
29
                ]))
30
                ->and($output = new OutputInterface())
31
            ->if($this->testedInstance->run($input, $output))
32
            ->then
33
                ->mock($handler)
34
                    ->call('handle')
35
                        ->withArguments('my_client', 'my_index')
36
                        ->once()
37
        ;
38
    }
39
    
40
    private function newDeleteIndexHandler()
41
    {
42
        $this->mockGenerator->shuntParentClassCalls();
43
        $this->mockGenerator->orphanize('__construct');
44
        
45
        $handler = new DeleteIndexHandler();
46
        
47
        $this->mockGenerator->unshuntParentClassCalls();
48
        
49
        return $handler;
50
    }
51
    
52
    public function createContainer($handler)
53
    {
54
        $container = new Container();
55
        $container->set(
56
            'gbprod.elasticsearch_extra.delete_index_handler',
57
            $handler 
58
        );
59
        
60
        return $container;
61
    }
62
    
63 View Code Duplication
    public function testDeleleDoesnotCallHandlerIfNotForced()
0 ignored issues
show
Duplication introduced by
This method 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...
64
    {
65
        $this
66
            ->given($this->newTestedInstance)
67
                ->and($handler = $this->newDeleteIndexHandler())
68
                ->and($container = $this->createContainer($handler))
69
                ->and($this->testedInstance->setContainer($container))
70
                ->and($input = new ArrayInput([
71
                    'client_id' => 'my_client', 
72
                    'index_id'  => 'my_index',
73
                ]))
74
                ->and($output = new OutputInterface())
75
            ->if($this->testedInstance->run($input, $output))
76
            ->then
77
                ->mock($handler)
78
                    ->call('handle')
79
                        ->never()
80
        ;
81
    }
82
}