TestCommandExecutionCapabilities::executeCommand()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 14
nc 2
nop 2
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace HMLB\UserBundle\Tests\Functional;
6
7
use Exception;
8
use Symfony\Bundle\FrameworkBundle\Console\Application;
9
use Symfony\Component\Console\Input\ArrayInput;
10
use Symfony\Component\HttpKernel\KernelInterface;
11
12
/**
13
 * Trait TestCommandExecutionCapabilities.
14
 *
15
 * @author Hugues Maignol <[email protected]>
16
 */
17
trait TestCommandExecutionCapabilities
18
{
19
    /**
20
     * @param       $command
21
     * @param array $options
22
     *
23
     * @throws Exception
24
     */
25
    protected function executeCommand($command, array $options = [])
26
    {
27
        $args = [
28
            'command' => $command,
29
        ];
30
        $args['--quiet'] = true;
31
        $args = array_merge($args, $options);
32
33
        $property = 'kernel';
34
        if (!property_exists($this, $property) || !$this->$property instanceof KernelInterface) {
35
            throw new Exception(
36
                sprintf(
37
                    'TestCommandExecutionCapabilities can only be used if the test case has a ::%s attribute.',
38
                    $property
39
                )
40
            );
41
        }
42
        $application = new Application($this->$property);
43
        $application->setAutoExit(false);
44
        $application->run(new ArrayInput($args));
45
    }
46
}
47