Completed
Push — master ( 17598f...abee1f )
by Kirill
13s queued 11s
created

ConsoleTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 24
dl 0
loc 56
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A runCommandDebug() 0 9 1
A runCommand() 0 8 1
A runCommandVeryVerbose() 0 9 1
A tearDown() 0 13 3
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Framework;
13
14
use Spiral\Boot\DirectoriesInterface;
15
use Spiral\Files\Files;
16
use Spiral\App\TestApp;
17
use Symfony\Component\Console\Input\ArrayInput;
18
use Symfony\Component\Console\Output\BufferedOutput;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
abstract class ConsoleTest extends BaseTest
22
{
23
    /** @var TestApp */
24
    protected $app;
25
26
    public function setUp(): void
27
    {
28
        $this->app = $this->makeApp();
29
    }
30
31
    public function tearDown(): void
32
    {
33
        parent::tearDown();
34
35
        $fs = new Files();
36
37
        if ($fs->isDirectory(__DIR__ . '/../app/migrations')) {
38
            $fs->deleteDirectory(__DIR__ . '/../app/migrations');
39
        }
40
41
        $runtime = $this->app->get(DirectoriesInterface::class)->get('runtime');
42
        if ($fs->isDirectory($runtime)) {
43
            $fs->deleteDirectory($runtime);
44
        }
45
    }
46
47
    public function runCommand(string $command, array $args = []): string
48
    {
49
        $input = new ArrayInput($args);
50
        $output = new BufferedOutput();
51
52
        $this->app->console()->run($command, $input, $output);
53
54
        return $output->fetch();
55
    }
56
57
    public function runCommandDebug(string $command, array $args = [], OutputInterface $output = null): string
58
    {
59
        $input = new ArrayInput($args);
60
        $output = $output ?? new BufferedOutput();
61
        $output->setVerbosity(BufferedOutput::VERBOSITY_VERBOSE);
62
63
        $this->app->console()->run($command, $input, $output);
64
65
        return $output->fetch();
0 ignored issues
show
Bug introduced by
The method fetch() does not exist on Symfony\Component\Console\Output\OutputInterface. It seems like you code against a sub-type of Symfony\Component\Console\Output\OutputInterface such as Symfony\Component\Console\Output\BufferedOutput. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        return $output->/** @scrutinizer ignore-call */ fetch();
Loading history...
66
    }
67
68
    public function runCommandVeryVerbose(string $command, array $args = [], OutputInterface $output = null): string
69
    {
70
        $input = new ArrayInput($args);
71
        $output = $output ?? new BufferedOutput();
72
        $output->setVerbosity(BufferedOutput::VERBOSITY_DEBUG);
73
74
        $this->app->console()->run($command, $input, $output);
75
76
        return $output->fetch();
77
    }
78
}
79