TestCase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getApplication() 0 3 1
A setUp() 0 3 1
A getCommandTester() 0 10 2
1
<?php
2
3
namespace GuillermoandraeTest\Commands;
4
5
use RuntimeException;
6
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
7
use Symfony\Component\Console\Application;
8
use Symfony\Component\Console\Tester\CommandTester;
9
10
class TestCase extends PHPUnitTestCase
11
{
12
    /**
13
     * @var Application
14
     */
15
    protected $application;
16
17
    protected function setUp()
18
    {
19
        $this->application = new Application();
20
    }
21
22
    /**
23
     * Returns an instance of the command tester using the options provided.
24
     *
25
     * @param string $commandName  The name of the command being tested.
26
     * @param array $options  An array of options to pass to the command.
27
     * @return CommandTester
28
     * @throws RuntimeException
29
     */
30
    protected function getCommandTester(string $commandName, array $options = []): CommandTester
31
    {
32
        if (!$command = $this->getApplication()->find($commandName)) {
33
            throw new RuntimeException(
34
                sprintf('Please register the % command before attempting to test it.', $commandName)
35
            );
36
        }
37
        $commandTester = new CommandTester($command);
38
        $commandTester->execute(['command' => $commandName], $options);
39
        return $commandTester;
40
    }
41
42
    /**
43
     * Returns the application registered with this test.
44
     *
45
     * @return Application
46
     */
47
    protected function getApplication(): Application
48
    {
49
        return $this->application;
50
    }
51
}
52