1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Phinx\Console\Command; |
9
|
|
|
|
10
|
|
|
use InvalidArgumentException; |
11
|
|
|
use Phinx\Migration\Manager\Environment; |
12
|
|
|
use Phinx\Util\Util; |
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Leonid Kuzmin <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class Test extends AbstractCommand |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected static $defaultName = 'test'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritDoc} |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
protected function configure() |
33
|
|
|
{ |
34
|
|
|
parent::configure(); |
35
|
|
|
|
36
|
|
|
$this->addOption('--environment', '-e', InputOption::VALUE_REQUIRED, 'The target environment'); |
37
|
|
|
|
38
|
|
|
$this->setDescription('Verify the configuration file') |
39
|
|
|
->setHelp( |
40
|
|
|
<<<EOT |
41
|
|
|
The <info>test</info> command is used to verify the phinx configuration file and optionally an environment |
42
|
|
|
|
43
|
|
|
<info>phinx test</info> |
44
|
|
|
<info>phinx test -e development</info> |
45
|
35 |
|
|
46
|
|
|
If the environment option is set, it will test that phinx can connect to the DB associated with that environment |
47
|
35 |
|
EOT |
48
|
|
|
); |
49
|
35 |
|
} |
50
|
|
|
|
51
|
35 |
|
/** |
52
|
35 |
|
* Verify configuration file |
53
|
35 |
|
* |
54
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input Input |
55
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output Output |
56
|
|
|
* @throws \InvalidArgumentException |
57
|
|
|
* @return int 0 on success |
58
|
|
|
*/ |
59
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
60
|
|
|
{ |
61
|
35 |
|
$this->loadConfig($input, $output); |
62
|
35 |
|
$this->loadManager($input, $output); |
63
|
|
|
|
64
|
|
|
// Verify the migrations path(s) |
65
|
|
|
array_map( |
66
|
|
|
[$this, 'verifyMigrationDirectory'], |
67
|
|
|
Util::globAll($this->getConfig()->getMigrationPaths()) |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
// Verify the seed path(s) |
71
|
|
|
array_map( |
72
|
|
|
[$this, 'verifySeedDirectory'], |
73
|
|
|
Util::globAll($this->getConfig()->getSeedPaths()) |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$envName = $input->getOption('environment'); |
77
|
|
|
if ($envName) { |
78
|
|
|
if (!$this->getConfig()->hasEnvironment($envName)) { |
79
|
|
|
throw new InvalidArgumentException(sprintf( |
80
|
|
|
'The environment "%s" does not exist', |
81
|
|
|
$envName |
82
|
|
|
)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$output->writeln(sprintf('<info>validating environment</info> %s', $envName), $this->verbosityLevel); |
86
|
|
|
$environment = new Environment( |
87
|
|
|
$envName, |
88
|
|
|
$this->getConfig()->getEnvironment($envName) |
89
|
|
|
); |
90
|
|
|
// validate environment connection |
91
|
|
|
$environment->getAdapter()->connect(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$output->writeln('<info>success!</info>', $this->verbosityLevel); |
95
|
|
|
|
96
|
|
|
return self::CODE_SUCCESS; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|