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(); |
|
|
|
|
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
|
|
|
|