Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何测试使用重定向器帮助器重定向的控制器插件?_Php_Zend Framework_Phpunit - Fatal编程技术网

Php 如何测试使用重定向器帮助器重定向的控制器插件?

Php 如何测试使用重定向器帮助器重定向的控制器插件?,php,zend-framework,phpunit,Php,Zend Framework,Phpunit,我无法解决这个问题 $this->_request->setBasePath('http://localhost/'); $this->_request->setModuleKey('admin'); $this->_request->setControllerKey('controller-page'); $this->_request->setActionKey('index'); $this->

我无法解决这个问题

    $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找不到错误


有什么想法吗?

如果这是您的单元测试代码,我没有看到任何模拟的东西,我完全确定我理解为什么要以这种方式实现它(如果目标是强制https连接)

我认为这两条线有问题

$this->_sslRedirect->preDispatch($this->_request);
$this->assertRedirectRegex('/https:/');
如果您可以发布您正在测试的完整操作,以及您用来测试它的完整单元测试,这将有所帮助