Test::execute()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 16
c 2
b 0
f 0
nc 6
nop 2
dl 0
loc 30
ccs 0
cts 21
cp 0
crap 20
rs 9.7333
1
<?php
2
3
namespace ZfPhinx\Command;
4
5
use Phinx\Console\Command\Test as TestPrototype;
6
use Phinx\Migration\Manager\Environment;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * 'Test' command implementation
12
 */
13
class Test extends TestPrototype
14
{
15
    /**
16
     * Verify configuration file
17
     *
18
     * @param  InputInterface            $input
19
     * @param  OutputInterface           $output
20
     * @throws \RuntimeException
21
     * @throws \InvalidArgumentException
22
     * @return void
23
     */
24
    protected function execute(InputInterface $input, OutputInterface $output)
25
    {
26
        $this->loadManager($input, $output);
27
28
        $migrationsPaths = (array) $this->getConfig()->getMigrationPaths();
29
        foreach ($migrationsPaths as $path) {
30
            $this->verifyMigrationDirectory($path);
31
        }
32
33
        $envName = $input->getOption('environment');
34
        if($envName)
35
        {
36
            if(!$this->getConfig()->hasEnvironment($envName))
37
            {
38
                throw new \InvalidArgumentException(sprintf(
39
                    'The environment "%s" does not exist',
40
                    $envName
41
                ));
42
            }
43
44
            $output->writeln(sprintf('<info>validating environment</info> %s', $envName));
45
            $environment = new Environment(
46
                $envName,
47
                $this->getConfig()->getEnvironment($envName)
48
            );
49
            // validate environment connection
50
            $environment->getAdapter()->connect();
51
        }
52
53
        $output->writeln('<info>success!</info>');
54
    }
55
}
56