TestCommandExecutionCapabilities   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A executeCommand() 0 21 3
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