ZF-11680: Zend_Test_PHPUnit_ControllerTestCase :: dispatch() doesn't accept absolute URL's
Description
Please check the example, I think it self-explainable.
$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
':username.domain.com',
array(
'controller' => 'user',
'action' => 'info'
)
);
$plainPathRoute = new Zend_Controller_Router_Route_Static('');
$router->addRoute('user', $hostnameRoute->chain($plainPathRoute));
// IndexControllerTest.php
<?php
class IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
$this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
parent::setUp();
}
public function testIndexAction()
{
$this->dispatch('http://myname.domain.com');
$this->assertController('user'); // Fail
}
}
$this->dispatch($url) is actually call Zend_Controller_Request_HttpTestCase->setRequestUri($url)
which is based on Zend_Controller_Request_Http which use parse_str function to parse $url argument.
parse_str usually used to parse query string, but not full URL.
I think it's better to use some sort of regexp's and/or parse_url() method.
Thanks, and sorry for my bad english :)
Comments
Posted by Dmitry Chirkin (josser) on 2011-08-17T19:37:22.000+0000
I found a workaround, which, I think is not good idea but it works:
define $_SERVER['HTTP_HOST'] before ->dispatch() call.
Posted by Maksym Sliesarenko (sm) on 2011-08-17T20:38:25.000+0000
Posted by Adam Lundrigan (adamlundrigan) on 2011-10-14T18:47:16.000+0000
Maks -- before your code contribution can be used in Zend Framework, you need to sign a CLA:
Once you've signed and returned it (email: cla@zend.com), comment on this issue and we'll have a look at your suggestion.
Thanks!
Posted by Maksym Sliesarenko (sm) on 2011-11-01T15:57:37.000+0000
I've signed it and sent it by fax couple weeks ago.