Completed
Push — master ( 5f95d7...c6e312 )
by GBProd
02:45
created

ProvideCommandTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 25 1
A testExecute() 0 14 1
1
<?php
2
3
namespace Tests\GBProd\ElasticsearchDataProviderBundle\Command;
4
5
use GBProd\ElasticsearchDataProviderBundle\Command\ProvideCommand;
6
use Symfony\Component\Console\Application;
7
use Symfony\Component\Console\Tester\CommandTester;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
use GBProd\ElasticsearchDataProviderBundle\DataProvider\Handler;
10
11
/**
12
 * Tests for ProvideCommand
13
 * 
14
 * @author gbprod <[email protected]>
15
 */
16
class ProvideCommandTest extends \PHPUnit_Framework_TestCase
17
{
18
    private $commandTester;
19
    private $handler;
20
    
21
    public function setUp()
22
    {
23
        $application = new Application();
24
        $application->add(new ProvideCommand());
25
26
        $command = $application->find('elasticsearch:provide');
27
        $this->commandTester = new CommandTester($command);
28
        
29
        $this->handler = $this
30
            ->getMockBuilder(Handler::class)
31
            ->disableOriginalConstructor()
32
            ->getMock()
33
        ;
34
        
35
        $container = $this->getMock(ContainerInterface::class);
36
        
37
        $container
38
            ->expects($this->once())
39
            ->method('get')
40
            ->with('gbprod.elasticsearch_dataprovider.handler')
41
            ->willReturn($this->handler)
42
        ;
43
        
44
        $command->setContainer($container);
45
    }    
46
    public function testExecute()
47
    {
48
        $this->handler
49
            ->expects($this->once())
50
            ->method('handle')
51
            ->with('my_index', 'my_type')
52
        ;
53
        
54
        $this->commandTester->execute([
55
            'command' => 'elasticsearch:provide',
56
            'index'   => 'my_index',
57
            'type'    => 'my_type',
58
        ]);
59
    }
60
}