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