Test   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 41
ccs 0
cts 21
cp 0
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 30 4
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