我很努力去理解我的功能測試或項目設置有什麼問題:phpunit執行只是打印出以下信息(我不打印出測試套件 - 即它不是來自客戶端 - > getResponse()打印或任何東西)。Symfony2功能測試打印出重定向html並停止測試執行
phpunit -c app --group temp1 src/AppBundle/Tests/Controller/SecurityControllerTest.php
我的測試代碼:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="1;url=/" />
<title>Redirecting to /</title>
</head>
<body>
Redirecting to <a href="/">/</a>.
</body>
</html>
從命令行運行PHPUnit之後:另外,該文本打印出到命令行之後的整個測試執行立即停止而沒有任何結果的信息相當簡單:
class SecurityControllerTest extends WebTestCase
{
/**
* test login with succesfull case
*
* @group login
* @group temp1
*/
public function testLogin_success()
{
$client = static::createClient();
$crawler = $client->request('GET', '/');
// temp - just to test that the initial crawler location is correct
$this->assertGreaterThan(0, $crawler->filter('html:contains("System Login")')->count(), "login page not found");
$client->followRedirects(true);
$crawler = $this->loginSubmit($client, $crawler, "[email protected]", "basic_user1_password");
// THE BELOW ROWS ARE NEVER REACHED
// test that the user can access the user home
$crawler = $client->request('GET', '/user/myprofile');
$this->assertGreaterThan(0, $crawler->filter('html:contains("Welcome to your user profile")')->count(), "User homepage not accessible after login");
}
private function loginSubmit($client, $crawler, $username, $password)
{
$loginButton = $crawler->selectButton('Login');
$loginForm = $loginButton->form();
$loginForm['form[email]'] = $username;
$loginForm['form[password]'] = $password;
// BELOW IS THE ROW THAT RESULTS IN THE PRINTOUT + TEST EXECUTION STOP
return $client->submit($loginForm);
}
//....
}
此外,e xactly相同的測試用例在我正在處理的另一個項目上工作正常,所以我一直試圖挖掘項目配置中的差異,但沒有運氣。
任何幫助非常感謝 - 如果這可能是有用的/相關的,隨意要求其他代碼/配置文件內容。
使用symfony的2.3.12 & PHPUnit的4.1.0
更新:特定的代碼鏈,導致錯誤
所以管理由解決基本的項目會議議題夫婦解決此問題後,幾天前,我回到調試這個問題還有點進一步。而目前看來,結果是由於下面的代碼鏈,第一呼叫前轉:
$this->forward('bundle:controller:action')->send();
,並在轉發控制器動作調用重定向:
$this->redirect($this->generateUrl($route, $parameters))->send();
顯然這個控制器的流動似乎有點怪總的來說,但問題仍然是爲什麼這導致了觀察結果?
斷言來自下面的行永遠不會到達的評論。我會將這些問題添加到 – ejuhjav
您是使用默認Web服務器還是使用apache進行檢查? –
@GaneshPatil我從phpunit的命令行運行這個(更新了問題) – ejuhjav