2012-05-14 34 views
3

我無法解決這個問題。PHPUnit如何測試使用重定向器助手重定向的Controller_Plugin?

$this->_request->setBasePath('http://localhost/'); 
    $this->_request->setModuleKey('admin'); 
    $this->_request->setControllerKey('controller-page'); 
    $this->_request->setActionKey('index'); 

    $this->_sslRedirect->preDispatch($this->_request); 

    $this->assertRedirectRegex('/https:/'); 

在我的控制器插件preDispatch()方法可能會或可能不會進行重定向到SSL。這適用於瀏覽器,但我無法爲它編寫測試。測試失敗,就像這樣:

Failed asserting response redirects to URL MATCHING "/https:/" 

/srv/app/zend/library/Zend/Test/PHPUnit/Constraint/Redirect.php:190 
/srv/app/zend/library/Zend/Test/PHPUnit/ControllerTestCase.php:764 
/srv/app/www/tests/lib/Saffron/Controller/Plugin/SslRedirectTest.php:36 
/usr/bin/phpunit:46 

我也試着用$這個 - >訊()的preDispatch()方法行後立即Zend_Test_PHPUnit_ControllerTestCase內,但由於某些原因這引起了錯誤404未找到.. 。

任何想法?

回答

0

如果這是你的單元測試代碼,我沒有看到任何東西嘲笑了,我完全相信我理解爲什麼這是正在實施的這種方式(如果目標是迫使HTTPS連接)

我認爲這兩條線都有問題。

$this->_sslRedirect->preDispatch($this->_request); 
$this->assertRedirectRegex('/https:/'); 

如果您可以發佈您正在測試的完整操作以及您用於測試的完整單元測試,這將有所幫助。