【问题标题】:Symfony2 command change environmentSymfony2 命令改变环境
【发布时间】:2013-07-22 08:41:18
【问题描述】:

我想设置一个命令,让我明确:缓存测试模式,然后做一个删除数据库,删除架构,添加方案,在测试模式下添加夹具。

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

开发环境如何通过测试?

谢谢

【问题讨论】:

    标签: php testing symfony command env


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢。现在,当我使用学说:模式:创建我有这个错误:没有选择的数据库。
    • 您能为此提出一个新问题吗?如果它适合你,别忘了批准我的回答:)
    • 这是正确答案,如果遵循 SF2 文档,则非常违反直觉
    猜你喜欢
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多