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

BuildSandbox   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 43
ccs 12
cts 16
cp 0.75
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 7 1
A execute() 0 16 2
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