禁用 symfony2 命令的输出

问题描述 投票:0回答:2

我正在编写一些单元测试,需要在单元测试中调用一些命令来创建测试数据库。 但是,当我调用该命令时,它会将通知转储到屏幕上。 有办法关闭这个吗? 我尝试执行 --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"} [] []
php doctrine-orm symfony-2.1
2个回答
0
投票

使用

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

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


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
© www.soinside.com 2019 - 2024. All rights reserved.