Passed
Push — master ( 77392d...e0a3bd )
by Kirill
08:16 queued 11s
created

ConsoleTest::cleanupMigrations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 5
rs 10
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
        $this->cleanupMigrations();
30
    }
31
32
    private function cleanupMigrations(): void
33
    {
34
        $fs = new Files();
35
        if ($fs->isDirectory(__DIR__ . '/../app/migrations')) {
36
            $fs->deleteDirectory(__DIR__ . '/../app/migrations');
37
        }
38
    }
39
40
    public function tearDown(): void
41
    {
42
        parent::tearDown();
43
44
        $this->cleanupMigrations();
45
46
        $fs = new Files();
47
        $runtime = $this->app->get(DirectoriesInterface::class)->get('runtime');
48
49
        if ($fs->isDirectory($runtime)) {
50
            $fs->deleteDirectory($runtime);
51
        }
52
    }
53
54
    public function runCommand(string $command, array $args = []): string
55
    {
56
        $input = new ArrayInput($args);
57
        $output = new BufferedOutput();
58
59
        $this->app->console()->run($command, $input, $output);
60
61
        return $output->fetch();
62
    }
63
64
    public function runCommandDebug(string $command, array $args = [], OutputInterface $output = null): string
65
    {
66
        $input = new ArrayInput($args);
67
        $output = $output ?? new BufferedOutput();
68
        $output->setVerbosity(BufferedOutput::VERBOSITY_VERBOSE);
69
70
        $this->app->console()->run($command, $input, $output);
71
72
        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 or Symfony\Component\Consol...put\TrimmedBufferOutput. ( Ignorable by Annotation )

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

72
        return $output->/** @scrutinizer ignore-call */ fetch();
Loading history...
73
    }
74
75
    public function runCommandVeryVerbose(string $command, array $args = [], OutputInterface $output = null): string
76
    {
77
        $input = new ArrayInput($args);
78
        $output = $output ?? new BufferedOutput();
79
        $output->setVerbosity(BufferedOutput::VERBOSITY_DEBUG);
80
81
        $this->app->console()->run($command, $input, $output);
82
83
        return $output->fetch();
84
    }
85
}
86