1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace PHPChunkit\Command; |
6
|
|
|
|
7
|
|
|
use PHPChunkit\Events; |
8
|
|
|
use PHPChunkit\TestRunner; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @testClass PHPChunkit\Test\Command\BuildSandboxTest |
17
|
|
|
*/ |
18
|
|
|
class BuildSandbox implements CommandInterface |
19
|
|
|
{ |
20
|
|
|
const NAME = 'sandbox'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var TestRunner |
24
|
|
|
*/ |
25
|
|
|
private $testRunner; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var EventDispatcher |
29
|
|
|
*/ |
30
|
|
|
private $eventDispatcher; |
31
|
|
|
|
32
|
1 |
|
public function __construct(TestRunner $testRunner, EventDispatcher $eventDispatcher) |
33
|
|
|
{ |
34
|
1 |
|
$this->testRunner = $testRunner; |
35
|
1 |
|
$this->eventDispatcher = $eventDispatcher; |
36
|
1 |
|
} |
37
|
|
|
|
38
|
|
|
public function getName() : string |
39
|
|
|
{ |
40
|
|
|
return self::NAME; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function configure(Command $command) |
44
|
|
|
{ |
45
|
|
|
$command |
46
|
|
|
->setDescription('Build a sandbox for a test run.') |
47
|
|
|
->addOption('create-dbs', null, InputOption::VALUE_NONE, 'Create the test databases after building the sandbox.') |
48
|
|
|
; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
public function execute(InputInterface $input, OutputInterface $output) |
52
|
|
|
{ |
53
|
1 |
|
$this->eventDispatcher->dispatch(Events::SANDBOX_PREPARE); |
54
|
|
|
|
55
|
1 |
|
if ($input->getOption('create-dbs')) { |
56
|
1 |
|
$this->testRunner->runTestCommand('create-dbs', [ |
57
|
1 |
|
'--sandbox' => true, |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
register_shutdown_function(function() use ($output) { |
62
|
|
|
$output->writeln('<info>Cleaning up sandbox...</info>'); |
63
|
|
|
|
64
|
|
|
$this->eventDispatcher->dispatch(Events::SANDBOX_CLEANUP); |
65
|
1 |
|
}); |
66
|
1 |
|
} |
67
|
|
|
} |
68
|
|
|
|