簡體   English   中英

我如何使用PHPUnit測試使用重定向器助手重定向的Controller_Plugin?

[英]How can I PHPUnit test a Controller_Plugin that uses a Redirector helper to redirect?

我無法解決這個問題。

    $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中使用$ this-> dispatch(),但由於某種原因,這導致錯誤404 Not Found ...

有任何想法嗎?

如果這是你的單元測試代碼,我沒有看到任何模擬,我完全確定我理解為什么這樣實現(如果目標是強制https連接)

我認為這兩行存在問題。

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

如果您可以發布您正在測試的完整操作,並且您正在使用完整的單元測試來測試它,那將會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM