How can I use PHPUnit to check the Controller_Plugin that the Redirector helper uses to redirect?

I can’t solve it.

    $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:/');

In my controller plugin, preDispatch () may or may not redirect to SSL. This works in the browser, however I cannot write a test for it. The test does not work, for example:

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

I also tried using $ this-> dispatch () inside Zend_Test_PHPUnit_ControllerTestCase right after the preDispatch () line, but for some reason this caused a 404 Not Found error ...

Any ideas?

+3
source share
1 answer

If this is your unit test code, I don’t see anything bullying, and I’m absolutely sure that I understand why this is done this way (if the goal is to force the https connection)

, .

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

, , unit test, , .

0

All Articles