Completed
Pull Request — master (#1390)
by
unknown
02:31
created

Test::configure()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Phinx
4
 *
5
 * (The MIT license)
6
 * Copyright (c) 2015 Rob Morgan
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated * documentation files (the "Software"), to
10
 * deal in the Software without restriction, including without limitation the
11
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
 * sell copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
 * IN THE SOFTWARE.
25
 *
26
 * @package    Phinx
27
 * @subpackage Phinx\Console
28
 */
29
namespace Phinx\Console\Command;
30
31
use Phinx\Migration\Manager\Environment;
32
use Phinx\Util\Util;
33
use Symfony\Component\Console\Input\InputInterface;
34
use Symfony\Component\Console\Input\InputOption;
35
use Symfony\Component\Console\Output\OutputInterface;
36
37
/**
38
 * @author Leonid Kuzmin <[email protected]>
39
 */
40
class Test extends AbstractCommand
41
{
42
    /**
43
     * {@inheritdoc}
44
     */
45 35
    protected function configure()
46
    {
47 35
        parent::configure();
48
49 35
        $this->addOption('--environment', '-e', InputOption::VALUE_REQUIRED, 'The target environment');
50
51 35
        $this->setName($this->getName() ?: 'test')
52 35
            ->setDescription('Verify the configuration file')
53 35
            ->setHelp(
54
                <<<EOT
55
The <info>test</info> command verifies the YAML configuration file and optionally an environment
56
57
<info>phinx test</info>
58
<info>phinx test -e development</info>
59
60
EOT
61 35
            );
62 35
    }
63
64
    /**
65
     * Verify configuration file
66
     *
67
     * @param \Symfony\Component\Console\Input\InputInterface $input
68
     * @param \Symfony\Component\Console\Output\OutputInterface $output
69
     * @throws \RuntimeException
70
     * @throws \InvalidArgumentException
71
     * @return void
72
     */
73
    protected function execute(InputInterface $input, OutputInterface $output)
74
    {
75
        $this->loadConfig($input, $output);
76
        $this->loadManager($input, $output);
77
78
        // Verify the migrations path(s)
79
        array_map(
80
            [$this, 'verifyMigrationDirectory'],
81
            Util::globAll($this->getConfig()->getMigrationPaths())
82
        );
83
84
        // Verify the seed path(s)
85
        array_map(
86
            [$this, 'verifySeedDirectory'],
87
            Util::globAll($this->getConfig()->getSeedPaths())
88
        );
89
90
        $envName = $input->getOption('environment');
91
        if ($envName) {
92
            if (!$this->getConfig()->hasEnvironment($envName)) {
93
                throw new \InvalidArgumentException(sprintf(
94
                    'The environment "%s" does not exist',
95
                    $envName
96
                ));
97
            }
98
99
            $output->writeln(sprintf('<info>validating environment</info> %s', $envName));
100
            $environment = new Environment(
101
                $envName,
102
                $this->getConfig()->getEnvironment($envName)
0 ignored issues
show
Bug introduced by
It seems like $this->getConfig()->getEnvironment($envName) targeting Phinx\Config\ConfigInterface::getEnvironment() can also be of type null; however, Phinx\Migration\Manager\Environment::__construct() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
103
            );
104
            // validate environment connection
105
            $environment->getAdapter()->connect();
106
        }
107
108
        $output->writeln('<info>success!</info>');
109
    }
110
}
111