简体   繁体   English

Symfony2命令更改环境

[英]Symfony2 command change environment

I want to set up an order allowing me to make clear: cache test mode, then do a drop database, drop scheama, add scheme, add fixtures in test mode. 我想建立一个命令让我明确:缓存测试模式,然后删除数据库,删除模式,添加方案,在测试模式中添加固定装置。

class BaseCommand extends \Symfony\Component\Console\Command\Command {

//put your code here

protected function configure()
{
    $this
            ->setName('mycommand:test')
            ->setDescription('Launch test')
    ;

}

protected function execute(InputInterface $input, OutputInterface $output)
{
    $command_first_migration = $this->getApplication()->find('cache:clear');
    $arguments_first_migration = array(
        'command' => 'cache:clean',
        '--env' => 'test'
    );
    $input_first_migration = new ArrayInput($arguments_first_migration);
    try {

        $returnCode = $command_first_migration->run($input_first_migration, $output);


    } catch (\Doctrine\DBAL\Migrations\MigrationException $ex) {
        echo "MigrationExcepion !!!! ";
    }
}

} }

but I have this result : 但我有这个结果:

clearing the case for the dev environment with debug true

How to pass the test in dev environment? 如何在开发环境中通过测试?

thank you 谢谢

You can't set the --env=test since the Kernel and the environment are already created when you run php app/console mycommand:test. 您无法设置--env = test,因为在运行php app / console mycommand:test时已经创建了内核和环境。

The only way is to specify the env when you run your command : 唯一的方法是在运行命令时指定env:

php app/console mycommand:test --env=test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM