Php Symfony2命令更改环境

Php Symfony2命令更改环境,php,testing,symfony,command,env,Php,Testing,Symfony,Command,Env,我想建立一个顺序,让我清楚:缓存测试模式,然后在测试模式下删除数据库,删除scheama,添加scheme,添加fixture class BaseCommand extends \Symfony\Component\Console\Command\Command { //put your code here protected function configure() { $this ->setName('mycommand:test')

我想建立一个顺序,让我清楚:缓存测试模式,然后在测试模式下删除数据库,删除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
如何在dev环境中通过测试

谢谢

您无法设置--env=test,因为在运行php应用程序/控制台mycommand:test时已经创建了内核和环境

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

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

非常感谢。现在,当我使用条令:schema:create时,我有一个错误:没有选定的数据库。你能就此提出一个新问题吗?如果适合您,请不要忘记批准我的答案:)这是正确的答案,如果遵循SF2文档,则非常违反直觉