禁用symfony2命令的输出

时间:2013-02-07 17:13:06

标签: doctrine-orm symfony-2.1

我正在编写一些单元测试,需要在单元测试中调用一些命令才能创建测试数据库。但是,当我调用命令时,它会将通知转储到屏幕上。有办法关闭它吗?我试图执行--quiet,但它并没有压制通知。

$this->runConsole("doctrine:mongodb:schema:create", array("-q"=> null,"--env" => "test"));    

...

protected function runConsole($command, Array $options = array())
{
    $options = array_merge($options, array('command' => $command));

    return $this->_application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
}

我收到的通知:

[2013-02-07 16:24:43] doctrine.INFO: MongoDB query: {"deleteIndexes":true,"db":"xxxxxx","collection":"xxxxxx} [] []
[2013-02-07 16:24:43] doctrine.INFO: MongoDB query: {"deleteIndexes":true,"db":"xxxxxx","collection":"xxxxxx"} [] []
[2013-02-07 16:24:43] doctrine.INFO: MongoDB query: {"deleteIndexes":true,"db":"xxxxxx","collection":"xxxxxx"} [] []

2 个答案:

答案 0 :(得分:0)

使用CommandTester测试您的命令。你可以在这里阅读更多相关信息:

http://symfony.com/doc/current/components/console/introduction.html#testing-commands

答案 1 :(得分:0)

我在app / config目录中添加了一个config_test.yml并添加了这些行(从我的config_dev.yml复制):

monolog:
    handlers:
       main:
           type:  stream
           path:  "%kernel.logs_dir%/%kernel.environment%.log"
           level: debug
       firephp:
           type:  firephp
           level: info