Completed
Pull Request — master (#38)
by Jonathan
02:53
created

BuildSandbox::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
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
    /**
21
     * @var TestRunner
22
     */
23
    private $testRunner;
24
25
    /**
26
     * @var EventDispatcher
27
     */
28
    private $eventDispatcher;
29
30 1
    public function __construct(TestRunner $testRunner, EventDispatcher $eventDispatcher)
31
    {
32 1
        $this->testRunner = $testRunner;
33 1
        $this->eventDispatcher = $eventDispatcher;
34 1
    }
35
36
    public function configure(Command $command)
37
    {
38
        $command
39
            ->setDescription('Build a sandbox for a test run.')
40
            ->addOption('create-dbs', null, InputOption::VALUE_NONE, 'Create the test databases after building the sandbox.')
41
        ;
42
    }
43
44 1
    public function execute(InputInterface $input, OutputInterface $output)
45
    {
46 1
        $this->eventDispatcher->dispatch(Events::SANDBOX_PREPARE);
47
48 1
        if ($input->getOption('create-dbs')) {
49 1
            $this->testRunner->runTestCommand('create-dbs', [
50 1
                '--sandbox' => true,
51
            ]);
52
        }
53
54 1
        register_shutdown_function(function() use ($output) {
55
            $output->writeln('<info>Cleaning up sandbox...</info>');
56
57
            $this->eventDispatcher->dispatch(Events::SANDBOX_CLEANUP);
58 1
        });
59 1
    }
60
}
61