2013-02-07 30 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