我正在编写一些单元测试,需要在单元测试中调用一些命令来创建测试数据库。 但是,当我调用该命令时,它会将通知转储到屏幕上。 有办法关闭这个吗? 我尝试执行 --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"} [] []
使用
CommandTester
测试您的命令。您可以在这里阅读更多相关信息:
http://symfony.com/doc/current/components/console/introduction.html#testing-commands
我在 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