2017-05-24 43 views
0

這個問題對我來說就是找到一種方法來改進我的測試。當我測試的代碼,我通常使用此代碼:PHPUnit從測試中得到很好的反饋

$this->assertContains('textExample', $client->getResponse()->getContent()); 

當測試得到OK一切都是正確的,但是當測試從PHPUnit的失敗反饋是如此沉重,因爲PHP單位回聲終端的所有頁面進入搜索文本示例。 我會篩選$ client-> getResponse() - > getContent()),並在我搜索它的網站的精確部分搜索textExample(div,h2 ...),並且沒有那個重要的反饋形式phpunit。

我希望我很清楚,如果不是,我會嘗試重新解釋。

回答

0

爲什麼不使用tearDwon()onNotSuccessfulTest()方法。這樣你可以處理錯誤和過濾,如果你需要。

舉例來說,你可以嘗試這樣開始:

public function onNotSuccessfulTest($e) { 
    // inspect $e to get the information you need, for ie: 
    print_r(get_class_methods($e)); die(); 
    parent::onNotSuccessfulTest($e); 
} 

檢查here以獲取更多信息。

+0

以及哪種方式來使用它?我認爲像$ client-> getResponse() - > getContent() - > filter('div .inThisDiv') – NicolaPez

+0

@NicolaPez我用get_class_methods更新了答案,因此您可以檢查$ e上的可用方法 – lloiacono

+0

@NicolaPez我沒有看到更新,這對你仍然有用嗎?我的回答有幫助嗎? – lloiacono