I am trying to make one of the most simplest (I think) functional test by PHPUnit for a Symfony3 controller.
My controller code is just a redirect:
class DefaultController extends Controller
{
public function indexAction()
{
return $this->redirectToRoute('admin_dashboard', array(), 301);
}
}
and my test function is as follows:
class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient(array(), array(
'HTTP_HOST' => 'www.admin.dev',
));
$client->request('GET', '/');
$client->followRedirect();
$this->assertTrue($client->getResponse()->isRedirect('/dashboard/'));
}
}
The error that I get here is as follows:
LogicException: The request was not redirected
Also some of the results that I get for some values are as follows:
$client->getRequest()->getUri() -> "http://www.admin.dev/"
$client->getResponse()->getStatusCode() -> 404
$client->getResponse() instanceof RedirectResponse -> false
$client->getResponse()->headers->get('location') -> null
A little more background for this issue:
- I have multiple domains pointing to this same project
- The bundle is only loaded when the relative domain is asked for.
For example:
www.admin.dev -> admin bundle
www.admin2.dev -> admin2 bundle
www.admin3.dev -> admin3 bundle
Any ideas what am I doing wrong that I am stuck with this simple problem?
My routing configuration is:
homepage:
host: "www.%domain%"
path: /
defaults: { _controller: MyBundle:Default:index}
admin_dashboard:
host: "www.%domain%"
prefix: /dashboard
path: /
defaults: { _controller: MyBundle:Dashboard:index}
And
%domain% is a parameter in the parameter file. The value is 'admin.dev'