2013-02-07 32 views
0

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

$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"} [] [] 

回答

0

使用CommandTester来测试你的命令。你可以阅读更多关于它在这里:

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

+0

对不起,我不清楚。我不需要测试命令..我正在编写测试,调用命令来加载一些数据。 – daSn0wie

+0

哦,好的。但无论如何 - 你不应该在你的单元测试中使用你的数据库(或任何其他数据源)!如果您使用数据库,则不再进行单元测试。我建议你存根适当的“数据提供者”,以获得你需要的任何数据。如果你展示你想测试的方法,也许我可以告诉更多 – Cyprian

+0

这是我的控制器的功能测试。我想确保控制器正确存储数据。有没有另一种方法来测试? – daSn0wie

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