CommandTestCase::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Sleepness\UberTranslationBundle\Tests\Command;
4
5
use Symfony\Component\Console\Tester\CommandTester;
6
use Symfony\Bundle\FrameworkBundle\Console\Application;
7
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
8
9
/**
10
 * Base command test case class for store base logic needed to run tests for command line tools
11
 *
12
 * @author Viktor Novikov <[email protected]>
13
 */
14
abstract class CommandTestCase extends KernelTestCase
15
{
16
    /**
17
     * @var \Symfony\Component\Console\Tester\CommandTester
18
     */
19
    protected $commandTester;
20
21
    /**
22
     * Get instance of console command
23
     *
24
     * @return mixed
25
     */
26
    abstract protected function getCommandInstance();
27
28
    /**
29
     * Get command text
30
     *
31
     * @return mixed
32
     */
33
    abstract protected function getCommand();
34
35
    /**
36
     * Return booted kernel
37
     *
38
     * @return \Symfony\Component\HttpKernel\KernelInterface
39
     */
40
    protected function getKernel()
41
    {
42
        $kernel = $this->createKernel();
43
        $kernel->boot();
44
45
        return $kernel;
46
    }
47
48
    /**
49
     * Boot command before run tests
50
     */
51
    protected function setUp()
52
    {
53
        $application = new Application($this->getKernel());
54
        $application->add($this->getCommandInstance());
55
        $command = $application->find($this->getCommand());
56
        $this->commandTester = new CommandTester($command);
57
    }
58
} 
59