Symfony2命令改变环境

时间:2013-07-22 08:41:19

标签: php testing symfony command env

我想设置一个允许我明确的命令:缓存测试模式,然后执行drop database,drop scheama,添加scheme,在测试模式下添加fixture。

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 !!!! ";
    }
}

}

但我有这个结果:

clearing the case for the dev environment with debug true

如何在开发环境中通过测试?

谢谢

1 个答案:

答案 0 :(得分:2)

您无法设置--env = test,因为在运行php app / console mycommand:test时已经创建了内核和环境。

唯一的方法是在运行命令时指定env:

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